Skip to content

Commit

Permalink
Merge branch 'release/5.0.4'
Browse files Browse the repository at this point in the history
  • Loading branch information
vincent-gao committed Jan 9, 2025
2 parents 9f5a14b + f3a0ee4 commit 7054e21
Show file tree
Hide file tree
Showing 20 changed files with 465 additions and 29 deletions.
Binary file modified .DS_Store
Binary file not shown.
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,9 @@
"codemirror/codemirror": "5.65.12",
"jquery/inputmask": "5.0.8",
"jquery/intl-tel-input": "17.0.19",
"progress-tracker/progress-tracker": "2.0.7"
"progress-tracker/progress-tracker": "2.0.7",
"drupal/shield": "^1.8",
"drupal/media_alias_display": "^2.1"
},
"repositories": {
"drupal": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,8 @@ third_party_settings:
label: 'Customised Header'
parent_name: group_section_header
children:
- field_landing_page_hero_image
- field_landing_page_hero_theme
- field_landing_page_hero_image
- field_landing_page_hero_logo
- field_graphical_image
- field_bottom_graphical_image
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ 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
description: 'If your hero image is mostly dark, apply the dark theme. This changes how the page title is displayed.'
required: false
label: Page title display style
description: 'By default the page title will display in the site’s primary colour. If you choose ‘Reverse blocked text’ the heading and introduction text will be white with a coloured block behind the text (the site’s ‘accent contrast’ and ‘accent alternate’ colours). See <a href="https://ripple.sdp.vic.gov.au/design-system/components/header">Ripple header page to understand the header </a>component design.'
required: true
translatable: false
default_value: { }
default_value:
-
value: light
default_value_callback: ''
settings: { }
field_type: list_string
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ settings:
allowed_values:
-
value: dark
label: Dark
label: Reverse blocked text
-
value: light
label: Light
label: Default
allowed_values_function: ''
module: options
locked: false
Expand Down
49 changes: 49 additions & 0 deletions modules/tide_landing_page/tests/behat/features/fields.feature
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ Feature: Fields for Landing Page content type
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"
And I press the "edit-field-landing-page-header-add-more-add-modal-form-area-add-more" button
Expand Down Expand Up @@ -164,6 +166,8 @@ Feature: Fields for Landing Page content type
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"
And I press the "edit-field-landing-page-header-add-more-add-modal-form-area-add-more" button
Expand Down Expand Up @@ -300,3 +304,48 @@ 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 "Default"
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 "Default"
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 "Reverse blocked text"
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 "Default"
And save screenshot
40 changes: 40 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,43 @@ 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, description, label.
*/
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('Page title display style');
$field->setRequired(TRUE);
$field->setDefaultValue('light');
$field->setDescription('By default the page title will display in the site’s primary colour. If you choose ‘Reverse blocked text’ the heading and introduction text will be white with a coloured block behind the text (the site’s ‘accent contrast’ and ‘accent alternate’ colours). See <a href="https://ripple.sdp.vic.gov.au/design-system/components/header">Ripple header page to understand the header </a>component design.');
$field->save();
}
}
}

/**
* Set label options for `field_landing_page_hero_theme`.
*/
function tide_landing_page_update_10109() {
$config = \Drupal::configFactory()->getEditable('field.storage.node.field_landing_page_hero_theme');
$allowed_values = $config->get('settings.allowed_values');
foreach ($allowed_values as $key => $allowed_value) {
if ($allowed_value['label'] === 'Dark') {
$allowed_values[$key]['label'] = 'Reverse blocked text';
}
elseif ($allowed_value['label'] === 'Light') {
$allowed_values[$key]['label'] = 'Default';
}
}
$config->set('settings.allowed_values', $allowed_values);
$config->save();
}
46 changes: 41 additions & 5 deletions modules/tide_landing_page/tide_landing_page.module
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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])) {
Expand Down Expand Up @@ -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.
*
Expand Down Expand Up @@ -405,6 +430,16 @@ 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'] = [
':input[name="_header_style_options"]' => [
['value' => 'fullwidth'],
['value' => 'cta'],
],
];

$form['field_landing_page_hero_image']['#states']['visible'] = [
Expand All @@ -413,6 +448,7 @@ function _tide_landing_page_form_node_form_process(array $form, FormStateInterfa
['value' => 'cta'],
],
];

