diff --git a/config/install/field.storage.node.field_uw_page_title_big_text.yml b/config/install/field.storage.node.field_uw_page_title_big_text.yml new file mode 100644 index 0000000000000000000000000000000000000000..86ca6f2e89745e031c1979faac3479382e51efdb --- /dev/null +++ b/config/install/field.storage.node.field_uw_page_title_big_text.yml @@ -0,0 +1,26 @@ +langcode: en +status: true +dependencies: + module: + - node + - options +id: node.field_uw_page_title_big_text +field_name: field_uw_page_title_big_text +entity_type: node +type: list_string +settings: + allowed_values: + - + value: '1' + label: 'Yes' + - + value: '0' + label: 'No' + allowed_values_function: '' +module: options +locked: false +cardinality: 1 +translatable: true +indexes: { } +persist_with_no_fields: false +custom_storage: false diff --git a/js/uw_cfg_common.js b/js/uw_cfg_common.js new file mode 100644 index 0000000000000000000000000000000000000000..a989ad56692453548f115ec379a94222b1d9e12d --- /dev/null +++ b/js/uw_cfg_common.js @@ -0,0 +1,61 @@ +/** + * @file + * Javascript for uw_cfg_common. + */ + +(function ($, Drupal, drupalSettings) { + + 'use strict'; + + Drupal.behaviors.uw_cfg_common = { + attach: function (context, drupalSettings) { + + // On document ready, check if the page has the page title + // as big text and if so enable/disable the big text + // in the banner image. + $(document).ready(function () { + setBigText(); + }); + + // When the big text in banner images is ready, check if it + // needs to be able enable/disabled based on page title. + $('input[name*="[subform][field_uw_ban_big_text]"]').ready(function () { + setBigText(); + }); + + // When the page title option has been changed set the big text + // in banner based on inputs. + $('#edit-field-uw-page-title-big-text').change(function () { + setBigText(); + }); + + // When the text overlay option has been changed set the big text + // in banner based on inputs. + $('#edit-field-uw-text-overlay-style').change(function () { + setBigText(); + }); + + // Function to set big text in banner image. + function setBigText() { + + // If not single page style banner and page title big text + // then disable big text in banner and set value to blank. + // Otherwise enable big text in banner. + if ( + $('#edit-field-uw-text-overlay-style').val() !== 'split' && + $('#edit-field-uw-page-title-big-text').val() == 1 + ) { + $('input[name*="[subform][field_uw_ban_big_text]"]').each(function () { + $(this).prop("disabled", true); + $(this).val(''); + }); + } + else { + $('input[name*="[subform][field_uw_ban_big_text]"]').each(function () { + $(this).prop("disabled", false); + }); + } + } + } + } +})(jQuery, Drupal, drupalSettings); diff --git a/src/Service/UwNodeFieldValue.php b/src/Service/UwNodeFieldValue.php index 8a02ed5995c942800ec669d5f23061833aa22832..5ca074724745414d67a9302fb6505e874c069d53 100644 --- a/src/Service/UwNodeFieldValue.php +++ b/src/Service/UwNodeFieldValue.php @@ -262,6 +262,15 @@ class UwNodeFieldValue { $media_width_classes = $layout_builder_style->getClasses(); } + // Flag to use page title as big text. + $use_page_title_big_text_flag = FALSE; + + if ($node->hasField('field_uw_page_title_big_text')) { + if ($node->field_uw_page_title_big_text->value) { + $use_page_title_big_text_flag = TRUE; + } + } + // Process banner images. foreach ($node->$field_name as $banner_item) { @@ -270,7 +279,7 @@ class UwNodeFieldValue { $banner = [ 'type' => $type, - 'big_text' => $banner_para->field_uw_ban_big_text->value, + 'big_text' => $use_page_title_big_text_flag ? $node->label() : $banner_para->field_uw_ban_big_text->value, 'small_text' => $banner_para->field_uw_ban_small_text->value, ]; @@ -317,6 +326,8 @@ class UwNodeFieldValue { 'style' => $node->field_uw_text_overlay_style->value, 'transition_speed' => $node->field_uw_transition_speed->value, 'media_width' => $media_width_classes ?? NULL, + 'text_overlay' => $node->field_uw_text_overlay_style->value, + 'use_page_title_big_text' => $use_page_title_big_text_flag, 'bundle' => $node->getType(), 'uuid' => uniqid(), ]; diff --git a/uw_cfg_common.libraries.yml b/uw_cfg_common.libraries.yml index 7fd5c46f098c2bbbcc3eb7cf0839b9a59bc1b2a3..87f3a347e32e6e1b3b077856db970a38b9b03f40 100644 --- a/uw_cfg_common.libraries.yml +++ b/uw_cfg_common.libraries.yml @@ -1,3 +1,7 @@ uw_mathjax: js: https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.7/MathJax.js?config=TeX-AMS_HTML: { type: external, minified: true } +uw_cfg_common: + version: 1.x + js: + js/uw_cfg_common.js: { } diff --git a/uw_cfg_common.module b/uw_cfg_common.module index 9cf2297efb48696d4d3a457ff8d86785c6e74163..546257332b910787ca89cc1889a84858f3a0ca82 100644 --- a/uw_cfg_common.module +++ b/uw_cfg_common.module @@ -1074,7 +1074,6 @@ function uw_cfg_common_form_alter(array &$form, FormStateInterface $form_state, // Hide elements under Twitter settings. $form['field_uw_meta_tags']['widget'][0]['twitter_cards']['twitter_cards_page_url']['#access'] = FALSE; - $form['field_uw_meta_tags']['widget'][0]['twitter_cards']['twitter_cards_page_url']['#access'] = FALSE; } } @@ -1127,6 +1126,17 @@ function uw_cfg_common_form_alter(array &$form, FormStateInterface $form_state, ], ]; + // Set the states for the banner settings. + $form['field_uw_text_overlay_style']['#states'] = [ + 'visible' => [ + [ + 'select[name="field_uw_type_of_media"]' => [ + ['value' => 'banner'], + ], + ], + ], + ]; + // Set the states for the banner settings. $form['field_uw_media_width']['#states'] = [ 'visible' => [ @@ -1141,6 +1151,38 @@ function uw_cfg_common_form_alter(array &$form, FormStateInterface $form_state, ], ]; + // Set the states for the banner settings, if it exists. + if (isset($form['field_uw_page_title_big_text'])) { + + // ISTWCMS-6313. + // The next two are for existing content types that do not have + // the default values and options set for page title big text. + if (empty($form['field_uw_page_title_big_text']['widget']['#default_value'])) { + $form['field_uw_page_title_big_text']['widget']['#default_value'][0] = 0; + } + if (isset($form['field_uw_page_title_big_text']['widget']['#options']['_none'])) { + unset($form['field_uw_page_title_big_text']['widget']['#options']['_none']); + } + + // The form state for page title as big text. + $form['field_uw_page_title_big_text']['#states'] = [ + 'visible' => [ + [ + 'select[name="field_uw_type_of_media"]' => [ + ['value' => 'banner'], + ], + 'select[name="field_uw_text_overlay_style"]' => [ + ['!value' => 'split'], + ], + ], + ], + ]; + } + + // ISTWCMS-6313: adding the JS on the node add/edit page, + // that will check for enable/disable big text in banner image. + $form['#attached']['library'][] = 'uw_cfg_common/uw_cfg_common'; + // Add our custom validation for banners. $form['#validate'][] = '_uw_cfg_common_banner_validate'; }