core/modules/settings_tray/js/settings_tray.es6.js | 14 ---------- core/modules/settings_tray/js/settings_tray.js | 8 ------ core/modules/settings_tray/settings_tray.module | 32 ++++++---------------- .../settings_tray/settings_tray.routing.yml | 1 + .../settings_tray/settings_tray.services.yml | 4 +++ .../src/Access/BlockHasOverridesAccessCheck.php | 29 ++++++++++++++++++++ 6 files changed, 42 insertions(+), 46 deletions(-) diff --git a/core/modules/settings_tray/js/settings_tray.es6.js b/core/modules/settings_tray/js/settings_tray.es6.js index 989fdde..6487690 100644 --- a/core/modules/settings_tray/js/settings_tray.es6.js +++ b/core/modules/settings_tray/js/settings_tray.es6.js @@ -171,20 +171,6 @@ } instance.options.data.dialogOptions.settingsTrayActiveEditableId = $(instance.element).parents('.settings-tray-editable').attr('id'); instance.progress = { type: 'fullscreen' }; - - /** - * This is work around because it is not possible to remove the link - * the server-side. - * @see settings_tray_preprocess_block(). - * @todo Remove this workaround in https://www.drupal.org/node/2937467. - */ - if (instance.hasOwnProperty('element')) { - const element = $(instance.element); - // If the ajax element is within a overridden block remove the link. - if (element.closest('[data-settings-tray-overridden]').length === 1) { - element.remove(); - } - } }); } diff --git a/core/modules/settings_tray/js/settings_tray.js b/core/modules/settings_tray/js/settings_tray.js index d4649d7..7a83e15 100644 --- a/core/modules/settings_tray/js/settings_tray.js +++ b/core/modules/settings_tray/js/settings_tray.js @@ -102,14 +102,6 @@ } instance.options.data.dialogOptions.settingsTrayActiveEditableId = $(instance.element).parents('.settings-tray-editable').attr('id'); instance.progress = { type: 'fullscreen' }; - - if (instance.hasOwnProperty('element')) { - var element = $(instance.element); - - if (element.closest('[data-settings-tray-overridden]').length === 1) { - element.remove(); - } - } }); } diff --git a/core/modules/settings_tray/settings_tray.module b/core/modules/settings_tray/settings_tray.module index f5e60ab..eb19144 100644 --- a/core/modules/settings_tray/settings_tray.module +++ b/core/modules/settings_tray/settings_tray.module @@ -12,7 +12,6 @@ use Drupal\settings_tray\Form\SystemBrandingOffCanvasForm; use Drupal\settings_tray\Form\SystemMenuOffCanvasForm; use Drupal\block\BlockInterface; -use Drupal\block\Entity\Block; /** * Implements hook_help(). @@ -77,6 +76,10 @@ function _settings_tray_has_block_overrides(BlockInterface $block) { * Implements hook_block_view_alter(). */ function settings_tray_block_view_alter(array &$build) { + // Ensure that contextual links vary by whether the block has config overrides + // or not. + // @see _contextual_links_to_id() + $build['#contextual_links']['block']['metadata']['has_overrides'] = _settings_tray_has_block_overrides($build['#block']) ? 1 : 0; // Force a new 'data-contextual-id' attribute on blocks when this module is // enabled so as not to reuse stale data cached client-side. // @todo Remove when https://www.drupal.org/node/2773591 is fixed. @@ -112,29 +115,10 @@ function settings_tray_preprocess_block(&$variables) { $block_plugin_manager = \Drupal::service('plugin.manager.block'); /** @var \Drupal\Core\Block\BlockPluginInterface $block_plugin */ $block_plugin = $block_plugin_manager->createInstance($variables['plugin_id']); - if (isset($variables['elements']['#contextual_links']['block']['route_parameters']['block'])) { - $block_id = $variables['elements']['#contextual_links']['block']['route_parameters']['block']; - $block = Block::load($block_id); - if ($access_checker->accessBlockPlugin($block_plugin)->isAllowed()) { - if (!_settings_tray_has_block_overrides($block)) { - // Add class and attributes to all blocks to allow JavaScript to target. - $variables['attributes']['class'][] = 'settings-tray-editable'; - $variables['attributes']['data-drupal-settingstray'] = 'editable'; - } - else { - // If the block is overridden then set an attribute which will be used - // in settings_tray.es6.js to remove the "Quick edit" link. - // It is not possible to remove the contextual link with - // hook_contextual_links_alter or hook_contextual_links_view_alter - // because they are only called when the client-side cache of contextual - // links is empty, invalidated, or a new variation is detected, and it - // currently is not possible to reliably detect configuration override - // changes, and therefore it is not possible to invalidate the - // client-side cache of contextual links when needed. - // @todo Remove this workaround in https://www.drupal.org/node/2937467. - $variables['attributes']['data-settings-tray-overridden'] = TRUE; - } - } + if ($access_checker->accessBlockPlugin($block_plugin)->isAllowed()) { + // Add class and attributes to all blocks to allow Javascript to target. + $variables['attributes']['class'][] = 'settings-tray-editable'; + $variables['attributes']['data-drupal-settingstray'] = 'editable'; } } diff --git a/core/modules/settings_tray/settings_tray.routing.yml b/core/modules/settings_tray/settings_tray.routing.yml index 01109e4..f8e2bfe 100644 --- a/core/modules/settings_tray/settings_tray.routing.yml +++ b/core/modules/settings_tray/settings_tray.routing.yml @@ -6,3 +6,4 @@ entity.block.off_canvas_form: requirements: _permission: 'administer blocks' _access_block_plugin_has_settings_tray_form: 'TRUE' + _access_block_has_overrides_settings_tray_form: 'TRUE' diff --git a/core/modules/settings_tray/settings_tray.services.yml b/core/modules/settings_tray/settings_tray.services.yml index a11a1d4..7c57e95 100644 --- a/core/modules/settings_tray/settings_tray.services.yml +++ b/core/modules/settings_tray/settings_tray.services.yml @@ -1,4 +1,8 @@ services: + access_check.settings_tray.block.has_overrides: + class: Drupal\settings_tray\Access\BlockHasOverridesAccessCheck + tags: + - { name: access_check, applies_to: _access_block_has_overrides_settings_tray_form } access_check.settings_tray.block.settings_tray_form: class: Drupal\settings_tray\Access\BlockPluginHasSettingsTrayFormAccessCheck tags: diff --git a/core/modules/settings_tray/src/Access/BlockHasOverridesAccessCheck.php b/core/modules/settings_tray/src/Access/BlockHasOverridesAccessCheck.php new file mode 100644 index 0000000..b21f8f4 --- /dev/null +++ b/core/modules/settings_tray/src/Access/BlockHasOverridesAccessCheck.php @@ -0,0 +1,29 @@ +