Skip to content

Commit

Permalink
[SD-345] Implement Ability to Remove Quick Exit from Specific Site Se…
Browse files Browse the repository at this point in the history
…ctions (#524)

* SD-345 Site specific quick exit change

* Reverted previous update hook

* Fixed review comments

* updated link (#521)

* [SD-418] add validation delete bulk approver (#527)

* added validation to current user

* Fix parent field name

* Changes in field label

* Null check for editing fields

* Behat test update

* Reorder new site specific field

* lints

---------

Co-authored-by: Sahil Sharma <[email protected]>
Co-authored-by: Md Nadim Hossain <[email protected]>
Co-authored-by: Yeni Atencio <[email protected]>
Co-authored-by: Sahil Sharma <[email protected]>
Co-authored-by: Vincent Gao <[email protected]>
  • Loading branch information
6 people authored Nov 26, 2024
1 parent da58426 commit b4f3247
Show file tree
Hide file tree
Showing 11 changed files with 162 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ dependencies:
- field.field.taxonomy_term.sites.field_bottom_corner_graphic
- field.field.taxonomy_term.sites.field_print_friendly_logo
- field.field.taxonomy_term.sites.field_prominence_ack_to_country
- field.field.taxonomy_term.sites.field_show_exit_site_specific
- field.field.taxonomy_term.sites.field_show_table_of_contents
- field.field.taxonomy_term.sites.field_site_domains
- field.field.taxonomy_term.sites.field_site_favicon
Expand Down Expand Up @@ -47,7 +48,7 @@ third_party_settings:
label: 'Table of contents'
region: content
parent_name: ''
weight: 18
weight: 19
format_type: details
format_settings:
classes: ''
Expand All @@ -62,7 +63,7 @@ third_party_settings:
label: 'Site theme values'
region: content
parent_name: ''
weight: 19
weight: 20
format_type: details
format_settings:
classes: ''
Expand All @@ -77,7 +78,7 @@ third_party_settings:
label: 'Site feature flag values'
region: content
parent_name: ''
weight: 20
weight: 21
format_type: details
format_settings:
classes: ''
Expand All @@ -92,7 +93,7 @@ third_party_settings:
label: 'Site favicon value'
region: content
parent_name: ''
weight: 21
weight: 22
format_type: details
format_settings:
classes: ''
Expand All @@ -108,7 +109,7 @@ third_party_settings:
label: 'Site header corner graphics'
region: content
parent_name: ''
weight: 22
weight: 23
format_type: details
format_settings:
classes: ''
Expand All @@ -124,7 +125,7 @@ mode: default
content:
field_acknowledgement_to_country:
type: string_textarea
weight: 12
weight: 13
region: content
settings:
rows: 5
Expand Down Expand Up @@ -155,12 +156,18 @@ content:
third_party_settings: { }
field_prominence_ack_to_country:
type: string_textarea
weight: 13
weight: 14
region: content
settings:
rows: 5
placeholder: ''
third_party_settings: { }
field_show_exit_site_specific:
type: options_select
weight: 12
region: content
settings: { }
third_party_settings: { }
field_show_table_of_contents:
type: boolean_checkbox
weight: 17
Expand Down Expand Up @@ -266,7 +273,7 @@ content:
third_party_settings: { }
field_site_og_image:
type: entity_browser_entity_reference
weight: 14
weight: 15
region: content
settings:
entity_browser: tide_image_browser
Expand Down Expand Up @@ -296,7 +303,7 @@ content:
third_party_settings: { }
field_site_social_links:
type: link_default
weight: 16
weight: 17
region: content
settings:
placeholder_url: 'https://example.com/Social'
Expand All @@ -323,7 +330,7 @@ content:
third_party_settings: { }
field_site_twitter_image:
type: entity_browser_entity_reference
weight: 15
weight: 16
region: content
settings:
entity_browser: tide_image_browser
Expand Down Expand Up @@ -362,7 +369,7 @@ content:
third_party_settings: { }
status:
type: boolean_checkbox
weight: 17
weight: 18
region: content
settings:
display_label: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ dependencies:
- field.field.taxonomy_term.sites.field_additional_comment
- field.field.taxonomy_term.sites.field_print_friendly_logo
- field.field.taxonomy_term.sites.field_prominence_ack_to_country
- field.field.taxonomy_term.sites.field_show_exit_site_specific
- field.field.taxonomy_term.sites.field_show_table_of_contents
- field.field.taxonomy_term.sites.field_site_domains
- field.field.taxonomy_term.sites.field_site_footer_logos
Expand Down Expand Up @@ -53,6 +54,13 @@ content:
third_party_settings: { }
weight: 12
region: content
field_show_exit_site_specific:
type: list_default
label: above
settings: { }
third_party_settings: { }
weight: 11
region: content
field_show_table_of_contents:
type: boolean
label: above
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
langcode: en
status: true
dependencies:
config:
- field.storage.taxonomy_term.field_show_exit_site_specific
- taxonomy.vocabulary.sites
module:
- options
id: taxonomy_term.sites.field_show_exit_site_specific
field_name: field_show_exit_site_specific
entity_type: taxonomy_term
bundle: sites
label: 'Show Quick exit button on pages in this site section?'
description: 'You can turn the Quick exit button on or off for a site section only, separate from the setting for the whole site.'
required: false
translatable: false
default_value: { }
default_value_callback: ''
settings: { }
field_type: list_string
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ dependencies:
config:
- field.storage.taxonomy_term.field_site_show_exit_site
- taxonomy.vocabulary.sites
_core:
default_config_hash: H4XsO_lcSpmN8fpKEaZh7KoUvvK8Ajfg5hOdosU4VKs
id: taxonomy_term.sites.field_site_show_exit_site
field_name: field_site_show_exit_site
entity_type: taxonomy_term
bundle: sites
label: 'Show Exit Site?'
label: 'Show Quick exit button sitewide?'
description: ''
required: false
translatable: false
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
langcode: en
status: true
dependencies:
module:
- options
- taxonomy
id: taxonomy_term.field_show_exit_site_specific
field_name: field_show_exit_site_specific
entity_type: taxonomy_term
type: list_string
settings:
allowed_values:
-
value: 'yes'
label: 'Yes'
-
value: 'no'
label: 'No'
allowed_values_function: ''
module: options
locked: false
cardinality: 1
translatable: true
indexes: { }
persist_with_no_fields: false
custom_storage: false
31 changes: 31 additions & 0 deletions modules/tide_site/js/quick_exit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
(function ($, Drupal) {

'use strict';

Drupal.behaviors.siteQuickExitFields = {
attach: function (context, settings) {
var parentField = ($('.taxonomy-term-sites-form #edit-parent'));
var parentVal = parentField.val();
if (parentVal == 0) {
$('.field--name-field-show-exit-site-specific').hide();
}
else {
$('.field--name-field-site-show-exit-site').hide();
}
$(parent).change(function() {
var selectedValue = $(this).val();
if (selectedValue == 0) {
$('#edit-field-show-exit-site-specific option:selected').prop('selected', false);
$('#edit-field-show-exit-site-specific').val('_none');
$('.field--name-field-show-exit-site-specific').hide();
$('.field--name-field-site-show-exit-site').show();
}
else {
$('#edit-field-site-show-exit-site-value').prop('checked', false);
$('.field--name-field-site-show-exit-site').hide();
$('.field--name-field-show-exit-site-specific').show();
}
});
}
};
})(jQuery, Drupal);
11 changes: 10 additions & 1 deletion modules/tide_site/tests/behat/features/sites.feature
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,16 @@ Feature: Sites taxonomy vocabulary
And I should see text matching "Footer logos"
And I should see text matching "No Paragraph added yet.."

And I see field "Show Exit Site?"
And I see field "Show Quick exit button sitewide?"
And I should see an "input#edit-field-site-show-exit-site-value" element
And I should not see an "input#edit-field-site-show-exit-site-value.required" element
And I should not see field "Show Quick exit button on pages in this site section?"
And I should not see an "input#edit-field-show-exit-site-specific" element

And I see field "Show Quick exit button on pages in this site section?"
And I should see an "input#edit-field-show-exit-site-specific" element
And I should not see an "input#edit-field-show-exit-site-specific.required" element
And I should not see field "Show Quick exit button sitewide?"
And I should not see an "input#edit-field-site-show-exit-site-value" element


28 changes: 28 additions & 0 deletions modules/tide_site/tide_site.install
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,31 @@ function tide_site_update_10001() {
$display_config_entity->save();
}
}

/**
* New field site specific quick exit button.
*/
function tide_site_update_10002() {
$update_service = \Drupal::service('tide_core.entity_update_helper');
// Import extra fields.
$field_configs = [
'taxonomy_term.field_show_exit_site_specific' => 'field_storage_config',
'taxonomy_term.sites.field_show_exit_site_specific' => 'field_config',
];
/** @var \Drupal\config_update\ConfigReverter $config_update */
foreach ($field_configs as $name => $type) {
$update_service->import($type, $name);
}
$taxonomy_configs = [
'entity_form_display' => 'taxonomy_term.sites.default',
'entity_view_display' => 'taxonomy_term.sites.default',
'field_config' => 'taxonomy_term.sites.field_site_show_exit_site',
];
foreach ($taxonomy_configs as $configs_name => $types) {
// Check default configuration.
$config = \Drupal::configFactory()->getEditable($configs_name);
if ($config) {
$update_service->revert($configs_name, $types);
}
}
}
5 changes: 5 additions & 0 deletions modules/tide_site/tide_site.libraries.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,8 @@ tide_site_layout:
css:
theme:
css/tide_site_layout.css: {}
tide_quick_exit:
js:
js/quick_exit.js: {}
dependencies:
- core/jquery
7 changes: 7 additions & 0 deletions modules/tide_site/tide_site.module
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,13 @@ function tide_site_entity_presave(EntityInterface $entity) {
*/
function tide_site_field_widget_single_element_form_alter(&$element, FormStateInterface $form_state, $context) {
$field_definition = $context['items']->getFieldDefinition();
// Site specific exit button state change.
$vocabulary = $form_state->get(['taxonomy', 'vocabulary']);
if (!empty($vocabulary)) {
if ($vocabulary->id() === 'sites') {
$element['#attached']['library'][] = 'tide_site/tide_quick_exit';
}
}

// Restrict options to 2 levels of depth for Site field.
if (TideSiteFields::isSiteField($field_definition->getName(), TideSiteFields::FIELD_SITE)) {
Expand Down
7 changes: 6 additions & 1 deletion src/TideEntityUpdateHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,12 @@ public function updateFieldTable(string $entity_type_id, string $field_name) {
}

/**
* {@inheritdoc}
* Perform config import from optional folder.
*
* @param string $type
* The type of config to import.
* @param string $name
* The name of config to import.
*/
public function updateFromOptional($type, $name) {
// Read the config from the file. Note: Do not call getFromExtension() here
Expand Down

0 comments on commit b4f3247

Please sign in to comment.