$form['field_graphical_image']['#states']['visible'] = [
':input[name="_header_style_options"]' => ['value' => 'corner'],
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,38 @@ function tide_media_secure_files_uninstall() {
\Drupal::service('module_installer')->uninstall(['pfdp']);
}

/**
* Adds a secure file widget to entity browser.
*/
function _create_secure_file_widget() {
if (\Drupal::moduleHandler()->moduleExists('entity_browser')) {
$uuid = \Drupal::service('uuid')->generate();
$secure_file_widget = [
'id' => 'entity_form',
'uuid' => $uuid,
'label' => 'Add secure file',
'weight' => 6,
'settings' => [
'submit_text' => 'Save secure file',
'entity_type' => 'media',
'bundle' => 'secure_file',
'form_mode' => 'default',
],
];

$config = \Drupal::configFactory()->getEditable('entity_browser.browser.tide_media_browser_iframe');
$widgets = $config->get('widgets');
if (!is_array($widgets)) {
$widgets = [];
}
if (!in_array($secure_file_widget, $widgets)) {
$widgets[$uuid] = $secure_file_widget;
$config->set('widgets', $widgets);
$config->save();
}
}
}

/**
* Implements hook_install().
*/
Expand All @@ -71,4 +103,13 @@ function tide_media_secure_files_install() {
user_role_grant_permissions($role->id(), ['view field_secure_file']);
}
}

_create_secure_file_widget();
}

/**
* Adds secure file widget to entity browser.
*/
function tide_media_secure_files_update_10001() {
_create_secure_file_widget();
}
20 changes: 20 additions & 0 deletions modules/tide_media/tide_media.install
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,23 @@ function tide_media_update_10005() {
$config->set('track_enabled_target_entity_types', $result);
$config->save();
}

/**
* Adds media_alias_display settings for document type.
*/
function tide_media_update_10006() {
// Check if the media_library module is enabled, enable it.
if (\Drupal::moduleHandler()->moduleExists('media_library') === FALSE) {
\Drupal::service('module_installer')->install(['media_library']);
}

if (\Drupal::moduleHandler()->moduleExists('media_alias_display') === FALSE) {
\Drupal::service('module_installer')->install(['media_alias_display']);
}

$media_config = \Drupal::service('config.factory')->getEditable('media_alias_display.settings');
if ($media_config) {
$media_config->set('media_bundles', ['document' => 'document']);
$media_config->save();
}
}
36 changes: 36 additions & 0 deletions modules/tide_media/tide_media.module
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

use Drupal\Component\Render\FormattableMarkup;
use Drupal\Core\Cache\RefinableCacheableDependencyInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Field\BaseFieldDefinition;
Expand All @@ -16,6 +17,7 @@ use Drupal\Core\Link;
use Drupal\Core\Url;
use Drupal\file\FileInterface;
use Drupal\views\ViewExecutable;
use Symfony\Component\HttpFoundation\RedirectResponse;

/**
* Implements hook_views_pre_view().
Expand Down Expand Up @@ -464,3 +466,37 @@ function tide_media_file_presave(FileInterface $file) {
$file->setFilename($filename_new);
}
}

/**
* Implements hook_preprocess_HOOK().
*/
function tide_media_preprocess_page(&$variables) {
$route_name = \Drupal::routeMatch()->getRouteName();
$current_user = \Drupal::currentUser();
$roles = $current_user->getRoles();

if ($route_name === 'entity.user.edit_form' && in_array('secure_file_user', $roles)) {
$url = Url::fromRoute('entity.user.canonical', ['user' => $current_user->id()]);
$response = new RedirectResponse($url->toString());
$response->send();
}
}

/**
* Implements hook_menu_local_tasks_alter().
*/
function tide_media_menu_local_tasks_alter(&$data, $route_name, RefinableCacheableDependencyInterface &$cacheability) {
$current_user = \Drupal::currentUser();
$roles = $current_user->getRoles();
if (in_array('secure_file_user', $roles, TRUE) && isset($data['tabs'])) {
foreach ($data['tabs'] as $key => &$tabs) {
if (is_array($tabs)) {
foreach ($tabs as $tab_key => $tab) {
if ($tab_key === 'entity.user.edit_form') {
unset($tabs[$tab_key]);
}
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
box-shadow: none !important;
border: none !important;
padding: 0 0 0.5em;
text-wrap: pretty;
}

.paragraphs-add-dialog-enhanced .paragraphs-add-dialog-list .paragraphs-add-dialog-row .description {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ third_party_settings:
label: 'Customised Header'
parent_name: group_section_header
children:
- field_landing_page_hero_image
- field_landing_page_hero_theme
- field_landing_page_hero_image
format_type: tab
format_settings:
description: ''
Expand Down
Loading

0 comments on commit 7054e21

Please sign in to comment.