diff --git a/core/modules/dblog/dblog.links.task.yml b/core/modules/dblog/dblog.links.task.yml new file mode 100644 index 000000000000..70987488a514 --- /dev/null +++ b/core/modules/dblog/dblog.links.task.yml @@ -0,0 +1,8 @@ +dblog.view_logs: + title: 'View' + route_name: dblog.overview + base_route: dblog.overview +dblog.clear_logs: + title: 'Delete' + route_name: dblog.confirm + base_route: dblog.overview diff --git a/core/modules/dblog/src/Controller/DbLogController.php b/core/modules/dblog/src/Controller/DbLogController.php index 7c83cce275bc..572b9ae5ac59 100644 --- a/core/modules/dblog/src/Controller/DbLogController.php +++ b/core/modules/dblog/src/Controller/DbLogController.php @@ -128,7 +128,6 @@ class DbLogController extends ControllerBase { $this->moduleHandler->loadInclude('dblog', 'admin.inc'); $build['dblog_filter_form'] = $this->formBuilder->getForm('Drupal\dblog\Form\DblogFilterForm'); - $build['dblog_clear_log_form'] = $this->formBuilder->getForm('Drupal\dblog\Form\DblogClearLogForm'); $header = array( // Icon column. diff --git a/core/modules/dblog/src/Form/DblogClearLogForm.php b/core/modules/dblog/src/Form/DblogClearLogForm.php deleted file mode 100644 index 134cfc1f17fd..000000000000 --- a/core/modules/dblog/src/Form/DblogClearLogForm.php +++ /dev/null @@ -1,71 +0,0 @@ -connection = $connection; - } - - /** - * {@inheritdoc} - */ - public static function create(ContainerInterface $container) { - return new static( - $container->get('database') - ); - } - - /** - * {@inheritdoc} - */ - public function getFormId() { - return 'dblog_clear_log_form'; - } - - /** - * {@inheritdoc} - */ - public function buildForm(array $form, FormStateInterface $form_state) { - $form['dblog_clear'] = array( - '#type' => 'details', - '#title' => $this->t('Clear log messages'), - '#description' => $this->t('This will permanently remove the log messages from the database.'), - ); - $form['dblog_clear']['clear'] = array( - '#type' => 'submit', - '#value' => $this->t('Clear log messages'), - ); - return $form; - } - - /** - * {@inheritdoc} - */ - public function submitForm(array &$form, FormStateInterface $form_state) { - $form_state->setRedirect('dblog.confirm'); - } - -} diff --git a/core/modules/dblog/src/Form/DblogFilterForm.php b/core/modules/dblog/src/Form/DblogFilterForm.php index 11bd54bd29d8..0434f121a0f9 100644 --- a/core/modules/dblog/src/Form/DblogFilterForm.php +++ b/core/modules/dblog/src/Form/DblogFilterForm.php @@ -26,7 +26,7 @@ class DblogFilterForm extends FormBase { $form['filters'] = array( '#type' => 'details', '#title' => $this->t('Filter log messages'), - '#open' => !empty($_SESSION['dblog_overview_filter']), + '#open' => TRUE, ); foreach ($filters as $key => $filter) { $form['filters']['status'][$key] = array( diff --git a/core/modules/dblog/src/Tests/DbLogTest.php b/core/modules/dblog/src/Tests/DbLogTest.php index 17066458fea6..90cb6c2bf396 100644 --- a/core/modules/dblog/src/Tests/DbLogTest.php +++ b/core/modules/dblog/src/Tests/DbLogTest.php @@ -220,6 +220,32 @@ class DbLogTest extends WebTestBase { } } + /** + * Clear the entry logs by clicking on 'Clear log messages' button. + */ + protected function clearLogsEntries() { + $this->drupalGet(Url::fromRoute('dblog.confirm')); + } + + /** + * Filters the logs according to the specific severity and log entry type. + * + * @param string $type + * (optional) The log entry type. + * @param string $severity + * (optional) The log entry severity. + */ + protected function filterLogsEntries($type = NULL, $severity = NULL) { + $edit = array(); + if (!is_null($type)) { + $edit['type[]'] = $type; + } + if (!is_null($severity)) { + $edit['severity[]'] = $severity; + } + $this->drupalPostForm(NULL, $edit, t('Filter')); + } + /** * Confirms that database log reports are displayed at the correct paths. * @@ -547,7 +573,7 @@ class DbLogTest extends WebTestBase { // Log in the admin user. $this->drupalLogin($this->adminUser); // Post in order to clear the database table. - $this->drupalPostForm('admin/reports/dblog', array(), t('Clear log messages')); + $this->clearLogsEntries(); // Confirm that the logs should be cleared. $this->drupalPostForm(NULL, array(), 'Confirm'); // Count the rows in watchdog that previously related to the deleted user. @@ -595,10 +621,7 @@ class DbLogTest extends WebTestBase { // Filter by each type and confirm that entries with various severities are // displayed. foreach ($type_names as $type_name) { - $edit = array( - 'type[]' => array($type_name), - ); - $this->drupalPostForm(NULL, $edit, t('Filter')); + $this->filterLogsEntries($type_name); // Count the number of entries of this type. $type_count = 0; @@ -615,11 +638,7 @@ class DbLogTest extends WebTestBase { // Set the filter to match each of the two filter-type attributes and // confirm the correct number of entries are displayed. foreach ($types as $type) { - $edit = array( - 'type[]' => array($type['type']), - 'severity[]' => array($type['severity']), - ); - $this->drupalPostForm(NULL, $edit, t('Filter')); + $this->filterLogsEntries($type['type'], $type['severity']); $count = $this->getTypeCount($types); $this->assertEqual(array_sum($count), $type['count'], 'Count matched'); @@ -630,7 +649,7 @@ class DbLogTest extends WebTestBase { $this->assertText(t('Operations'), 'Operations text found'); // Clear all logs and make sure the confirmation message is found. - $this->drupalPostForm('admin/reports/dblog', array(), t('Clear log messages')); + $this->clearLogsEntries(); // Confirm that the logs should be cleared. $this->drupalPostForm(NULL, array(), 'Confirm'); $this->assertText(t('Database log cleared.'), 'Confirmation message found'); @@ -648,7 +667,7 @@ class DbLogTest extends WebTestBase { */ protected function getLogEntries() { $entries = array(); - if ($table = $this->xpath('.//table[@id="admin-dblog"]')) { + if ($table = $this->getLogsEntriesTable()) { $table = array_shift($table); foreach ($table->tbody->tr as $row) { $entries[] = array( @@ -662,6 +681,16 @@ class DbLogTest extends WebTestBase { return $entries; } + /** + * Find the Logs table in the DOM. + * + * @return \SimpleXMLElement[] + * The return value of a xpath search. + */ + protected function getLogsEntriesTable() { + return $this->xpath('.//table[@id="admin-dblog"]'); + } + /** * Gets the count of database log entries by database log event type. *