From f73de6fb710f2354c5c98b338dbfc4665ca9344b Mon Sep 17 00:00:00 2001 From: Eric Bremner <ebremner@uwaterloo.ca> Date: Tue, 18 Oct 2022 10:34:25 -0400 Subject: [PATCH] ISTWCMS-5880: updating the states for media and adding allowed value function for media width --- uw_cfg_common.module | 42 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/uw_cfg_common.module b/uw_cfg_common.module index dddb5d0c..db7398e0 100644 --- a/uw_cfg_common.module +++ b/uw_cfg_common.module @@ -589,6 +589,41 @@ function uw_cfg_common_preprocess_node(&$variables) { } } +/** + * Get the layout builder styles as options. + * + * @param \Drupal\field\Entity\FieldStorageConfig $definition + * The field definition. + * @param \Drupal\Core\Entity\ContentEntityInterface|null $entity + * The entity being created if applicable. + * @param bool $cacheable + * Boolean indicating if the results are cacheable. + * + * @return array + * An array of possible key and value options. + * + * @see options_allowed_values() + */ +function _uw_cfg_common_get_layout_builder_styles ( + FieldStorageConfig $definition, + ContentEntityInterface $entity = NULL, + $cacheable +) { + + // Get all the styles for sections. + $all_styles = _layout_builder_styles_retrieve_by_type('section'); + + // Array of options. + $options = []; + + // Step through each style and get the info. + foreach ($all_styles as $style) { + $options[$style->id()] = $style->label(); + } + + return $options; +} + /** * Implements hook_page_attachments(). */ @@ -925,7 +960,7 @@ function uw_cfg_common_form_alter(array &$form, FormStateInterface $form_state, ]; // Set the states for the banner. - $form['field_uw_banner']['#states'] = [ + $form['group_banner']['#states'] = [ 'visible' => [ [ 'select[name="field_uw_type_of_media"]' => [ @@ -936,12 +971,15 @@ function uw_cfg_common_form_alter(array &$form, FormStateInterface $form_state, ]; // Set the states for the banner settings. - $form['group_banner_settings']['#states'] = [ + $form['field_uw_media_width']['#states'] = [ 'visible' => [ [ 'select[name="field_uw_type_of_media"]' => [ ['value' => 'banner'], ], + 'select[name="field_uw_text_overlay_style"]' => [ + ['value' => 'full-width'], + ], ], ], ]; -- GitLab