forked from borisay/assign_calc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathassign_calc.module
More file actions
executable file
·60 lines (53 loc) · 1.79 KB
/
Copy pathassign_calc.module
File metadata and controls
executable file
·60 lines (53 loc) · 1.79 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
/**
* @file
* Contains assign_calc.module.
*/
use Drupal\Core\Form\FormStateInterface;
use Drupal\node\NodeInterface;
// phpcs:disable
const BODY = 'body';
const STEPS = 'steps';
const STEP = 'step';
const PARAGRAPH_NAME = 'step';
// phpcs:enable
/**
* Attaches the assign_calc/basic library to assignment nodes and example forms.
*/
function assign_calc_page_attachments(array &$page) {
$node = \Drupal::routeMatch()->getParameter('node');
if ($node instanceof NodeInterface && $node->getType() == 'assignment' || \Drupal::routeMatch()->getRouteName() == 'example.form') {
$page['#attached']['library'][] = 'assign_calc/basic';
}
}
/**
* Alters the assignment planner feedback form subject default value.
*/
function assign_calc_form_alter(&$form, FormStateInterface $form_state, $form_id) {
if ($form_id == "contact_message_assignment_planner_feedback_form") {
$form['subject']['widget'][0]['value']['#default_value'] = "Assignment Planner Feedback";
}
}
/**
* Adds assign_calc attributes.
*/
function assign_calc_preprocess_node(&$variables) {
if ($variables['node']->getType() == 'assignment') {
$variables['content']['body']['#attributes']['assign_calc'] = BODY;
$variables['content']['field_steps']['#attributes']['assign_calc'] = STEPS;
$i = 0;
while ($variables['content']['field_steps'][$i]) {
$variables['content']['field_steps'][$i]['#attributes']['assign_calc'] = STEP;
$variables['content']['field_steps'][$i]['#attributes']['assign_calc_step'] = $i;
$i++;
}
}
}
/**
* Adds assign_calc attribute.
*/
function assign_calc_preprocess_field(&$variables) {
if ($variables['element']['#bundle'] === PARAGRAPH_NAME && $variables['entity_type'] == 'paragraph') {
$variables['attributes']['assign_calc'] = $variables['field_name'];
}
}