core/lib/Drupal/Core/Render/MainContent/HtmlRenderer.php | 3 --- .../Core/Render/Plugin/DisplayVariant/SimplePageVariant.php | 3 --- .../block/src/Plugin/DisplayVariant/BlockPageVariant.php | 3 --- .../src/Unit/Plugin/DisplayVariant/BlockPageVariantTest.php | 9 ++------- core/modules/system/system.module | 12 +++++++++--- .../system/templates/container--main-content.html.twig | 12 ------------ core/modules/views/views.theme.inc | 12 ++++++++++++ core/modules/views_ui/src/Tests/DisplayTest.php | 7 ++++--- 8 files changed, 27 insertions(+), 34 deletions(-) diff --git a/core/lib/Drupal/Core/Render/MainContent/HtmlRenderer.php b/core/lib/Drupal/Core/Render/MainContent/HtmlRenderer.php index 935c34d..cd0d482 100644 --- a/core/lib/Drupal/Core/Render/MainContent/HtmlRenderer.php +++ b/core/lib/Drupal/Core/Render/MainContent/HtmlRenderer.php @@ -227,9 +227,6 @@ protected function prepare(array $main_content, Request $request, RouteMatchInte // missing for controllers whose entire returned render array is // render cached. $main_content['#cache_properties'][] = '#title'; - // Retain #contextual_links, otherwise main content that has - // associated contextual links would be missing. - $main_content['#cache_properties'][] = '#contextual_links'; } return $this->renderer->render($main_content, FALSE); }); diff --git a/core/lib/Drupal/Core/Render/Plugin/DisplayVariant/SimplePageVariant.php b/core/lib/Drupal/Core/Render/Plugin/DisplayVariant/SimplePageVariant.php index 987cfaa..a82acbb 100644 --- a/core/lib/Drupal/Core/Render/Plugin/DisplayVariant/SimplePageVariant.php +++ b/core/lib/Drupal/Core/Render/Plugin/DisplayVariant/SimplePageVariant.php @@ -68,9 +68,6 @@ public function build() { ], ], ]; - // Assign the main content container theme wrapper to the main content, to - // ensure contextual links on the main content work as expected. - $build['content']['main_content']['#theme_wrappers'][] = 'container__main_content'; return $build; } diff --git a/core/modules/block/src/Plugin/DisplayVariant/BlockPageVariant.php b/core/modules/block/src/Plugin/DisplayVariant/BlockPageVariant.php index d3f73f6..7d913a7 100644 --- a/core/modules/block/src/Plugin/DisplayVariant/BlockPageVariant.php +++ b/core/modules/block/src/Plugin/DisplayVariant/BlockPageVariant.php @@ -178,9 +178,6 @@ public function build() { // the main content they came for. if (!$main_content_block_displayed) { $build['content']['system_main'] = $this->mainContent; - // Assign the main content container theme wrapper to the main content, to - // ensure contextual links on the main content work as expected. - $build['content']['system_main']['#theme_wrappers'][] = 'container__main_content'; } // If no block displays status messages, still render them. diff --git a/core/modules/block/tests/src/Unit/Plugin/DisplayVariant/BlockPageVariantTest.php b/core/modules/block/tests/src/Unit/Plugin/DisplayVariant/BlockPageVariantTest.php index e54f9c1..4636250 100644 --- a/core/modules/block/tests/src/Unit/Plugin/DisplayVariant/BlockPageVariantTest.php +++ b/core/modules/block/tests/src/Unit/Plugin/DisplayVariant/BlockPageVariantTest.php @@ -186,10 +186,7 @@ public function providerBuild() { // The main content, messages and title are rendered via the fallback in // case there are no blocks rendering them. 'content' => [ - 'system_main' => [ - '#markup' => 'Hello kittens!', - '#theme_wrappers' => ['container__main_content'], - ], + 'system_main' => ['#markup' => 'Hello kittens!'], 'messages' => [ '#weight' => -1000, '#type' => 'status_messages', @@ -267,9 +264,7 @@ public function testBuildWithoutMainContent() { 'max-age' => -1, ], 'content' => [ - 'system_main' => [ - '#theme_wrappers' => ['container__main_content'], - ], + 'system_main' => [], 'messages' => [ '#weight' => -1000, '#type' => 'status_messages', diff --git a/core/modules/system/system.module b/core/modules/system/system.module index 145ffef..a8cc12d 100644 --- a/core/modules/system/system.module +++ b/core/modules/system/system.module @@ -213,9 +213,6 @@ function system_theme() { 'variables' => array('menu_items' => NULL), 'file' => 'system.admin.inc', ), - 'container__main_content' => array( - 'base hook' => 'container', - ), )); } @@ -1399,6 +1396,15 @@ function system_entity_type_build(array &$entity_types) { } /** + * Implements hook_block_view_BASE_BLOCK_ID_alter(). + */ +function system_block_view_system_main_block_alter(array &$build, BlockPluginInterface $block) { + // Contextual links on the system_main block would basically duplicate the + // tabs/local tasks, so reduce the clutter. + unset($build['#contextual_links']); +} + +/** * Implements hook_path_update(). */ function system_path_update() { diff --git a/core/modules/system/templates/container--main-content.html.twig b/core/modules/system/templates/container--main-content.html.twig deleted file mode 100644 index ad841a9..0000000 --- a/core/modules/system/templates/container--main-content.html.twig +++ /dev/null @@ -1,12 +0,0 @@ -{# -/** - * @file - * Main content container. - * - * Unlike container.html.twig, this also prints title_suffix, to allow the main - * content to show a contextual link. - * - * @ingroup themeable - */ -#} -{{ title_suffix }}{{ children }} diff --git a/core/modules/views/views.theme.inc b/core/modules/views/views.theme.inc index f34d076..0ad38b0 100644 --- a/core/modules/views/views.theme.inc +++ b/core/modules/views/views.theme.inc @@ -38,6 +38,18 @@ function template_preprocess_views_view(&$variables) { $variables['attributes']['class'][] = $variables['css_class']; } + // contextual_preproces() only works on render elements, and since this theme + // hook is not for a render element, contextual_preprocess() falls back to the + // first argument and checks if that is a render element. The first element is + // view_array. However, view_array does not get set anywhere, but since we do + // have access to the View object, we can also access the View object's + // element, which is a render element that does have #contextual_links set if + // the display supports it. Doing this allows contextual_preprocess() to + // access this theme hook's render element, and therefore allows this template + // to have contextual links. + // @see views_theme() + $variables['view_array'] = $variables['view']->element; + // Attachments are always updated with the outer view, never by themselves, // so they do not have dom ids. if (empty($view->is_attachment)) { diff --git a/core/modules/views_ui/src/Tests/DisplayTest.php b/core/modules/views_ui/src/Tests/DisplayTest.php index 0672616..c6dd7c0 100644 --- a/core/modules/views_ui/src/Tests/DisplayTest.php +++ b/core/modules/views_ui/src/Tests/DisplayTest.php @@ -195,11 +195,12 @@ public function testPageContextualLinks() { $json = Json::decode($response); $this->assertIdentical($json[$id], ''); - // When a "main content" is placed, we find a contexutal link placeholder - // for both configuring the block and editing the view. + // When a "main content" is placed, we still find a contextual link + // placeholder for editing just the view (not the main content block). + // @see system_block_view_system_main_block_alter() $this->drupalPlaceBlock('system_main_block', ['id' => 'main_content']); $this->drupalGet('test-display'); - $id = 'block:block=main_content:langcode=en|entity.view.edit_form:view=test_display:location=page&name=test_display&display_id=page_1&langcode=en'; + $id = 'entity.view.edit_form:view=test_display:location=page&name=test_display&display_id=page_1&langcode=en'; // @see \Drupal\contextual\Tests\ContextualDynamicContextTest:assertContextualLinkPlaceHolder() $this->assertRaw(' $id)) . '>', format_string('Contextual link placeholder with id @id exists.', array('@id' => $id))); }