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-345] Implement Ability to Remove Quick Exit from Specific Site Sections #524

Open
wants to merge 10 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 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 @@ -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 @@ -161,6 +162,12 @@ content:
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
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 Exit Site Specific?'
description: ''
required: false
translatable: false
default_value: { }
default_value_callback: ''
settings: { }
field_type: list_string
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 parent = ($('.taxonomy-term-sites-form #edit-parent'));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of using parent, which is a common jQuery method, use a more descriptive variable name like parentField to avoid confusion.

var parentVal = parent.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);
9 changes: 9 additions & 0 deletions modules/tide_site/tests/behat/features/sites.feature
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,13 @@ Feature: Sites taxonomy vocabulary
And I see field "Show Exit Site?"
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 Exit Site Specific?"
And I should not see an "input#edit-field-show-exit-site-specific" element

And I see field "Show Exit Site Specific?"
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 Exit Site?"
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',
];
//$update_service->configMergeDeep('tide_site', TideEntityUpdateHelper::INSTALL_DIR, $taxonomy_configs);
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
5 changes: 5 additions & 0 deletions modules/tide_site/tide_site.module
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,11 @@ 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 ($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
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,17 @@ public function viewsForm(&$form, FormStateInterface $form_state) {
'#empty_option' => $this->t('- Select -'),
];
$current_user = \Drupal::currentUser();

// Removed delete option for approver role.
if ($current_user) {
$roles = $current_user->getRoles();
if (
in_array('approver', $roles) &&
isset($form['header']['node_bulk_form']['action']['#options']['node_delete_action'])
) {
unset($form['header']['node_bulk_form']['action']['#options']['node_delete_action']);
}
}
if (!$current_user->hasPermission('tide node bulk update') &&
!\Drupal::service('tide_site_restriction.helper')->canBypassRestriction($current_user)) {
$form['actions']['submit']['#disabled'] = TRUE;
Expand All @@ -86,15 +97,6 @@ public function viewsForm(&$form, FormStateInterface $form_state) {
// Remove the default actions build array.
unset($form['actions']);
}

// Removed delete option for approver role.
$roles = $current_user->getRoles();
if (
in_array('approver', $roles) &&
isset($form['header']['node_bulk_form']['action']['#options']['node_delete_action'])
) {
unset($form['header']['node_bulk_form']['action']['#options']['node_delete_action']);
}
}

}
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}
* @param string $type
* The type of config to import
* @param string $name
* The name of config to import
*
* Perform config import from optional folder
*/
public function updateFromOptional($type, $name) {
// Read the config from the file. Note: Do not call getFromExtension() here
Expand Down
2 changes: 1 addition & 1 deletion tide_core.module
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ function tide_core_form_alter(&$form, FormStateInterface $form_state, $form_id)
&& isset($form['field_metatags']['widget'][0]['open_graph'])
&& isset($form['field_metatags']['widget'][0]['open_graph']['og_locale'])
) {
$url = Url::fromUri('https://digital-vic.atlassian.net/servicedesk/customer/portal/14/article/2272657746', [
$url = Url::fromUri('https://digital-vic.atlassian.net/servicedesk/customer/portal/27/article/2272657746', [
'attributes' => [
'target' => '_blank',
],
Expand Down
Loading