Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SD-22] Updated hero theme image #555

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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: ''
Expand Down
40 changes: 40 additions & 0 deletions modules/tide_landing_page/js/hero_image_theme.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
(function (Drupal) {
"use strict";

Drupal.behaviors.heroImageTheme = {
attach: function (context, settings) {
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 = document.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);
48 changes: 48 additions & 0 deletions modules/tide_landing_page/tests/behat/features/fields.feature
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@ 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

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"
Expand Down Expand Up @@ -156,13 +158,15 @@ 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

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"
Expand Down Expand Up @@ -300,3 +304,47 @@ 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 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 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
21 changes: 21 additions & 0 deletions modules/tide_landing_page/tide_landing_page.install
Original file line number Diff line number Diff line change
Expand Up @@ -203,3 +203,24 @@ function tide_landing_page_update_10107() {
$tide_update_helper = \Drupal::service('tide_core.entity_update_helper');
$tide_update_helper->revert('field_config', 'paragraph.key_journeys.field_paragraph_title');
}

/**
* Set field `field_landing_page_hero_theme` to mandatory.
*/
function tide_landing_page_update_10108() {
$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->setDefaultValue('light');
$field->save();
}
}
}
1 change: 1 addition & 0 deletions modules/tide_landing_page/tide_landing_page.libraries.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ landing_page_form:
js:
js/hide_elements.js: {}
js/statistics_grid.js: {}
js/hero_image_theme.js: {}
dependencies:
- core/jquery
5 changes: 3 additions & 2 deletions modules/tide_landing_page/tide_landing_page.module
Original file line number Diff line number Diff line change
Expand Up @@ -406,13 +406,14 @@ function _tide_landing_page_form_node_form_process(array $form, FormStateInterfa
'cta' => t('Call to action banner'),
],
];

$form['field_landing_page_hero_image']['#states']['visible'] = [
$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'] = [
':input[name="_header_style_options"]' => ['value' => 'corner'],
];
Expand Down
7 changes: 2 additions & 5 deletions modules/tide_publication/tide_publication.module
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down