public DbLogController::overview()
Displays a listing of database log messages.
Messages are truncated at 56 chars. Full-length messages can be viewed on the message details page.
Return value
array A render array as expected by drupal_render().
See also
dblog_clear_log_form()
dblog_event()
File
- core/modules/dblog/src/Controller/DbLogController.php, line 121
Class
- DbLogController
- Returns responses for dblog routes.
Namespace
Drupal\dblog\Controller
Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 | public function overview() { $filter = $this ->buildFilterQuery(); $rows = array (); $classes = static ::getLogLevelClassMap(); $this ->moduleHandler->loadInclude( 'dblog' , 'admin.inc' ); $build [ 'dblog_filter_form' ] = $this ->formBuilder->getForm( 'Drupal\dblog\Form\DblogFilterForm' ); $header = array ( // Icon column. '' , array ( 'data' => $this ->t( 'Type' ), 'field' => 'w.type' , 'class' => array (RESPONSIVE_PRIORITY_MEDIUM)), array ( 'data' => $this ->t( 'Date' ), 'field' => 'w.wid' , 'sort' => 'desc' , 'class' => array (RESPONSIVE_PRIORITY_LOW)), $this ->t( 'Message' ), array ( 'data' => $this ->t( 'User' ), 'field' => 'ufd.name' , 'class' => array (RESPONSIVE_PRIORITY_MEDIUM)), array ( 'data' => $this ->t( 'Operations' ), 'class' => array (RESPONSIVE_PRIORITY_LOW)), ); $query = $this ->database->select( 'watchdog' , 'w' ) ->extend( '\Drupal\Core\Database\Query\PagerSelectExtender' ) ->extend( '\Drupal\Core\Database\Query\TableSortExtender' ); $query ->fields( 'w' , array ( 'wid' , 'uid' , 'severity' , 'type' , 'timestamp' , 'message' , 'variables' , 'link' , )); $query ->leftJoin( 'users_field_data' , 'ufd' , 'w.uid = ufd.uid' ); if (! empty ( $filter [ 'where' ])) { $query ->where( $filter [ 'where' ], $filter [ 'args' ]); } $result = $query ->limit(50) ->orderByHeader( $header ) ->execute(); foreach ( $result as $dblog ) { $message = $this ->formatMessage( $dblog ); if ( $message && isset( $dblog ->wid)) { $title = Unicode::truncate(Html::decodeEntities( strip_tags ( $message )), 256, TRUE, TRUE); $log_text = Unicode::truncate( $title , 56, TRUE, TRUE); // The link generator will escape any unsafe HTML entities in the final // text. $message = $this ->l( $log_text , new Url( 'dblog.event' , array ( 'event_id' => $dblog ->wid), array ( 'attributes' => array ( // Provide a title for the link for useful hover hints. The // Attribute object will escape any unsafe HTML entities in the // final text. 'title' => $title , ), ))); } $username = array ( '#theme' => 'username' , '#account' => $this ->userStorage->load( $dblog ->uid), ); $rows [] = array ( 'data' => array ( // Cells. array ( 'class' => array ( 'icon' )), $this ->t( $dblog ->type), $this ->dateFormatter->format( $dblog ->timestamp, 'short' ), $message , array ( 'data' => $username ), array ( 'data' => array ( '#markup' => $dblog ->link)), ), // Attributes for table row. 'class' => array (Html::getClass( 'dblog-' . $dblog ->type), $classes [ $dblog ->severity]), ); } $build [ 'dblog_table' ] = array ( '#type' => 'table' , '#header' => $header , '#rows' => $rows , '#attributes' => array ( 'id' => 'admin-dblog' , 'class' => array ( 'admin-dblog' )), '#empty' => $this ->t( 'No log messages available.' ), '#attached' => array ( 'library' => array ( 'dblog/drupal.dblog' ), ), ); $build [ 'dblog_pager' ] = array ( '#type' => 'pager' ); return $build ; } |
Please login to continue.