.../Plugin/DisplayVariant/SimplePageVariant.php | 3 +++ .../src/Plugin/DisplayVariant/BlockPageVariant.php | 3 +++ .../src/Tests/ContextualDynamicContextTest.php | 6 ++---- core/modules/system/system.module | 3 +++ .../templates/container--main-content.html.twig | 12 ++++++++++++ core/modules/views_ui/src/Tests/DisplayTest.php | 21 +++++++++++---------- 6 files changed, 34 insertions(+), 14 deletions(-) diff --git a/core/lib/Drupal/Core/Render/Plugin/DisplayVariant/SimplePageVariant.php b/core/lib/Drupal/Core/Render/Plugin/DisplayVariant/SimplePageVariant.php index a82acbb..987cfaa 100644 --- a/core/lib/Drupal/Core/Render/Plugin/DisplayVariant/SimplePageVariant.php +++ b/core/lib/Drupal/Core/Render/Plugin/DisplayVariant/SimplePageVariant.php @@ -68,6 +68,9 @@ 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 7d913a7..d3f73f6 100644 --- a/core/modules/block/src/Plugin/DisplayVariant/BlockPageVariant.php +++ b/core/modules/block/src/Plugin/DisplayVariant/BlockPageVariant.php @@ -178,6 +178,9 @@ 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/contextual/src/Tests/ContextualDynamicContextTest.php b/core/modules/contextual/src/Tests/ContextualDynamicContextTest.php index 65ecc42..38955ab 100644 --- a/core/modules/contextual/src/Tests/ContextualDynamicContextTest.php +++ b/core/modules/contextual/src/Tests/ContextualDynamicContextTest.php @@ -47,7 +47,7 @@ class ContextualDynamicContextTest extends WebTestBase { * * @var array */ - public static $modules = array('block', 'contextual', 'node', 'views', 'views_ui', 'language', 'menu_test'); + public static $modules = array('contextual', 'node', 'views', 'views_ui', 'language', 'menu_test'); protected function setUp() { parent::setUp(); @@ -55,8 +55,6 @@ protected function setUp() { $this->drupalCreateContentType(array('type' => 'page', 'name' => 'Basic page')); $this->drupalCreateContentType(array('type' => 'article', 'name' => 'Article')); - $this->drupalPlaceBlock('system_main_block', ['id' => 'main_content']); - ConfigurableLanguage::createFromLangcode('it')->save(); $this->rebuildContainer(); @@ -88,7 +86,7 @@ function testDifferentPermissions() { 'node:node=' . $node1->id() . ':changed=' . $node1->getChangedTime() . '&langcode=en', 'node:node=' . $node2->id() . ':changed=' . $node2->getChangedTime() . '&langcode=en', 'node:node=' . $node3->id() . ':changed=' . $node3->getChangedTime() . '&langcode=en', - 'block:block=main_content:langcode=en|entity.view.edit_form:view=frontpage:location=page&name=frontpage&display_id=page_1&langcode=en', + 'entity.view.edit_form:view=frontpage:location=page&name=frontpage&display_id=page_1&langcode=en', ]; // Editor user: can access contextual links and can edit articles. diff --git a/core/modules/system/system.module b/core/modules/system/system.module index 561504c..145ffef 100644 --- a/core/modules/system/system.module +++ b/core/modules/system/system.module @@ -213,6 +213,9 @@ function system_theme() { 'variables' => array('menu_items' => NULL), 'file' => 'system.admin.inc', ), + 'container__main_content' => array( + 'base hook' => 'container', + ), )); } diff --git a/core/modules/system/templates/container--main-content.html.twig b/core/modules/system/templates/container--main-content.html.twig new file mode 100644 index 0000000..9db3e4f --- /dev/null +++ b/core/modules/system/templates/container--main-content.html.twig @@ -0,0 +1,12 @@ +{# +/** + * @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_ui/src/Tests/DisplayTest.php b/core/modules/views_ui/src/Tests/DisplayTest.php index c799ff3..1f13508 100644 --- a/core/modules/views_ui/src/Tests/DisplayTest.php +++ b/core/modules/views_ui/src/Tests/DisplayTest.php @@ -35,15 +35,6 @@ class DisplayTest extends UITestBase { public static $modules = array('contextual'); /** - * {@inheritdoc} - */ - protected function setUp() { - parent::setUp(); - - $this->drupalPlaceBlock('system_main_block', ['id' => 'main_content']); - } - - /** * Tests reordering of displays. */ public function testReorderDisplay() { @@ -189,8 +180,10 @@ public function testPageContextualLinks() { $view->enable()->save(); $this->container->get('router.builder')->rebuildIfNeeded(); + // When no "main content" block is placed, we find a contextual link + // placeholder for editing just the view. $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))); @@ -201,6 +194,14 @@ public function testPageContextualLinks() { $this->assertResponse(200); $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. + $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'; + // @see \Drupal\contextual\Tests\ContextualDynamicContextTest:assertContextualLinkPlaceHolder() + $this->assertRaw(' $id)) . '>', format_string('Contextual link placeholder with id @id exists.', array('@id' => $id))); } /**