-
Notifications
You must be signed in to change notification settings - Fork 0
/
math_parser.module
44 lines (40 loc) · 1.15 KB
/
math_parser.module
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
<?php
/**
* Implements hook_theme().
*
* @return array
*/
function math_parser_theme($existing, $type, $theme, $path) {
$template_params = ['formula' => NULL, 'result' => NULL, 'delta' => NULL];
return [
'formula_formatter_react' => [
'variables' => $template_params,
'template' => 'formula-formatter-react',
],
'formula_formatter_twig' => [
'variables' => $template_params,
'template' => 'formula-formatter-twig',
],
'field__math_parser' => [
'template' => 'field/field--math-parser',
'base hook' => 'field',
],
];
}
/**
* Implements hook_preprocess_HOOK().
*
* @param $variables
*/
function math_parser_preprocess_field__math_parser(&$variables) {
if ($node = \Drupal::request()->attributes->get('node')) {
$nid = $node->id();
if (isset($variables['items'])) {
$attributes = $variables['items'][0]['attributes'];
$attributes->setAttribute('id', 'math_parser_list_' . $nid . '_' . $variables['field_name']);
$attributes->setAttribute('data-nid', $nid);
$attributes->addClass('math-parser-list');
$variables['items'][0]['attributes'] = $attributes;
}
}
}