diff --git a/core/modules/outside_in/outside_in.module b/core/modules/outside_in/outside_in.module index d944565..86976c7 100644 --- a/core/modules/outside_in/outside_in.module +++ b/core/modules/outside_in/outside_in.module @@ -40,6 +40,18 @@ function outside_in_contextual_links_view_alter(&$element, $items) { } /** + * Implements hook_block_view_alter(). + */ +function outside_in_block_view_alter(array &$build) { + // 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. + $build['#contextual_links']['outside_in'] = [ + 'route_parameters' => [], + ]; +} + +/** * Implements hook_page_top(). */ function outside_in_page_top(array &$page_top) { @@ -77,7 +89,7 @@ function outside_in_entity_type_build(array &$entity_types) { function outside_in_preprocess_block(&$variables) { // The main system block does not contain the block contextual links. $variables['#cache']['contexts'][] = 'outside_in_is_applied'; - if (\Drupal::service('outside_in.info')->isApplied() && $variables['plugin_id'] !== 'system_main_block') { + if (\Drupal::service('outside_in.manager')->isApplicable() && $variables['plugin_id'] !== 'system_main_block') { // Add class to all blocks to allow Javascript to target. $variables['attributes']['class'][] = 'outside-in-editable'; } @@ -90,7 +102,7 @@ function outside_in_preprocess_block(&$variables) { */ function outside_in_toolbar_alter(&$items) { $items['contextual']['#cache']['contexts'][] = 'outside_in_is_applied'; - if (\Drupal::service('outside_in.info')->isApplied() && isset($items['contextual']['tab'])) { + if (\Drupal::service('outside_in.manager')->isApplicable() && isset($items['contextual']['tab'])) { $items['contextual']['#weight'] = -1000; $items['contextual']['#attached']['library'][] = 'outside_in/drupal.outside_in'; diff --git a/core/modules/outside_in/outside_in.services.yml b/core/modules/outside_in/outside_in.services.yml index 47b2585..9ac920a 100644 --- a/core/modules/outside_in/outside_in.services.yml +++ b/core/modules/outside_in/outside_in.services.yml @@ -5,12 +5,12 @@ services: tags: - { name: render.main_content_renderer, format: drupal_offcanvas } - outside_in.info: - class: Drupal\outside_in\OutsideInInfo + outside_in.manager: + class: Drupal\outside_in\OutsideInManager arguments: ['@router.admin_context', '@current_route_match', '@current_user'] cache_context.outside_in_is_applied: class: Drupal\outside_in\Cache\Context\OutsideInCacheContext - arguments: ['@outside_in.info'] + arguments: ['@outside_in.manager'] tags: - { name: cache.context} diff --git a/core/modules/outside_in/src/Cache/Context/OutsideInCacheContext.php b/core/modules/outside_in/src/Cache/Context/OutsideInCacheContext.php index 36b8fe3..193b948 100644 --- a/core/modules/outside_in/src/Cache/Context/OutsideInCacheContext.php +++ b/core/modules/outside_in/src/Cache/Context/OutsideInCacheContext.php @@ -4,7 +4,7 @@ use Drupal\Core\Cache\CacheableMetadata; use Drupal\Core\Cache\Context\CacheContextInterface; -use Drupal\outside_in\OutsideInInfoInterface; +use Drupal\outside_in\OutsideInManagerInterface; /** * Defines the OutsideInCacheContext service, for "Outside-In or not" caching. @@ -14,20 +14,20 @@ class OutsideInCacheContext implements CacheContextInterface { /** - * The Outside-In info. + * The Outside-In manager. * - * @var \Drupal\outside_in\OutsideInInfoInterface + * @var \Drupal\outside_in\OutsideInManagerInterface */ - protected $outsideInInfo; + protected $outsideInManager; /** * OutsideInCacheContext constructor. * - * @param \Drupal\outside_in\OutsideInInfoInterface $outside_in_info - * The Outside-In info. + * @param \Drupal\outside_in\OutsideInManagerInterface $outside_in_manager + * The Outside-In manager. */ - public function __construct(OutsideInInfoInterface $outside_in_info) { - $this->outsideInInfo = $outside_in_info; + public function __construct(OutsideInManagerInterface $outside_in_manager) { + $this->outsideInManager = $outside_in_manager; } /** @@ -41,7 +41,7 @@ public static function getLabel() { * {@inheritdoc} */ public function getContext() { - return $this->outsideInInfo->isApplied() ? '1' : '0'; + return $this->outsideInManager->isApplicable() ? '1' : '0'; } /** diff --git a/core/modules/outside_in/src/OutsideInInfo.php b/core/modules/outside_in/src/OutsideInManager.php similarity index 78% rename from core/modules/outside_in/src/OutsideInInfo.php rename to core/modules/outside_in/src/OutsideInManager.php index 1af0a2a..e0897fd 100644 --- a/core/modules/outside_in/src/OutsideInInfo.php +++ b/core/modules/outside_in/src/OutsideInManager.php @@ -7,9 +7,9 @@ use Drupal\Core\Session\AccountInterface; /** - * Provides information related to Outside-In. + * Manages information related to Outside-In. */ -class OutsideInInfo implements OutsideInInfoInterface { +class OutsideInManager implements OutsideInManagerInterface { /** * The admin context service. @@ -33,7 +33,7 @@ class OutsideInInfo implements OutsideInInfoInterface { protected $account; /** - * OutsideInInfo constructor. + * OutsideInManager constructor. * * @param \Drupal\Core\Routing\AdminContext $admin_context * The admin context service. @@ -51,15 +51,15 @@ public function __construct(AdminContext $admin_context, RouteMatchInterface $ro /** * {@inheritdoc} */ - public function isApplied() { + public function isApplicable() { // Remove on Admin routes. - $admin_route = $this->adminContext->isAdminRoute(); + $is_admin_route = $this->adminContext->isAdminRoute(); // Remove on Block Demo page. - $admin_demo = $this->routeMatch->getRouteName() === 'block.admin_demo'; + $is_admin_demo_route = $this->routeMatch->getRouteName() === 'block.admin_demo'; // @todo Check if there is actually a different admin theme. - return $this->account->hasPermission('administer blocks') && !$admin_route && !$admin_demo; + return $this->account->hasPermission('administer blocks') && !$is_admin_route && !$is_admin_demo_route; } } diff --git a/core/modules/outside_in/src/OutsideInInfoInterface.php b/core/modules/outside_in/src/OutsideInManagerInterface.php similarity index 61% rename from core/modules/outside_in/src/OutsideInInfoInterface.php rename to core/modules/outside_in/src/OutsideInManagerInterface.php index bd18386..bb3dae5 100644 --- a/core/modules/outside_in/src/OutsideInInfoInterface.php +++ b/core/modules/outside_in/src/OutsideInManagerInterface.php @@ -3,9 +3,9 @@ namespace Drupal\outside_in; /** - * Provides an interface for defining information related to Outside-In. + * Provides an interface for managing information related to Outside-In. */ -interface OutsideInInfoInterface { +interface OutsideInManagerInterface { /** * Determines if the Outside-In logic should be run on the current page. @@ -13,6 +13,6 @@ * @return bool * TRUE if the Outside-In logic should be run. */ - public function isApplied(); + public function isApplicable(); } diff --git a/core/modules/outside_in/tests/src/Unit/OutsideInInfoTest.php b/core/modules/outside_in/tests/src/Unit/OutsideInManagerTest.php similarity index 68% rename from core/modules/outside_in/tests/src/Unit/OutsideInInfoTest.php rename to core/modules/outside_in/tests/src/Unit/OutsideInManagerTest.php index adc4298..53b83e7 100644 --- a/core/modules/outside_in/tests/src/Unit/OutsideInInfoTest.php +++ b/core/modules/outside_in/tests/src/Unit/OutsideInManagerTest.php @@ -5,20 +5,20 @@ use Drupal\Core\Routing\AdminContext; use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\Session\AccountInterface; -use Drupal\outside_in\OutsideInInfo; +use Drupal\outside_in\OutsideInManager; use Drupal\Tests\UnitTestCase; /** - * @coversDefaultClass \Drupal\outside_in\OutsideInInfo + * @coversDefaultClass \Drupal\outside_in\OutsideInManager * @group outside_in */ -class OutsideInInfoTest extends UnitTestCase { +class OutsideInManagerTest extends UnitTestCase { /** - * @covers ::isApplied - * @dataProvider providerTestIsApplied + * @covers ::isApplicable + * @dataProvider providerTestIsApplicable */ - public function testIsApplied($is_admin_route, $route_name, $has_permission, $expected) { + public function testIsApplicable($is_admin_route, $route_name, $has_permission, $expected) { $admin_context = $this->prophesize(AdminContext::class); $admin_context->isAdminRoute()->willReturn($is_admin_route); @@ -28,12 +28,12 @@ public function testIsApplied($is_admin_route, $route_name, $has_permission, $ex $account = $this->prophesize(AccountInterface::class); $account->hasPermission('administer blocks')->willReturn($has_permission); - $outside_in_info = new OutsideInInfo($admin_context->reveal(), $route_match->reveal(), $account->reveal()); + $outside_in_manager = new OutsideInManager($admin_context->reveal(), $route_match->reveal(), $account->reveal()); - $this->assertSame($expected, $outside_in_info->isApplied()); + $this->assertSame($expected, $outside_in_manager->isApplicable()); } - public function providerTestIsApplied() { + public function providerTestIsApplicable() { $data = []; // Passing combination.