Skip to content

Commit

Permalink
fix(thumbnail-view-defaults): default selected on no config
Browse files Browse the repository at this point in the history
When an existing view is modified, the default was that show thumbnail
would be false, when in fact, it should default to true.  When creating
new views, it does this, but for those that had no value at all, it
defaulted to unchecked.

This checks if fieldOptionValue is empty and if so, it uses the default
value of show_thumbnail enabled.
  • Loading branch information
dblanken-yale committed Sep 18, 2024
1 parent e748237 commit 06d02eb
Showing 1 changed file with 2 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ public function formElement(
];

$fieldOptionValue = ($items[$delta]->params) ? $this->viewsBasicManager->getDefaultParamValue('field_options', $items[$delta]->params) : [];
$fieldOptionDefaultValue = $fieldOptionValue ?? ['show_thumbnail' => 'show_thumbnail'];
$isNewForm = str_contains($formState->getCompleteForm()['#id'], 'layout-builder-add-block');
// Set the default value for 'field_options' to 'show_thumbnail'
// when creating a new block.
Expand All @@ -232,7 +233,7 @@ public function formElement(
],
'#title' => $this->t('Field Display Options'),
'#tree' => TRUE,
'#default_value' => ($isNewForm && empty($fieldOptionValue)) ? ['show_thumbnail'] : $fieldOptionValue,
'#default_value' => ($isNewForm && empty($fieldOptionValue)) ? ['show_thumbnail'] : $fieldOptionDefaultValue,
'show_thumbnail' => [
'#states' => [
'visible' => [
Expand Down

0 comments on commit 06d02eb

Please sign in to comment.