-
Notifications
You must be signed in to change notification settings - Fork 1
/
asu_react_core.module
121 lines (99 loc) · 4.17 KB
/
asu_react_core.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<?php
use Drupal\asu_react_core\ComponentFactory;
/**
* Implements hook_preprocess_HOOK().
*/
function asu_react_core_preprocess_paragraph(&$variables) {
$paragraph = $variables['paragraph'];
$type = $paragraph->type->target_id;
$component_builder = 'asu_react_core_process_component_' . $type;
if (function_exists($component_builder)) {
call_user_func_array($component_builder, [&$variables]);
}
}
/**
* Implements hook_preprocess_HOOK().
*/
function asu_react_core_preprocess_block(&$variables) {
$plugin_id = $variables['base_plugin_id'] ?? '';
if ($plugin_id != 'inline_block') {
return;
}
$type = $variables['derivative_plugin_id'];
$component = ComponentFactory::load($type);
if ($component) {
$component->buildSettings($variables);
}
}
function asu_react_core_process_component_testimonial(&$variables) {
/** @var \Drupal\paragraphs\Entity\Paragraph $paragraph */
$paragraph = $variables['paragraph'];
$id = $paragraph->uuid();
$cite = new \stdClass();
if ($paragraph->field_citation_author) {
$cite->name = $paragraph->field_citation_author->value;
}
if ($paragraph->field_citation_title) {
$cite->description = $paragraph->field_citation_title->value;
}
$quote = new \stdClass();
if ($paragraph->field_heading) {
$quote->title = $paragraph->field_heading->value;
}
if ($paragraph->field_formatted_text) {
$quote->content = $paragraph->field_formatted_text->value;
}
$quote->cite = $cite;
$testimonial = new \stdClass();
$testimonial->id = $id;
$testimonial->quote = $quote;
if ($paragraph->field_media->target_id && $paragraph->field_media->entity->field_media_image->target_id) {
$imageUri = $paragraph->field_media->entity->field_media_image->entity->getFileUri();
$testimonial->imageSource = \Drupal::service('file_url_generator')->generateAbsoluteString($imageUri);
$testimonial->imageAltText = $paragraph->field_media->entity->field_media_image->alt;
}
$settings = [];
$settings['components'][$paragraph->bundle()][$id] = $testimonial;
$variables['content']['#attached']['drupalSettings']['asu'] = $settings;
}
function asu_react_core_process_component_gallery_image(&$variables) {
/** @var \Drupal\paragraphs\Entity\Paragraph $paragraph */
$paragraph = $variables['paragraph'];
$id = $paragraph->uuid();
$image = new \stdClass();
$image->id = $id;
if ($paragraph->field_media->target_id && $paragraph->field_media->entity->field_media_image->target_id) {
$fileUri = $paragraph->field_media->entity->field_media_image->entity->getFileUri();
$image->imageSource = \Drupal::service('file_url_generator')->generateAbsoluteString($fileUri);
$image->imageAltText = $paragraph->field_media->entity->field_media_image->alt;
}
if ($paragraph->field_formatted_text) {
$image->content = $paragraph->field_formatted_text->value;
}
if ($paragraph->field_title) {
$image->title = $paragraph->field_title->value;
}
$settings = [];
$settings['components'][$paragraph->bundle()][$id] = $image;
$variables['content']['#attached']['drupalSettings']['asu'] = $settings;
}
function asu_react_core_process_component_card(&$variables) {
$paragraph = $variables['paragraph'];
$settings = \Drupal::service('asu_react_core.helper_functions')->getCardContent($paragraph);
$variables['content']['#attached']['drupalSettings']['asu'] = $settings;
}
function asu_react_core_process_component_card_degree(&$variables) {
$paragraph = $variables['paragraph'];
$settings = \Drupal::service('asu_react_core.helper_functions')->getCardContent($paragraph);
$variables['content']['#attached']['drupalSettings']['asu'] = $settings;
}
function asu_react_core_process_component_card_story(&$variables) {
$paragraph = $variables['paragraph'];
$settings = \Drupal::service('asu_react_core.helper_functions')->getCardContent($paragraph);
$variables['content']['#attached']['drupalSettings']['asu'] = $settings;
}
function asu_react_core_process_component_card_with_icon(&$variables) {
$paragraph = $variables['paragraph'];
$settings = \Drupal::service('asu_react_core.helper_functions')->getCardContent($paragraph);
$variables['content']['#attached']['drupalSettings']['asu'] = $settings;
}