-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpreprocess.module
More file actions
46 lines (39 loc) · 1.44 KB
/
preprocess.module
File metadata and controls
46 lines (39 loc) · 1.44 KB
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
<?php
/**
* @file
* Preprocess module functions and hooks.
*/
/**
* Implements hook_preprocess_node().
*/
function preprocess_preprocess_node(&$variables) {
$entity_type = $variables['theme_hook_original'];
$plugin_service_id = ($entity_type === 'node') ? 'plugin.manager.preprocess_node_plugin_manager' : 'plugin.manager.preprocess_paragraph_plugin_manager';
$bundle = $variables[$entity_type]->getType();
$view_mode = $variables['elements']['#view_mode'];
$plugin_service = \Drupal::service($plugin_service_id);
$theme = \Drupal::service('theme.manager')->getActiveTheme()->getName();
// Do discovery only once per request.
$plugins = &drupal_static("preprocess_plugins_$bundle");
if (NULL === $plugins) {
$plugins = $plugin_service->getDefinitions();
}
// Select which preprocess plugin should be called.
foreach ($plugins as $plugin_id => $plugin) {
if ($plugin['bundle'] === $bundle && $plugin['view_mode'] === $view_mode && $plugin['theme'] === $theme) {
// Instantiate only plugins that are needed.
if (!isset($plugin['instance'])) {
// Save instances for later use.
$plugins[$plugin_id]['instance'] = $plugin_service->createInstance($plugin_id);
}
$plugins[$plugin_id]['instance']->process($variables);
break;
}
}
}
/**
* Implements hook_preprocess_paragraph().
*/
function preprocess_preprocess_paragraph(&$variables) {
preprocess_preprocess_node($variables);
}