diff --git a/core/modules/dblog/dblog.module b/core/modules/dblog/dblog.module index a0afcd4..bc35f36 100644 --- a/core/modules/dblog/dblog.module +++ b/core/modules/dblog/dblog.module @@ -196,3 +196,22 @@ function dblog_theme() { ), ); } + +/** + * Provides a mapping between the severity constants and a readable version. + * + * @return array + * An assosiative array with the severity constant as key and ... as value. + */ +function dblog_views_severity_options_callback() { + return array( + WATCHDOG_DEBUG => 'dblog-debug', + WATCHDOG_INFO => 'dblog-info', + WATCHDOG_NOTICE => 'dblog-notice', + WATCHDOG_WARNING => 'dblog-warning', + WATCHDOG_ERROR => 'dblog-error', + WATCHDOG_CRITICAL => 'dblog-critical', + WATCHDOG_ALERT => 'dblog-alert', + WATCHDOG_EMERGENCY => 'dblog-emergency', + ); +} diff --git a/core/modules/dblog/dblog.views.inc b/core/modules/dblog/dblog.views.inc new file mode 100644 index 0000000..e8cae28 --- /dev/null +++ b/core/modules/dblog/dblog.views.inc @@ -0,0 +1,223 @@ + 'wid', + 'title' => t('Watchdog event'), + 'help' => t('Contains a list of log entries.'), + ); + + $data['watchdog']['wid'] = array( + 'title' => t('WID'), + 'help' => t('Unique watchdog event ID.'), + 'field' => array( + 'id' => 'numeric', + 'click sortable' => TRUE, + ), + 'filter' => array( + 'id' => 'numeric', + ), + 'argument' => array( + 'id' => 'numeric', + ), + 'search' => array( + 'id' => 'standard', + ), + ); + + $data['watchdog']['uid'] = array( + 'title' => t('UID'), + 'help' => t('The user ID of the user on which the log entry was written..'), + 'field' => array( + 'id' => 'numeric', + 'click sortable' => TRUE, + ), + 'filter' => array( + 'id' => 'numeric', + ), + 'argument' => array( + 'id' => 'numeric', + ), + 'search' => array( + 'id' => 'standard', + ), + 'relationship' => array( + 'title' => t('User'), + 'help' => t('The user on which the log entry as written.'), + 'base' => 'users', + 'base field' => 'uid', + 'id' => 'standard', + ), + ); + + $data['watchdog']['type'] = array( + 'title' => t('Type'), + 'help' => t('The of the log entry, for example "user" or "page not found.".'), + 'field' => array( + 'id' => 'standard', + ), + 'argument' => array( + 'id' => 'string', + ), + 'filter' => array( + 'id' => 'string', + ), + 'sort' => array( + 'id' => 'standard', + ), + ); + + $data['watchdog']['message'] = array( + 'title' => t('Message'), + 'help' => t('The actual message of the log entry.'), + 'field' => array( + 'id' => 'dblog_message', + ), + 'argument' => array( + 'id' => 'string', + ), + 'filter' => array( + 'id' => 'string', + ), + 'sort' => array( + 'id' => 'standard', + ), + ); + + $data['watchdog']['variables'] = array( + 'title' => t('Variables'), + 'help' => t('The variables of the log entry in a serialized format.'), + 'field' => array( + 'id' => 'serialized', + ), + 'argument' => array( + 'id' => 'string', + ), + 'filter' => array( + 'id' => 'string', + ), + 'sort' => array( + 'id' => 'standard', + ), + ); + + $data['watchdog']['severity'] = array( + 'title' => t('Severity level'), + 'help' => t('The severity level of the event; ranges from 0 (Emergency) to 7 (Debug).'), + 'field' => array( + 'id' => 'machine_name', + 'options callback' => 'dblog_views_severity_options_callback' + ), + 'filter' => array( + 'id' => 'in_operator', + 'options callback' => 'dblog_views_severity_options_callback' + ), + + ); + + $data['watchdog']['link'] = array( + 'title' => t('Link'), + 'help' => t('Link to view the result of the event.'), + 'field' => array( + 'id' => 'standard', + 'click sortable' => TRUE, + ), + 'argument' => array( + 'id' => 'string', + ), + 'filter' => array( + 'id' => 'string', + ), + 'sort' => array( + 'id' => 'standard', + ), + ); + + $data['watchdog']['location'] = array( + 'title' => t('Location'), + 'help' => t('URL of the origin of the event.'), + 'field' => array( + 'id' => 'standard', + 'click sortable' => TRUE, + ), + 'argument' => array( + 'id' => 'string', + ), + 'filter' => array( + 'id' => 'string', + ), + 'sort' => array( + 'id' => 'standard', + ), + ); + + $data['watchdog']['referer'] = array( + 'title' => t('Referer'), + 'help' => t('URL of the previous page.'), + 'field' => array( + 'id' => 'standard', + 'click sortable' => TRUE, + ), + 'argument' => array( + 'id' => 'string', + ), + 'filter' => array( + 'id' => 'string', + ), + 'sort' => array( + 'id' => 'standard', + ), + ); + + $data['watchdog']['hostname'] = array( + 'title' => t('Hostname'), + 'help' => t('Hostname of the user who triggered the event.'), + 'field' => array( + 'id' => 'standard', + 'click sortable' => TRUE, + ), + 'argument' => array( + 'id' => 'string', + ), + 'filter' => array( + 'id' => 'string', + ), + 'sort' => array( + 'id' => 'standard', + ), + ); + + $data['watchdog']['timestamp'] = array( + 'title' => t('Timestamp'), + 'help' => t('Date when the event occurred.'), + 'field' => array( + 'id' => 'date', + 'click sortable' => TRUE, + ), + 'argument' => array( + 'id' => 'date', + ), + 'filter' => array( + 'id' => 'date', + ), + 'sort' => array( + 'id' => 'date', + ), + ); + + return $data; +} diff --git a/core/modules/dblog/lib/Drupal/dblog/Plugin/views/field/DblogMessage.php b/core/modules/dblog/lib/Drupal/dblog/Plugin/views/field/DblogMessage.php new file mode 100644 index 0000000..f674ef4 --- /dev/null +++ b/core/modules/dblog/lib/Drupal/dblog/Plugin/views/field/DblogMessage.php @@ -0,0 +1,77 @@ +options['replace_variables']) { + $this->additional_fields[] = 'variables'; + } + } + + + /** + * Overrides \Drupal\views\Plugin\views\field\FieldPluginBase::defineOptions(). + */ + protected function defineOptions() { + $options = parent::defineOptions(); + $options['replace_variables'] = array('default' => TRUE, 'bool' => TRUE); + + return $options; + } + + /** + * Overrides \Drupal\views\Plugin\views\field\FieldPluginBase::buildOptionsForm(). + */ + public function buildOptionsForm(&$form, &$form_state) { + parent::buildOptionsForm($form, $form_state); + + $form['replace_variables'] = array( + '#title' => t('Replace variables'), + '#type' => 'checkbox', + '#default_value' => $this->options['replace_variables'], + ); + } + + + /** + * Overrides \Drupal\views\Plugin\views\field\FieldPluginBase::FieldPluginBase(). + */ + function render($values) { + $value = $this->get_value($values); + + if ($this->options['replace_variables']) { + $variables = unserialize($this->get_value($values, 'variables')); + return format_string($value, $variables); + } + else { + return $this->sanitizeValue($value); + } + } + +} diff --git a/core/modules/dblog/lib/Drupal/dblog/Tests/Views/ViewsIntegrationTest.php b/core/modules/dblog/lib/Drupal/dblog/Tests/Views/ViewsIntegrationTest.php new file mode 100644 index 0000000..d752239 --- /dev/null +++ b/core/modules/dblog/lib/Drupal/dblog/Tests/Views/ViewsIntegrationTest.php @@ -0,0 +1,68 @@ + 'Dblog Integration', + 'description' => 'Tests the views integration of dblog module.', + 'group' => 'Views Modules' + ); + } + + protected function setUp() { + parent::setUp(); + + ViewTestData::importTestViews(get_class($this), array('dblog_test_views')); + } + + /** + * Tests the integration. + */ + public function testIntegration() { + $entries = array(); + $entries[] = array( + 'message' => $this->randomName(), + ); + foreach ($entries as $entry) { + $entry += array( + 'type' => 'test-views', + 'variables' => array(), + ); + watchdog($entry['type'], $entry['message']); + } + + $view = views_get_view('test_dblog'); + + $this->executeView($view); + debug($view->result); + } + +} diff --git a/core/modules/dblog/tests/dblog_test_views/dblog_test_views.info b/core/modules/dblog/tests/dblog_test_views/dblog_test_views.info new file mode 100644 index 0000000..56fb11f --- /dev/null +++ b/core/modules/dblog/tests/dblog_test_views/dblog_test_views.info @@ -0,0 +1,8 @@ +name = Dblog test views +description = Provides default views for views dblog tests. +package = Testing +version = VERSION +core = 8.x +dependencies[] = dblog +dependencies[] = views +hidden = TRUE diff --git a/core/modules/dblog/tests/dblog_test_views/dblog_test_views.module b/core/modules/dblog/tests/dblog_test_views/dblog_test_views.module new file mode 100644 index 0000000..b3d9bbc --- /dev/null +++ b/core/modules/dblog/tests/dblog_test_views/dblog_test_views.module @@ -0,0 +1 @@ +enableModules($modules, FALSE); }