' . t('About') . ''; $output .= '
' . t('Provides Log entity') . '
'; } return $output; } /** * Implements hook_ENTITY_TYPE_presave(). */ function log_log_presave(LogInterface $log) { // Dispatch an event on log presave. // @todo Replace this with core event via https://www.drupal.org/node/2551893. $event = new LogEvent($log); $event_dispatcher = \Drupal::service('event_dispatcher'); $event_dispatcher->dispatch($event, LogEvent::PRESAVE); } /** * Implements hook_ENTITY_TYPE_insert(). */ function log_log_insert(LogInterface $log) { // Dispatch an event on log insert. // @todo Replace this with core event via https://www.drupal.org/node/2551893. $event = new LogEvent($log); $event_dispatcher = \Drupal::service('event_dispatcher'); $event_dispatcher->dispatch($event, LogEvent::INSERT); } /** * Implements hook_ENTITY_TYPE_update(). */ function log_log_update(LogInterface $log) { // Dispatch an event on log update. // @todo Replace this with core event via https://www.drupal.org/node/2551893. $event = new LogEvent($log); $event_dispatcher = \Drupal::service('event_dispatcher'); $event_dispatcher->dispatch($event, LogEvent::UPDATE); } /** * Implements hook_ENTITY_TYPE_delete(). */ function log_log_delete(LogInterface $log) { // Dispatch an event on log delete. // @todo Replace this with core event via https://www.drupal.org/node/2551893. $event = new LogEvent($log); $event_dispatcher = \Drupal::service('event_dispatcher'); $event_dispatcher->dispatch($event, LogEvent::DELETE); } /** * Implements hook_theme(). */ function log_theme() { return [ 'log' => [ 'render element' => 'elements', ], ]; } /** * Implements hook_theme_suggestions_HOOK(). */ function log_theme_suggestions_log(array $variables) { $suggestions = []; $log = $variables['elements']['#log']; $sanitized_view_mode = strtr($variables['elements']['#view_mode'], '.', '_'); $suggestions[] = 'log__' . $sanitized_view_mode; $suggestions[] = 'log__' . $log->bundle(); $suggestions[] = 'log__' . $log->bundle() . '__' . $sanitized_view_mode; $suggestions[] = 'log__' . $log->id(); $suggestions[] = 'log__' . $log->id() . '__' . $sanitized_view_mode; return $suggestions; } /** * Prepares variables for log templates. * * Default template: log.html.twig. * * @param array $variables * An associative array containing: * - elements: An associative array containing the log information and any * fields attached to the log. Properties used: * - #log: A \Drupal\log\Entity\Log object. The log entity. * - attributes: HTML attributes for the containing element. */ function template_preprocess_log(&$variables) { $variables['log'] = $variables['elements']['#log']; // Helpful $content variable for templates. foreach (Element::children($variables['elements']) as $key) { $variables['content'][$key] = $variables['elements'][$key]; } }