summaryrefslogtreecommitdiffstats
path: root/core/modules/settings_tray/settings_tray.module
diff options
context:
space:
mode:
Diffstat (limited to 'core/modules/settings_tray/settings_tray.module')
-rw-r--r--core/modules/settings_tray/settings_tray.module49
1 files changed, 39 insertions, 10 deletions
diff --git a/core/modules/settings_tray/settings_tray.module b/core/modules/settings_tray/settings_tray.module
index 48b08ca..208e1ef 100644
--- a/core/modules/settings_tray/settings_tray.module
+++ b/core/modules/settings_tray/settings_tray.module
@@ -11,6 +11,8 @@ use Drupal\Core\Url;
use Drupal\settings_tray\Block\BlockEntityOffCanvasForm;
use Drupal\settings_tray\Form\SystemBrandingOffCanvasForm;
use Drupal\settings_tray\Form\SystemMenuOffCanvasForm;
+use Drupal\block\entity\Block;
+use Drupal\block\BlockInterface;
/**
* Implements hook_help().
@@ -55,9 +57,33 @@ function settings_tray_contextual_links_view_alter(&$element, $items) {
}
/**
+ * Checks if a block has overrides.
+ *
+ * @param \Drupal\block\BlockInterface $block
+ * The block to check for overrides.
+ *
+ * @return bool
+ * TRUE if the block has overrides otherwise FALSE.
+ *
+ * @internal
+ */
+function _settings_tray_has_block_overrides(BlockInterface $block) {
+ // @todo Replace the following with $block->hasOverrides() in https://www.drupal.org/project/drupal/issues/2910353
+ // and remove this function.
+ return \Drupal::config($block->getEntityType()->getConfigPrefix() . '.' . $block->id())->hasOverrides();
+}
+
+/**
* Implements hook_block_view_alter().
*/
function settings_tray_block_view_alter(array &$build) {
+ if (isset($build['#contextual_links']['block'])) {
+ // 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.
@@ -80,12 +106,12 @@ function settings_tray_entity_type_build(array &$entity_types) {
* Implements hook_preprocess_HOOK() for block templates.
*/
function settings_tray_preprocess_block(&$variables) {
- // Only blocks that have an settings_tray form will have a "Quick Edit" link.
- // We could wait for the contextual links to be initialized on the client
- // side, and then add the class and data- attribute below there (via
- // JavaScript). But that would mean that it would be impossible to show
- // Settings Tray's clickable regions immediately when the page loads. When
- // latency is high, this will cause flicker.
+ // Only blocks that have a settings_tray form and have no configuration
+ // overrides will have a "Quick Edit" link. We could wait for the contextual
+ // links to be initialized on the client side, and then add the class and
+ // data- attribute below there (via JavaScript). But that would mean that it
+ // would be impossible to show Settings Tray's clickable regions immediately
+ // when the page loads. When latency is high, this will cause flicker.
// @see \Drupal\settings_tray\Access\BlockPluginHasSettingsTrayFormAccessCheck
/** @var \Drupal\settings_tray\Access\BlockPluginHasSettingsTrayFormAccessCheck $access_checker */
$access_checker = \Drupal::service('access_check.settings_tray.block.settings_tray_form');
@@ -93,10 +119,13 @@ 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 ($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';
+ if (isset($variables['elements']['#contextual_links']['block']['route_parameters']['block'])) {
+ $block = Block::load($variables['elements']['#contextual_links']['block']['route_parameters']['block']);
+ if ($access_checker->accessBlockPlugin($block_plugin)->isAllowed() && !_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';
+ }
}
}