diff --git a/src/Form/HelpLockForm.php b/src/Form/HelpLockForm.php index efa0094..c50273d 100644 --- a/src/Form/HelpLockForm.php +++ b/src/Form/HelpLockForm.php @@ -38,7 +38,15 @@ class HelpLockForm extends EntityConfirmFormBase { public function submitForm(array &$form, FormStateInterface $form_state) { $this->entity->setLocked(); $this->entity->save(); - drupal_set_message(t('Locked help topic %name.', ['%name' => $this->entity->label()])); + + $link = $this->entity->toLink(NULL, 'canonical')->toString(); + $ops_link = $this->entity->toLink($this->t('View'), 'canonical')->toString(); + $args = ['@link' => $link]; + $message = $this->t('The help topic @link has been locked.', $args); + drupal_set_message($message); + $this->getLogger('config_help')->notice($message, $args + [ + 'link' => $ops_link, + ]); $form_state->setRedirectUrl($this->getCancelUrl()); } diff --git a/src/Form/HelpTopicForm.php b/src/Form/HelpTopicForm.php index 7c72e38..c62d3e3 100644 --- a/src/Form/HelpTopicForm.php +++ b/src/Form/HelpTopicForm.php @@ -268,12 +268,21 @@ class HelpTopicForm extends EntityForm { $form_state->setRedirect('entity.help_topic.collection'); $status = $this->entity->save(); + + $link = $this->entity->toLink(NULL, 'canonical')->toString(); + $ops_link = $this->entity->toLink($this->t('View'), 'canonical')->toString(); + $args = ['@link' => $link]; if ($status == SAVED_UPDATED) { - drupal_set_message($this->t('Help topic updated.')); + $message = $this->t('The help topic @link has been updated.', $args); } else { - drupal_set_message($this->t('Help topic added.')); + $message = $this->t('The help topic @link has been added.', $args); } + + drupal_set_message($message); + $this->getLogger('config_help')->notice($message, $args + [ + 'link' => $ops_link, + ]); } } diff --git a/src/Form/HelpUnlockForm.php b/src/Form/HelpUnlockForm.php index c12e793..0c6fb3a 100644 --- a/src/Form/HelpUnlockForm.php +++ b/src/Form/HelpUnlockForm.php @@ -38,7 +38,15 @@ class HelpUnlockForm extends EntityConfirmFormBase { public function submitForm(array &$form, FormStateInterface $form_state) { $this->entity->setLocked(FALSE); $this->entity->save(); - drupal_set_message(t('Unlocked help topic %name.', ['%name' => $this->entity->label()])); + + $link = $this->entity->toLink(NULL, 'canonical')->toString(); + $ops_link = $this->entity->toLink($this->t('View'), 'canonical')->toString(); + $args = ['@link' => $link]; + $message = $this->t('The help topic @link has been unlocked.', $args); + drupal_set_message($message); + $this->getLogger('config_help')->notice($message, $args + [ + 'link' => $ops_link, + ]); $form_state->setRedirectUrl($this->getCancelUrl()); } diff --git a/tests/src/Functional/HelpTopicAdminTest.php b/tests/src/Functional/HelpTopicAdminTest.php index 1f5fa9e..1ec2153 100644 --- a/tests/src/Functional/HelpTopicAdminTest.php +++ b/tests/src/Functional/HelpTopicAdminTest.php @@ -25,6 +25,7 @@ class HelpTopicAdminTest extends BrowserTestBase { 'color', 'block', 'help', + 'dblog', ]; /** @@ -61,6 +62,7 @@ class HelpTopicAdminTest extends BrowserTestBase { 'use text format help', 'view help topics', 'administer help topic locking', + 'access site reports', ]); $this->nonLockingUser = $this->createUser([ 'access administration pages', @@ -129,6 +131,8 @@ class HelpTopicAdminTest extends BrowserTestBase { return; } + $dblogs = []; + // Verify that locked pages cannot be edited or deleted. Editing and // deleting of unlocked pages is tested elsewhere. Note that the URL // for editing has no suffix. @@ -141,13 +145,17 @@ class HelpTopicAdminTest extends BrowserTestBase { // Unlock the page, and verify it can then be edited/deleted, but not // unlocked. $this->drupalGet('admin/config/development/help/manage/help_test_locked/unlock'); + $title = 'Locked topic'; $session = $this->assertSession(); $session->pageTextContains('Locked topics are typically provided by modules'); $session->pageTextContains('Are you sure you want to unlock the topic'); - $session->pageTextContains('Locked topic'); + $session->pageTextContains($title); $this->drupalPostForm(NULL, [], 'Unlock'); $session = $this->assertSession(); - $session->pageTextContains('Unlocked help topic'); + $session->pageTextContains("The help topic $title has been unlocked."); + $dblogs[] = "The help topic $title has been unlocked."; + $dblogs[] = 'View'; + // The '' action is actually edit. foreach (['', '/delete', '/lock'] as $action) { $this->drupalGet('admin/config/development/help/manage/help_test_locked' . $action); @@ -166,7 +174,9 @@ class HelpTopicAdminTest extends BrowserTestBase { $session->pageTextContains('Locked topic'); $this->drupalPostForm(NULL, [], 'Lock'); $session = $this->assertSession(); - $session->pageTextContains('Locked help topic'); + $session->pageTextContains("The help topic $title has been locked."); + $dblogs[] = "The help topic $title has been locked."; + // The '' action is actually edit. foreach (['', '/delete', '/lock'] as $action) { $this->drupalGet('admin/config/development/help/manage/help_test_locked' . $action); @@ -176,6 +186,12 @@ class HelpTopicAdminTest extends BrowserTestBase { $this->drupalGet('admin/config/development/help/manage/help_test_locked/unlock'); $session = $this->assertSession(); $session->statusCodeEquals(200); + + $this->drupalGet('admin/reports/dblog'); + $session = $this->assertSession(); + foreach ($dblogs as $message) { + $session->linkExists($message); + } } /** @@ -231,6 +247,8 @@ class HelpTopicAdminTest extends BrowserTestBase { return; } + $dblogs = []; + // Create a new help topic from the UI. $body = 'This text is for the foo topic'; $title = 'Foo topic'; @@ -242,7 +260,9 @@ class HelpTopicAdminTest extends BrowserTestBase { 'body[value]' => $body, ], 'Save'); $session = $this->assertSession(); - $session->pageTextContains('Help topic added'); + $session->pageTextContains("The help topic $title has been added."); + $dblogs[] = "The help topic $title has been added."; + $dblogs[] = 'View'; // Click to view the topic and verify the edit link works too. $this->clickLink($title); @@ -258,7 +278,8 @@ class HelpTopicAdminTest extends BrowserTestBase { 'id' => $new_id, ], 'Save'); $session = $this->assertSession(); - $session->pageTextContains('Help topic updated'); + $session->pageTextContains("The help topic $new_title has been updated."); + $dblogs[] = "The help topic $new_title has been updated."; $session->linkExists($new_title); // Test a few autocomplete values. @@ -296,9 +317,9 @@ class HelpTopicAdminTest extends BrowserTestBase { $session->pageTextContains($new_title); $this->drupalPostForm(NULL, [], 'Delete'); $session = $this->assertSession(); - $session->pageTextContains('The help topic'); - $session->pageTextContains('has been deleted.'); - $session->pageTextContains($new_title); + $session->pageTextContains("The help topic $new_title has been deleted"); + $dblogs[] = "The help topic $new_title has been deleted"; + // Verfiy we are back on the admin page and there is no longer a link // to the topic we just deleted. $session->linkExists('Add new help topic'); @@ -323,7 +344,7 @@ class HelpTopicAdminTest extends BrowserTestBase { 'related' => 'invalid.text', ], 'Save'); $session = $this->assertSession(); - $session->pageTextNotContains('Help topic added'); + $session->pageTextNotContains('has been added'); $session->pageTextContains('Must be a comma-separated list of existing topic machine names'); // Fix form and add dependency field. @@ -332,7 +353,7 @@ class HelpTopicAdminTest extends BrowserTestBase { 'modules' => 'color', ], 'Save'); $session = $this->assertSession(); - $session->pageTextContains('Help topic added'); + $session->pageTextContains('has been added'); $session->linkExists($title); $this->drupalGet('admin/help'); $session = $this->assertSession(); @@ -344,6 +365,12 @@ class HelpTopicAdminTest extends BrowserTestBase { $session = $this->assertSession(); $session->linkExists('Building a help system'); $session->linkNotExists($title); + + $this->drupalGet('admin/reports/dblog'); + $session = $this->assertSession(); + foreach ($dblogs as $message) { + $session->linkExists($message); + } } /**