summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLee Rowlands2018-02-01 23:07:12 (GMT)
committerLee Rowlands2018-02-01 23:07:12 (GMT)
commit41baf345af64894b58808ed662a517a560a799b8 (patch)
tree585fdceb0f1cb065fc955ecf048a1bcac494610b
parentb1e477ec25c951337f3160528225a1170faf6092 (diff)
Issue #2938186 by navneet0693, John Cook, Eli-T, markconroy, smaz, ckrina, andrewmacpherson, larowlan: Set toolbar warning message to only appear on admin/edit pages
-rw-r--r--core/profiles/demo_umami/demo_umami.profile18
-rw-r--r--core/profiles/demo_umami/tests/src/Functional/DemoUmamiProfileTest.php47
2 files changed, 60 insertions, 5 deletions
diff --git a/core/profiles/demo_umami/demo_umami.profile b/core/profiles/demo_umami/demo_umami.profile
index 02a5853..dc8384f 100644
--- a/core/profiles/demo_umami/demo_umami.profile
+++ b/core/profiles/demo_umami/demo_umami.profile
@@ -34,8 +34,17 @@ function demo_umami_toolbar() {
// @todo: This can be removed once a generic warning for experimental profiles has been introduced.
// @see https://www.drupal.org/project/drupal/issues/2934374
$items['experimental-profile-warning'] = [
- '#type' => 'toolbar_item',
- 'tab' => [
+ '#weight' => 999,
+ '#cache' => [
+ 'contexts' => ['route'],
+ ],
+ ];
+
+ // Show warning only on administration pages.
+ $admin_context = \Drupal::service('router.admin_context');
+ if ($admin_context->isAdminRoute()) {
+ $items['experimental-profile-warning']['#type'] = 'toolbar_item';
+ $items['experimental-profile-warning']['tab'] = [
'#type' => 'inline_template',
'#template' => '<a class="toolbar-warning" href="{{ more_info_link }}">This installation is for demonstration purposes only.</a>',
'#context' => [
@@ -44,8 +53,7 @@ function demo_umami_toolbar() {
'#attached' => [
'library' => ['demo_umami/toolbar-warning'],
],
- ],
- '#weight' => 999,
- ];
+ ];
+ }
return $items;
}
diff --git a/core/profiles/demo_umami/tests/src/Functional/DemoUmamiProfileTest.php b/core/profiles/demo_umami/tests/src/Functional/DemoUmamiProfileTest.php
index 3e8d697..f4bd76a 100644
--- a/core/profiles/demo_umami/tests/src/Functional/DemoUmamiProfileTest.php
+++ b/core/profiles/demo_umami/tests/src/Functional/DemoUmamiProfileTest.php
@@ -122,4 +122,51 @@ class DemoUmamiProfileTest extends BrowserTestBase {
$webassert->pageTextContains('Umami');
}
+ /**
+ * Tests that the toolbar warning only appears on the admin pages.
+ */
+ public function testDemonstrationWarningMessage() {
+ $permissions = [
+ 'access content overview',
+ 'administer nodes',
+ 'create recipe content',
+ 'edit any recipe content',
+ 'access toolbar',
+ ];
+ $account = $this->drupalCreateUser($permissions);
+ $this->drupalLogin($account);
+ $web_assert = $this->assertSession();
+
+ $nodes = $this->container->get('entity_type.manager')
+ ->getStorage('node')
+ ->loadByProperties(['title' => 'Deep mediterranean quiche']);
+ /* @var \Drupal\node\Entity\Node $recipe_node */
+ $recipe_node = reset($nodes);
+
+ // Check when editing a node, the warning is visible.
+ $this->drupalGet($recipe_node->toUrl('edit-form'));
+ $web_assert->statusCodeEquals('200');
+ $web_assert->pageTextContains('This installation is for demonstration purposes only.');
+
+ // Check when adding a node, the warning is visible.
+ $this->drupalGet('node/add/recipe');
+ $web_assert->statusCodeEquals('200');
+ $web_assert->pageTextContains('This installation is for demonstration purposes only.');
+
+ // Check when looking at admin/content, the warning is visible.
+ $this->drupalGet('admin/content');
+ $web_assert->statusCodeEquals('200');
+ $web_assert->pageTextContains('This installation is for demonstration purposes only.');
+
+ // Check when viewing a node, the warning is not visible.
+ $this->drupalGet($recipe_node->toUrl());
+ $web_assert->statusCodeEquals('200');
+ $web_assert->pageTextNotContains('This installation is for demonstration purposes only.');
+
+ // Check when viewing the homepage, the warning is not visible.
+ $this->drupalGet('<front>');
+ $web_assert->statusCodeEquals('200');
+ $web_assert->pageTextNotContains('This installation is for demonstration purposes only.');
+ }
+
}