log.module in Log entity 2.x
Same filename and directory in other branches
Hooks and customizations for the log module.
File
log.moduleView source
<?php
/**
* @file
* Hooks and customizations for the log module.
*/
use Drupal\Core\Render\Element;
use Drupal\Core\Routing\RouteMatchInterface;
/**
* Implements hook_help().
*/
function log_help($route_name, RouteMatchInterface $route_match) {
$output = '';
// Main module help for the log module.
if ($route_name == 'help.page.log') {
$output = '';
$output .= '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t('Provides Log entity') . '</p>';
}
return $output;
}
/**
* 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];
}
}
Functions
Name | Description |
---|---|
log_help | Implements hook_help(). |
log_theme | Implements hook_theme(). |
log_theme_suggestions_log | Implements hook_theme_suggestions_HOOK(). |
template_preprocess_log | Prepares variables for log templates. |