Skip to content

Commit

Permalink
added hook update to set label options
Browse files Browse the repository at this point in the history
  • Loading branch information
yeniatencio committed Dec 17, 2024
1 parent a425ad7 commit 7dfaa7f
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 6 deletions.
14 changes: 13 additions & 1 deletion modules/tide_landing_page/tide_landing_page.install
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ function tide_landing_page_update_10107() {
}

/**
* Set field `field_landing_page_hero_theme` to mandatory.
* Set field `field_landing_page_hero_theme` to mandatory, description and label.
*/
function tide_landing_page_update_10108() {
$bundles = [
Expand All @@ -225,3 +225,15 @@ function tide_landing_page_update_10108() {
}
}
}

/**
* Set label options for `field_landing_page_hero_theme`.
*/
function tide_landing_page_update_10109() {
$fieldStorage = Drupal::entityTypeManager()->getStorage('field_storage_config')->load('node.field_landing_page_hero_theme');
$fieldStorage->setSettings(['allowed_values' => [
"dark" => "Reverse blocked text",
"light" => "Default",
]]);
$fieldStorage->save();
}
38 changes: 33 additions & 5 deletions modules/tide_landing_page/tide_landing_page.module
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
* Tide Landing Page module functionality.
*/

use Drupal\Core\Ajax\AjaxResponse;
use Drupal\Core\Ajax\InvokeCommand;
use Drupal\Core\Cache\Cache;
use Drupal\Core\Field\WidgetBase;
use Drupal\Core\Form\FormStateInterface;
Expand Down Expand Up @@ -117,11 +119,6 @@ function tide_landing_page_form_node_form_alter(&$form, FormStateInterface $form
$form['field_landing_page_hero_image']['widget']['field_show_hero_image_caption'] = $form['field_show_hero_image_caption'];
unset($form['field_show_hero_image_caption']);
}
// Move Hero Image theme to Hero Image field group.
// if (isset($form['field_landing_page_hero_theme']) && isset($form['field_landing_page_hero_image']['widget'])) {
// $form['field_landing_page_hero_image']['widget']['field_landing_page_hero_theme'] = $form['field_landing_page_hero_theme'];
// unset($form['field_landing_page_hero_theme']);
// }

// @todo the below block needs to be in a proper widget alter.
if (isset($form['field_landing_page_component']['widget'][0])) {
Expand Down Expand Up @@ -371,6 +368,34 @@ function tide_landing_page_field_widget_single_element_paragraphs_form_alter(&$e
}
}

/**
* Function to set value to Hero image theme.
*
* @param array $form
* The form.
* @param Drupal\Core\Form\FormStateInterface $form_state
* The form state.
*
* @return Drupal\Core\Ajax\AjaxResponse
* The response.
*/
function tide_landing_page_set_value_hero_image_theme(array $form, FormStateInterface $form_state): AjaxResponse {
$response = new AjaxResponse();
$value = $form_state->getValue('_header_style_options');
if ($value === 'fullwidth') {
return $response->addCommand(new InvokeCommand(
'#edit-field-landing-page-hero-theme',
'val',
['dark']
));
}
return $response->addCommand(new InvokeCommand(
'#edit-field-landing-page-hero-theme',
'val',
['light']
));
}

/**
* Node form #process callback.
*
Expand Down Expand Up @@ -405,6 +430,9 @@ function _tide_landing_page_form_node_form_process(array $form, FormStateInterfa
'corner' => t('Corner graphics'),
'cta' => t('Call to action banner'),
],
'#ajax' => [
'callback' => 'tide_landing_page_set_value_hero_image_theme',
],
];

$form['field_landing_page_hero_theme']['#states']['disabled'] = [
Expand Down

0 comments on commit 7dfaa7f

Please sign in to comment.