From c7d45c85a6ab2821621756f98cb51fc94f68283a Mon Sep 17 00:00:00 2001 From: Yeni Atencio Date: Tue, 1 Oct 2024 18:29:24 +1000 Subject: [PATCH 01/17] added logic for landing page --- .../tide_landing_page/js/hero_image_theme.js | 39 +++++++++++++++++++ .../tide_landing_page.libraries.yml | 1 + .../tide_landing_page.module | 8 ++-- 3 files changed, 43 insertions(+), 5 deletions(-) create mode 100644 modules/tide_landing_page/js/hero_image_theme.js diff --git a/modules/tide_landing_page/js/hero_image_theme.js b/modules/tide_landing_page/js/hero_image_theme.js new file mode 100644 index 000000000..10f88c2c4 --- /dev/null +++ b/modules/tide_landing_page/js/hero_image_theme.js @@ -0,0 +1,39 @@ +(function (Drupal) { + "use strict"; + + Drupal.behaviors.heroImageTheme = { + attach: function (context, settings) { + const imageTheme = document.querySelector( + 'select[data-drupal-selector^="edit-field-landing-page-hero-theme"]' + ); + + if (imageTheme !== null) { + setImageTheme(); + + const headerStyles = document.querySelectorAll( + 'input[data-drupal-selector^="edit-header-style-options"]' + ); + + if (headerStyles !== null) { + headerStyles.forEach((style) => { + style.addEventListener("change", () => { + setImageTheme(); + }); + }); + } + } + + function setImageTheme() { + let defaultHeaderStyle = document.querySelector( + 'input[data-drupal-selector^="edit-header-style-options"]:checked' + ).value; + + if (defaultHeaderStyle === "fullwidth") { + imageTheme.value = "dark"; + } else { + imageTheme.value = "light"; + } + } + }, + }; +})(Drupal); diff --git a/modules/tide_landing_page/tide_landing_page.libraries.yml b/modules/tide_landing_page/tide_landing_page.libraries.yml index 9f056fcd9..a0928ca57 100644 --- a/modules/tide_landing_page/tide_landing_page.libraries.yml +++ b/modules/tide_landing_page/tide_landing_page.libraries.yml @@ -5,5 +5,6 @@ landing_page_form: js: js/hide_elements.js: {} js/statistics_grid.js: {} + js/hero_image_theme.js: {} dependencies: - core/jquery diff --git a/modules/tide_landing_page/tide_landing_page.module b/modules/tide_landing_page/tide_landing_page.module index 5dee1ecfc..ace81857a 100644 --- a/modules/tide_landing_page/tide_landing_page.module +++ b/modules/tide_landing_page/tide_landing_page.module @@ -414,12 +414,10 @@ function _tide_landing_page_form_node_form_process(array $form, FormStateInterfa ], ]; - $form['field_landing_page_hero_image']['#states']['visible'] = [ - ':input[name="_header_style_options"]' => [ - ['value' => 'fullwidth'], - ['value' => 'cta'], - ], + $form['field_landing_page_hero_image']['widget']['field_landing_page_hero_theme']['#states']['enabled'] = [ + ':input[name="_header_style_options"]' => ['value' => 'corner'], ]; + $form['field_graphical_image']['#states']['visible'] = [ ':input[name="_header_style_options"]' => ['value' => 'corner'], ]; From 30e903b39d84bbc7c449c878ab7ae39499274ad2 Mon Sep 17 00:00:00 2001 From: Yeni Atencio Date: Tue, 1 Oct 2024 21:02:32 +1000 Subject: [PATCH 02/17] Added hook update --- ...ing_page.field_landing_page_hero_theme.yml | 4 ++-- .../tide_landing_page.install | 20 +++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/modules/tide_landing_page/config/install/field.field.node.landing_page.field_landing_page_hero_theme.yml b/modules/tide_landing_page/config/install/field.field.node.landing_page.field_landing_page_hero_theme.yml index 087e8ca17..6a6628c5a 100644 --- a/modules/tide_landing_page/config/install/field.field.node.landing_page.field_landing_page_hero_theme.yml +++ b/modules/tide_landing_page/config/install/field.field.node.landing_page.field_landing_page_hero_theme.yml @@ -10,9 +10,9 @@ id: node.landing_page.field_landing_page_hero_theme field_name: field_landing_page_hero_theme entity_type: node bundle: landing_page -label: Here image theme +label: Hero image theme description: 'If your hero image is mostly dark, apply the dark theme. This changes how the page title is displayed.' -required: false +required: true translatable: false default_value: { } default_value_callback: '' diff --git a/modules/tide_landing_page/tide_landing_page.install b/modules/tide_landing_page/tide_landing_page.install index b890acf77..c825cb4f2 100644 --- a/modules/tide_landing_page/tide_landing_page.install +++ b/modules/tide_landing_page/tide_landing_page.install @@ -175,3 +175,23 @@ function tide_landing_page_update_10105() { ]); $field_storage->save(); } + +/** + * Set field `field_landing_page_hero_theme` to mandatory. + */ +function tide_landing_page_update_10106() { + $bundles = [ + 'landing_page', + 'publication', + 'publication_page', + ]; + + foreach ($bundles as $bundle) { + $field = FieldConfig::loadByName('node', $bundle, 'field_landing_page_hero_theme'); + if (!empty($field)) { + $field->setLabel('Hero image theme'); + $field->setRequired(TRUE); + $field->save(); + } + } +} From 2c041b6de30ea0b0f29bbafc28ff3167a821c6b5 Mon Sep 17 00:00:00 2001 From: Yeni Atencio Date: Tue, 1 Oct 2024 21:35:02 +1000 Subject: [PATCH 03/17] updated behat test --- .../tide_landing_page/tests/behat/features/fields.feature | 4 ++++ modules/tide_publication/tide_publication.module | 7 ++----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/modules/tide_landing_page/tests/behat/features/fields.feature b/modules/tide_landing_page/tests/behat/features/fields.feature index 53568ea26..c9b09dd63 100644 --- a/modules/tide_landing_page/tests/behat/features/fields.feature +++ b/modules/tide_landing_page/tests/behat/features/fields.feature @@ -27,6 +27,7 @@ Feature: Fields for Landing Page content type And I should see text matching "Call to action banner" And I should see text matching "No Hero Banner with CTA added yet." And I should see the button "Add Hero banner with CTA" in the "content" region + And I should see a "select#edit-field-landing-page-hero-theme" element And the "#edit-field-landing-page-hero-logo" element should contain "Logo" And I should see an "input#edit-field-landing-page-hero-logo-entity-browser-entity-browser-open-modal" element @@ -34,6 +35,7 @@ Feature: Fields for Landing Page content type And I select the radio button "Corner graphics" And the "#edit-field-bottom-graphical-image" element should contain "Bottom Corner Graphic" And I should see an "input#edit-field-bottom-graphical-image-entity-browser-target" element + And I should see a "select#edit-field-landing-page-hero-theme" element And I click on the horizontal tab "Header extras" And I should see text matching "Header components" @@ -156,6 +158,7 @@ Feature: Fields for Landing Page content type And I should see text matching "Call to action banner" And I should see text matching "No Hero Banner with CTA added yet." And I should see the button "Add Hero banner with CTA" in the "content" region + And I should see a "select#edit-field-landing-page-hero-theme" element And the "#edit-field-landing-page-hero-logo" element should contain "Logo" And I should see an "input#edit-field-landing-page-hero-logo-entity-browser-entity-browser-open-modal" element @@ -163,6 +166,7 @@ Feature: Fields for Landing Page content type And I select the radio button "Corner graphics" And the "#edit-field-bottom-graphical-image" element should contain "Bottom Corner Graphic" And I should see an "input#edit-field-bottom-graphical-image-entity-browser-target" element + And I should see a "select#edit-field-landing-page-hero-theme" element And I click on the horizontal tab "Header extras" And I should see text matching "Header components" diff --git a/modules/tide_publication/tide_publication.module b/modules/tide_publication/tide_publication.module index 7dd65b6e5..47d35b5dd 100644 --- a/modules/tide_publication/tide_publication.module +++ b/modules/tide_publication/tide_publication.module @@ -128,11 +128,8 @@ function _tide_publication_form_node_form_process(array $form, FormStateInterfac ], ]; - $form['field_landing_page_hero_image']['#states']['visible'] = [ - ':input[name="_header_style_options"]' => [ - ['value' => 'fullwidth'], - ['value' => 'cta'], - ], + $form['field_landing_page_hero_image']['widget']['field_landing_page_hero_theme']['#states']['enabled'] = [ + ':input[name="_header_style_options"]' => ['value' => 'corner'], ]; // Determine the initial value of Header style. From f3a0c31b836ff813440510f06a6f0360dc68ae57 Mon Sep 17 00:00:00 2001 From: Yeni Atencio Date: Wed, 2 Oct 2024 17:55:32 +1000 Subject: [PATCH 04/17] remove patch as new released has been launched --- composer.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 412b399c3..5378be27b 100644 --- a/composer.json +++ b/composer.json @@ -436,8 +436,7 @@ "Support views data export using drush - https://www.drupal.org/project/views_data_export/issues/2887450#comment-15199879": "https://www.drupal.org/files/issues/2023-11-29/vde-drush-with-output-location-2887450-91.patch" }, "drupal/jsonapi_extras": { - "Make max value of page[limit] configurable per entity/bundle - https://www.drupal.org/project/jsonapi_extras/issues/2884292#comment-14794882": "https://www.drupal.org/files/issues/2022-11-21/max_page_limit_configuration-2884292-33.patch", - "Issue #3473990: Fix PHP Fatal error on Declaration of the normalize function must be compatible with normalize function return type after Schemata 8.x-1.0 was released": "https://git.drupalcode.org/project/jsonapi_extras/-/commit/d7ab37658999b5fae74769ade4155ec7310aa468.diff" + "Make max value of page[limit] configurable per entity/bundle - https://www.drupal.org/project/jsonapi_extras/issues/2884292#comment-14794882": "https://www.drupal.org/files/issues/2022-11-21/max_page_limit_configuration-2884292-33.patch" }, "drupal/jsonapi_menu_items": { "Allow filtering of response payload - https://www.drupal.org/project/jsonapi_menu_items/issues/3350524#comment-15577964": "https://www.drupal.org/files/issues/2024-05-02/3350524-filter_fields-6.patch" From 9672fbcdbd3d5e90aba322292c87784d5a248085 Mon Sep 17 00:00:00 2001 From: Yeni Atencio Date: Tue, 8 Oct 2024 21:53:43 +1100 Subject: [PATCH 05/17] Updated --- .../tide_landing_page/js/hero_image_theme.js | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/modules/tide_landing_page/js/hero_image_theme.js b/modules/tide_landing_page/js/hero_image_theme.js index 10f88c2c4..2b512ef3f 100644 --- a/modules/tide_landing_page/js/hero_image_theme.js +++ b/modules/tide_landing_page/js/hero_image_theme.js @@ -3,36 +3,36 @@ Drupal.behaviors.heroImageTheme = { attach: function (context, settings) { - const imageTheme = document.querySelector( + const imageTheme = context.querySelector( 'select[data-drupal-selector^="edit-field-landing-page-hero-theme"]' ); if (imageTheme !== null) { setImageTheme(); - const headerStyles = document.querySelectorAll( + const headerStyles = context.querySelectorAll( 'input[data-drupal-selector^="edit-header-style-options"]' ); - if (headerStyles !== null) { + if (headerStyles.length > 0) { headerStyles.forEach((style) => { - style.addEventListener("change", () => { - setImageTheme(); - }); + style.addEventListener("change", setImageTheme); }); } } function setImageTheme() { - let defaultHeaderStyle = document.querySelector( + const selectedHeaderStyle = document.querySelector( 'input[data-drupal-selector^="edit-header-style-options"]:checked' - ).value; + ); - if (defaultHeaderStyle === "fullwidth") { - imageTheme.value = "dark"; - } else { - imageTheme.value = "light"; + if (!selectedHeaderStyle) { + return; // Exit if no style option is selected. } + + let defaultHeaderStyle = selectedHeaderStyle.value; + imageTheme.value = + defaultHeaderStyle === "fullwidth" ? "dark" : "light"; } }, }; From 0e683159e89a06bb1547bd0227bd13f064b1071a Mon Sep 17 00:00:00 2001 From: Yeni Atencio Date: Mon, 28 Oct 2024 14:06:21 +1100 Subject: [PATCH 06/17] Replaced drupal state condition with JS due to bug in Drupal core #states when using ajax --- modules/tide_landing_page/js/hero_image_theme.js | 2 ++ modules/tide_landing_page/tide_landing_page.module | 4 ---- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/modules/tide_landing_page/js/hero_image_theme.js b/modules/tide_landing_page/js/hero_image_theme.js index 2b512ef3f..6a86c059f 100644 --- a/modules/tide_landing_page/js/hero_image_theme.js +++ b/modules/tide_landing_page/js/hero_image_theme.js @@ -31,6 +31,8 @@ } let defaultHeaderStyle = selectedHeaderStyle.value; + imageTheme.disabled = + defaultHeaderStyle === "corner" ? false : true; imageTheme.value = defaultHeaderStyle === "fullwidth" ? "dark" : "light"; } diff --git a/modules/tide_landing_page/tide_landing_page.module b/modules/tide_landing_page/tide_landing_page.module index 6b507adee..d87f842c4 100644 --- a/modules/tide_landing_page/tide_landing_page.module +++ b/modules/tide_landing_page/tide_landing_page.module @@ -409,10 +409,6 @@ function _tide_landing_page_form_node_form_process(array $form, FormStateInterfa ], ]; - $form['field_landing_page_hero_image']['widget']['field_landing_page_hero_theme']['#states']['enabled'] = [ - ':input[name="_header_style_options"]' => ['value' => 'corner'], - ]; - $form['field_graphical_image']['#states']['visible'] = [ ':input[name="_header_style_options"]' => ['value' => 'corner'], ]; From ab1735afc0383f7a0e6531faf8a162ed9e0c957d Mon Sep 17 00:00:00 2001 From: Yeni Atencio Date: Sun, 17 Nov 2024 20:46:33 +1100 Subject: [PATCH 07/17] Implement feedback --- modules/tide_landing_page/js/hero_image_theme.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/modules/tide_landing_page/js/hero_image_theme.js b/modules/tide_landing_page/js/hero_image_theme.js index 6a86c059f..a4f9a82d0 100644 --- a/modules/tide_landing_page/js/hero_image_theme.js +++ b/modules/tide_landing_page/js/hero_image_theme.js @@ -1,8 +1,8 @@ (function (Drupal) { - "use strict"; + 'use strict'; Drupal.behaviors.heroImageTheme = { - attach: function (context, settings) { + attach: function (context) { const imageTheme = context.querySelector( 'select[data-drupal-selector^="edit-field-landing-page-hero-theme"]' ); @@ -16,13 +16,13 @@ if (headerStyles.length > 0) { headerStyles.forEach((style) => { - style.addEventListener("change", setImageTheme); + style.addEventListener('change', setImageTheme); }); } } function setImageTheme() { - const selectedHeaderStyle = document.querySelector( + const selectedHeaderStyle = context.querySelector( 'input[data-drupal-selector^="edit-header-style-options"]:checked' ); @@ -31,10 +31,9 @@ } let defaultHeaderStyle = selectedHeaderStyle.value; - imageTheme.disabled = - defaultHeaderStyle === "corner" ? false : true; + imageTheme.disabled = defaultHeaderStyle === 'corner' ? false : true; imageTheme.value = - defaultHeaderStyle === "fullwidth" ? "dark" : "light"; + defaultHeaderStyle === 'fullwidth' ? 'dark' : 'light'; } }, }; From 4d1de876799b820bd77ebd2b8a67d89bac92ecb2 Mon Sep 17 00:00:00 2001 From: Vincent Gao Date: Mon, 18 Nov 2024 18:45:41 +1100 Subject: [PATCH 08/17] test --- .../tide_landing_page.module | 29 ++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/modules/tide_landing_page/tide_landing_page.module b/modules/tide_landing_page/tide_landing_page.module index d87f842c4..107649ee5 100644 --- a/modules/tide_landing_page/tide_landing_page.module +++ b/modules/tide_landing_page/tide_landing_page.module @@ -44,7 +44,7 @@ function tide_landing_page_entity_bundle_create($entity_type_id, $bundle) { $editorial_workflow = Workflow::load('editorial'); if ($editorial_workflow) { $editorial_workflow->getTypePlugin() - ->addEntityTypeAndBundle('node', 'landing_page'); + ->addEntityTypeAndBundle('node', 'landing_page'); $editorial_workflow->save(); } } @@ -373,6 +373,23 @@ function tide_landing_page_field_widget_single_element_paragraphs_form_alter(&$e } } +function change_the_value($form, FormStateInterface $form_state): \Drupal\Core\Ajax\AjaxResponse { + $response = new \Drupal\Core\Ajax\AjaxResponse(); + $value = $form_state->getValue('_header_style_options'); + if ($value === 'fullwidth'){ + return $response->addCommand(new \Drupal\Core\Ajax\InvokeCommand( + '#edit-field-landing-page-hero-theme', + 'val', + ['dark'] + )); + } + return $response->addCommand(new \Drupal\Core\Ajax\InvokeCommand( + '#edit-field-landing-page-hero-theme', + 'val', + ['light'] + )); +} + /** * Node form #process callback. * @@ -407,6 +424,16 @@ function _tide_landing_page_form_node_form_process(array $form, FormStateInterfa 'corner' => t('Corner graphics'), 'cta' => t('Call to action banner'), ], + '#ajax' => [ + 'callback' => 'change_the_value', + ], + ]; + $form['field_landing_page_hero_image']['widget']['field_landing_page_hero_theme']['#states']['disabled'] = [ + ':input[name="_header_style_options"]' => [ + ['value' => 'default'], + ['value' => 'fullwidth'], + ['value' => 'cta'], + ], ]; $form['field_graphical_image']['#states']['visible'] = [ From 294b0c698029999fc994009cbfa969d83a6bef9c Mon Sep 17 00:00:00 2001 From: Yeni Atencio Date: Thu, 21 Nov 2024 12:26:39 +1100 Subject: [PATCH 09/17] fixed lint --- .../tide_landing_page/tide_landing_page.module | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/modules/tide_landing_page/tide_landing_page.module b/modules/tide_landing_page/tide_landing_page.module index 107649ee5..772b81062 100644 --- a/modules/tide_landing_page/tide_landing_page.module +++ b/modules/tide_landing_page/tide_landing_page.module @@ -6,6 +6,8 @@ */ use Drupal\Core\Cache\Cache; +use \Drupal\Core\Ajax\AjaxResponse; +use \Drupal\Core\Ajax\InvokeCommand; use Drupal\Core\Field\WidgetBase; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Render\Element; @@ -44,7 +46,7 @@ function tide_landing_page_entity_bundle_create($entity_type_id, $bundle) { $editorial_workflow = Workflow::load('editorial'); if ($editorial_workflow) { $editorial_workflow->getTypePlugin() - ->addEntityTypeAndBundle('node', 'landing_page'); + ->addEntityTypeAndBundle('node', 'landing_page'); $editorial_workflow->save(); } } @@ -373,17 +375,17 @@ function tide_landing_page_field_widget_single_element_paragraphs_form_alter(&$e } } -function change_the_value($form, FormStateInterface $form_state): \Drupal\Core\Ajax\AjaxResponse { - $response = new \Drupal\Core\Ajax\AjaxResponse(); +function tide_landing_page_change_the_value($form, FormStateInterface $form_state): \Drupal\Core\Ajax\AjaxResponse { + $response = new AjaxResponse(); $value = $form_state->getValue('_header_style_options'); - if ($value === 'fullwidth'){ - return $response->addCommand(new \Drupal\Core\Ajax\InvokeCommand( + if ($value === 'fullwidth') { + return $response->addCommand(new InvokeCommand( '#edit-field-landing-page-hero-theme', 'val', ['dark'] )); } - return $response->addCommand(new \Drupal\Core\Ajax\InvokeCommand( + return $response->addCommand(new InvokeCommand( '#edit-field-landing-page-hero-theme', 'val', ['light'] @@ -425,7 +427,7 @@ function _tide_landing_page_form_node_form_process(array $form, FormStateInterfa 'cta' => t('Call to action banner'), ], '#ajax' => [ - 'callback' => 'change_the_value', + 'callback' => 'tide_landing_page_change_the_value', ], ]; $form['field_landing_page_hero_image']['widget']['field_landing_page_hero_theme']['#states']['disabled'] = [ From eb3f8025602abf1ef0c2c58df34658486dfa443e Mon Sep 17 00:00:00 2001 From: Yeni Atencio Date: Thu, 21 Nov 2024 13:01:09 +1100 Subject: [PATCH 10/17] added function description --- .../tide_landing_page/tide_landing_page.module | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/modules/tide_landing_page/tide_landing_page.module b/modules/tide_landing_page/tide_landing_page.module index 772b81062..2f7abf2a3 100644 --- a/modules/tide_landing_page/tide_landing_page.module +++ b/modules/tide_landing_page/tide_landing_page.module @@ -5,9 +5,9 @@ * Tide Landing Page module functionality. */ +use Drupal\Core\Ajax\AjaxResponse; +use Drupal\Core\Ajax\InvokeCommand; use Drupal\Core\Cache\Cache; -use \Drupal\Core\Ajax\AjaxResponse; -use \Drupal\Core\Ajax\InvokeCommand; use Drupal\Core\Field\WidgetBase; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Render\Element; @@ -375,7 +375,18 @@ function tide_landing_page_field_widget_single_element_paragraphs_form_alter(&$e } } -function tide_landing_page_change_the_value($form, FormStateInterface $form_state): \Drupal\Core\Ajax\AjaxResponse { +/** + * Function to change value. + * + * @param array $form + * The form. + * @param FormStateInterface $form_state + * The form state. + * + * @return AjaxResponse + * The response. + */ +function tide_landing_page_change_the_value(array $form, FormStateInterface $form_state): AjaxResponse { $response = new AjaxResponse(); $value = $form_state->getValue('_header_style_options'); if ($value === 'fullwidth') { From c2996c2c431a2c4f1caf3d7bad5d70dc6db517af Mon Sep 17 00:00:00 2001 From: Yeni Atencio Date: Thu, 21 Nov 2024 13:25:38 +1100 Subject: [PATCH 11/17] added function description --- modules/tide_landing_page/tide_landing_page.module | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/tide_landing_page/tide_landing_page.module b/modules/tide_landing_page/tide_landing_page.module index 2f7abf2a3..e78b8c140 100644 --- a/modules/tide_landing_page/tide_landing_page.module +++ b/modules/tide_landing_page/tide_landing_page.module @@ -380,10 +380,10 @@ function tide_landing_page_field_widget_single_element_paragraphs_form_alter(&$e * * @param array $form * The form. - * @param FormStateInterface $form_state + * @param Drupal\Core\Form\FormStateInterface $form_state * The form state. * - * @return AjaxResponse + * @return Drupal\Core\Ajax\AjaxResponse * The response. */ function tide_landing_page_change_the_value(array $form, FormStateInterface $form_state): AjaxResponse { From 6a00fe0c25b84d13520822c9e920f07c5fd54861 Mon Sep 17 00:00:00 2001 From: Yeni Atencio Date: Mon, 25 Nov 2024 20:02:40 +1100 Subject: [PATCH 12/17] removed js --- .../tide_landing_page/js/hero_image_theme.js | 40 ------------------- .../tests/behat/features/fields.feature | 9 +++++ .../tide_landing_page.install | 1 + .../tide_landing_page.libraries.yml | 1 - .../tide_landing_page.module | 4 +- 5 files changed, 12 insertions(+), 43 deletions(-) delete mode 100644 modules/tide_landing_page/js/hero_image_theme.js diff --git a/modules/tide_landing_page/js/hero_image_theme.js b/modules/tide_landing_page/js/hero_image_theme.js deleted file mode 100644 index a4f9a82d0..000000000 --- a/modules/tide_landing_page/js/hero_image_theme.js +++ /dev/null @@ -1,40 +0,0 @@ -(function (Drupal) { - 'use strict'; - - Drupal.behaviors.heroImageTheme = { - attach: function (context) { - const imageTheme = context.querySelector( - 'select[data-drupal-selector^="edit-field-landing-page-hero-theme"]' - ); - - if (imageTheme !== null) { - setImageTheme(); - - const headerStyles = context.querySelectorAll( - 'input[data-drupal-selector^="edit-header-style-options"]' - ); - - if (headerStyles.length > 0) { - headerStyles.forEach((style) => { - style.addEventListener('change', setImageTheme); - }); - } - } - - function setImageTheme() { - const selectedHeaderStyle = context.querySelector( - 'input[data-drupal-selector^="edit-header-style-options"]:checked' - ); - - if (!selectedHeaderStyle) { - return; // Exit if no style option is selected. - } - - let defaultHeaderStyle = selectedHeaderStyle.value; - imageTheme.disabled = defaultHeaderStyle === 'corner' ? false : true; - imageTheme.value = - defaultHeaderStyle === 'fullwidth' ? 'dark' : 'light'; - } - }, - }; -})(Drupal); diff --git a/modules/tide_landing_page/tests/behat/features/fields.feature b/modules/tide_landing_page/tests/behat/features/fields.feature index c9b09dd63..280d5de7a 100644 --- a/modules/tide_landing_page/tests/behat/features/fields.feature +++ b/modules/tide_landing_page/tests/behat/features/fields.feature @@ -304,3 +304,12 @@ Feature: Fields for Landing Page content type # This field can be "seen" but not visible. And I see field "field_landing_page_component[0][subform][field_customise][value]" And save screenshot + + @api @javascript + Scenario: Selecting a value from the field Hero image theme. + Given I am logged in as a user with the "create landing_page content" permission + When I visit "node/add/landing_page" + And I click "Customised Header" + Then I select "Corner graphics" from "edit-header-style-options-corner" + Then I select "Hero image theme" from "edit-field-landing-page-hero-theme" + And save screenshot diff --git a/modules/tide_landing_page/tide_landing_page.install b/modules/tide_landing_page/tide_landing_page.install index b2869d956..126dc781c 100644 --- a/modules/tide_landing_page/tide_landing_page.install +++ b/modules/tide_landing_page/tide_landing_page.install @@ -210,6 +210,7 @@ function tide_landing_page_update_10107() { if (!empty($field)) { $field->setLabel('Hero image theme'); $field->setRequired(TRUE); + $field->setDefaultValue('light'); $field->save(); } } diff --git a/modules/tide_landing_page/tide_landing_page.libraries.yml b/modules/tide_landing_page/tide_landing_page.libraries.yml index a0928ca57..9f056fcd9 100644 --- a/modules/tide_landing_page/tide_landing_page.libraries.yml +++ b/modules/tide_landing_page/tide_landing_page.libraries.yml @@ -5,6 +5,5 @@ landing_page_form: js: js/hide_elements.js: {} js/statistics_grid.js: {} - js/hero_image_theme.js: {} dependencies: - core/jquery diff --git a/modules/tide_landing_page/tide_landing_page.module b/modules/tide_landing_page/tide_landing_page.module index e78b8c140..d1934a6f7 100644 --- a/modules/tide_landing_page/tide_landing_page.module +++ b/modules/tide_landing_page/tide_landing_page.module @@ -376,7 +376,7 @@ function tide_landing_page_field_widget_single_element_paragraphs_form_alter(&$e } /** - * Function to change value. + * Function to set value to Hero image theme. * * @param array $form * The form. @@ -386,7 +386,7 @@ function tide_landing_page_field_widget_single_element_paragraphs_form_alter(&$e * @return Drupal\Core\Ajax\AjaxResponse * The response. */ -function tide_landing_page_change_the_value(array $form, FormStateInterface $form_state): AjaxResponse { +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') { From 950b3f8830860bceadaae28b370b546ee186c75c Mon Sep 17 00:00:00 2001 From: Yeni Atencio <47239456+yeniatencio@users.noreply.github.com> Date: Mon, 25 Nov 2024 20:12:58 +1100 Subject: [PATCH 13/17] Update tide_landing_page.module --- modules/tide_landing_page/tide_landing_page.module | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/tide_landing_page/tide_landing_page.module b/modules/tide_landing_page/tide_landing_page.module index b724733a0..6b9007d56 100644 --- a/modules/tide_landing_page/tide_landing_page.module +++ b/modules/tide_landing_page/tide_landing_page.module @@ -436,7 +436,7 @@ function _tide_landing_page_form_node_form_process(array $form, FormStateInterfa 'cta' => t('Call to action banner'), ], '#ajax' => [ - 'callback' => 'tide_landing_page_change_the_value', + 'callback' => 'tide_landing_page_set_value_hero_image_theme', ], ]; $form['field_landing_page_hero_image']['widget']['field_landing_page_hero_theme']['#states']['disabled'] = [ From 4524117c9ca266f8320f3de7be3c6210c93d71dd Mon Sep 17 00:00:00 2001 From: Yeni Atencio Date: Mon, 25 Nov 2024 20:24:40 +1100 Subject: [PATCH 14/17] upgrade search api version --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 6c82c5535..be29f2b95 100644 --- a/composer.json +++ b/composer.json @@ -37,7 +37,7 @@ "drupal/maxlength": "^2.1", "drupal/entity_hierarchy": "4.x", "drupal/elasticsearch_connector": "^7.0", - "drupal/search_api": "^1.11", + "drupal/search_api": "^1.36", "drupal/data_pipelines": "1.0.0-alpha22", "drupal/data_pipelines_elasticsearch": "^1.0@alpha", "drupal/key": "^1.17", From ad83ea7e66bf1e12de1c8dba6c509e9eefe49df7 Mon Sep 17 00:00:00 2001 From: Yeni Atencio Date: Mon, 25 Nov 2024 20:33:12 +1100 Subject: [PATCH 15/17] upgrade patch --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index be29f2b95..fbeaa1696 100644 --- a/composer.json +++ b/composer.json @@ -406,7 +406,7 @@ "[UX] Add the ability to hide or disable the import CSV option - https://www.drupal.org/project/tablefield/issues/2337743": "https://www.drupal.org/files/issues/2020-11-11/tablefield-allowed_data_sources-2337743-16.patch" }, "drupal/search_api": { - "Provide drush support to index a specific entity - https://www.drupal.org/project/search_api/issues/3016809": "https://www.drupal.org/files/issues/2020-02-08/search_api-index-specific-items-3016809-09.patch" + "Provide drush support to index a specific entity - https://www.drupal.org/project/search_api/issues/3016809": "https://www.drupal.org/files/issues/2024-11-25/search_api-index-specific-items-3016809-10.patch" }, "drupal/key": { "KeyProviderInterface::getKeyValue() doesn't always return a string - https://www.drupal.org/project/key/issues/3356052#comment-15030602": "https://git.drupalcode.org/project/key/-/merge_requests/11/diffs.patch", From 9289343db350057301167dcc650ec23ac717f5be Mon Sep 17 00:00:00 2001 From: Yeni Atencio Date: Tue, 26 Nov 2024 10:10:36 +1100 Subject: [PATCH 16/17] added behat test for hero theme scenarios --- .../tests/behat/features/fields.feature | 45 ++++++++++++++++--- 1 file changed, 40 insertions(+), 5 deletions(-) diff --git a/modules/tide_landing_page/tests/behat/features/fields.feature b/modules/tide_landing_page/tests/behat/features/fields.feature index 280d5de7a..1ea3e80b2 100644 --- a/modules/tide_landing_page/tests/behat/features/fields.feature +++ b/modules/tide_landing_page/tests/behat/features/fields.feature @@ -306,10 +306,45 @@ Feature: Fields for Landing Page content type And save screenshot @api @javascript - Scenario: Selecting a value from the field Hero image theme. - Given I am logged in as a user with the "create landing_page content" permission + Scenario: Selecting Corner graphics value from header style. + Given I am logged in as a user with the "editor" role + When I visit "node/add/landing_page" + And I click on the horizontal tab "Customised Header" + Then I should see an "#edit-header-style-options-corner" element + And I select "corner" from "edit-header-style-options-corner" + Then I should see an "#edit-field-landing-page-hero-theme" element + And I should see text matching "Light" + And save screenshot + + @api @javascript + Scenario: Selecting Default appearance value from header style. + Given I am logged in as a user with the "editor" role When I visit "node/add/landing_page" - And I click "Customised Header" - Then I select "Corner graphics" from "edit-header-style-options-corner" - Then I select "Hero image theme" from "edit-field-landing-page-hero-theme" + And I click on the horizontal tab "Customised Header" + Then I should see an "#edit-header-style-options-default" element + And I select "corner" from "edit-header-style-options-default" + Then I should see an "#edit-field-landing-page-hero-theme" element + And I should see text matching "Light" + And save screenshot + +@api @javascript + Scenario: Selecting Full-width background image value from header style. + Given I am logged in as a user with the "editor" role + When I visit "node/add/landing_page" + And I click on the horizontal tab "Customised Header" + Then I should see an "#edit-header-style-options-fullwidtht" element + And I select "corner" from "edit-header-style-options-fullwidth" + Then I should see an "#edit-field-landing-page-hero-theme" element + And I should see text matching "Dark" + And save screenshot + +@api @javascript + Scenario: Selecting Call to action banner value from header style. + Given I am logged in as a user with the "editor" role + When I visit "node/add/landing_page" + And I click on the horizontal tab "Customised Header" + Then I should see an "#edit-header-style-options-cta" element + And I select "corner" from "edit-header-style-options-cta" + Then I should see an "#edit-field-landing-page-hero-theme" element + And I should see text matching "Light" And save screenshot From 66d86884f419116e5354617452e86e1167f23ba6 Mon Sep 17 00:00:00 2001 From: Yeni Atencio Date: Tue, 26 Nov 2024 10:27:45 +1100 Subject: [PATCH 17/17] fixed lint --- .../src/Plugin/Filter/FilterResizeTableColumns.php | 2 -- modules/tide_ckeditor/tide_ckeditor.install | 7 ++++--- .../Plugin/jsonapi/FieldEnhancer/BasicTextEnhancer.php | 10 +++++++--- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/modules/tide_ckeditor/modules/ckeditor_tablecol_resize/src/Plugin/Filter/FilterResizeTableColumns.php b/modules/tide_ckeditor/modules/ckeditor_tablecol_resize/src/Plugin/Filter/FilterResizeTableColumns.php index 8d1ef0ae6..bfd26ad0f 100644 --- a/modules/tide_ckeditor/modules/ckeditor_tablecol_resize/src/Plugin/Filter/FilterResizeTableColumns.php +++ b/modules/tide_ckeditor/modules/ckeditor_tablecol_resize/src/Plugin/Filter/FilterResizeTableColumns.php @@ -4,9 +4,7 @@ use Drupal\ckeditor5\Plugin\CKEditor5PluginManagerInterface; use Drupal\Component\Utility\Html; -use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; -use Drupal\Core\Routing\CurrentRouteMatch; use Drupal\filter\FilterProcessResult; use Drupal\filter\Plugin\FilterBase; use Psr\Container\ContainerInterface; diff --git a/modules/tide_ckeditor/tide_ckeditor.install b/modules/tide_ckeditor/tide_ckeditor.install index 47bcde624..4c8ed1760 100644 --- a/modules/tide_ckeditor/tide_ckeditor.install +++ b/modules/tide_ckeditor/tide_ckeditor.install @@ -47,16 +47,17 @@ function tide_ckeditor_update_10002() { if ($filter) { // Add , , and to allowed HTML. $additional_allowed_tags = ' '; - // Append the new tags to the allowed HTML, making sure not to add duplicates + // Append the new tags to the allowed HTML, + // making sure not to add duplicates $replaced = $allowed_html . ' ' . $additional_allowed_tags; $replaced = trim($replaced, ','); - // Set the updated allowed HTML tags in the filter + // Set the updated allowed HTML tags in the filter. $filter->set('filters.filter_html.settings.allowed_html', $replaced); $filter->set('filters.filter_resize_tablecolumns', [ 'id' => 'filter_resize_tablecolumns', 'provider' => 'ckeditor_tablecol_resize', - 'status' => true, + 'status' => TRUE, 'weight' => 99, 'settings' => [], ]); diff --git a/modules/tide_landing_page/src/Plugin/jsonapi/FieldEnhancer/BasicTextEnhancer.php b/modules/tide_landing_page/src/Plugin/jsonapi/FieldEnhancer/BasicTextEnhancer.php index b3cf7b5b3..bd165bf65 100644 --- a/modules/tide_landing_page/src/Plugin/jsonapi/FieldEnhancer/BasicTextEnhancer.php +++ b/modules/tide_landing_page/src/Plugin/jsonapi/FieldEnhancer/BasicTextEnhancer.php @@ -83,6 +83,9 @@ public function replaceUnicodeWhitespace(array $data) { return $data; } + /** + * Helper function to add table styles to processed field. + */ public function addTableStylesToProcessed(&$data) { // Check if 'value' and 'processed' keys exist in $data. if (isset($data['value']) && isset($data['processed'])) { @@ -91,7 +94,7 @@ public function addTableStylesToProcessed(&$data) { $processedDom = new \DOMDocument(); // Suppress warnings for malformed HTML in $value and $processed. - libxml_use_internal_errors(true); + libxml_use_internal_errors(TRUE); $valueDom->loadHTML($data['value']); $processedDom->loadHTML($data['processed']); libxml_clear_errors(); @@ -117,14 +120,14 @@ public function addTableStylesToProcessed(&$data) { $processedCol = $processedCols->item($j); if ($valueCol->hasAttribute('style')) { - // Parse the style attribute. + // Parse the style attribute. $styleValue = $valueCol->getAttribute('style'); $styles = explode(';', $styleValue); foreach ($styles as $style) { $style = trim($style); if (!empty($style)) { - list($property, $value) = explode(':', $style, 2); + [$property, $value] = explode(':', $style, 2); $property = trim($property); $value = trim($value); @@ -149,4 +152,5 @@ public function addTableStylesToProcessed(&$data) { } return $data; } + }