From 7dfaa7f4ec49ec7f1dc08f99fb2c728f6ccfc9b7 Mon Sep 17 00:00:00 2001 From: Yeni Atencio Date: Wed, 18 Dec 2024 10:11:26 +1100 Subject: [PATCH] added hook update to set label options --- .../tide_landing_page.install | 14 ++++++- .../tide_landing_page.module | 38 ++++++++++++++++--- 2 files changed, 46 insertions(+), 6 deletions(-) diff --git a/modules/tide_landing_page/tide_landing_page.install b/modules/tide_landing_page/tide_landing_page.install index 1ea248a1..08d33cf6 100644 --- a/modules/tide_landing_page/tide_landing_page.install +++ b/modules/tide_landing_page/tide_landing_page.install @@ -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 = [ @@ -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(); +} diff --git a/modules/tide_landing_page/tide_landing_page.module b/modules/tide_landing_page/tide_landing_page.module index f32c1f6a..19093c63 100644 --- a/modules/tide_landing_page/tide_landing_page.module +++ b/modules/tide_landing_page/tide_landing_page.module @@ -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; @@ -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])) { @@ -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. * @@ -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'] = [