Newer
Older
Eric Bremner
committed
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
<?php
namespace Drupal\uw_cfg_common\Service;
use Drupal\node\Entity\Node;
/**
* Class UwNodeContent.
*
* Gets the content out of a node.
*
* @package Drupal\uw_cfg_common\Service
*/
class UwNodeContent {
/**
* The UW node data service.
*
* @var UwNodeData
*/
private $uwNodeData;
/**
* Default constructor.
*
* @param UwNodeData $uwNodeData
* The UW node data service.
*/
public function __construct(UwNodeData $uwNodeData) {
$this->uwNodeData = $uwNodeData;
}
/**
* Gets the content of a node.
*
* @param \Drupal\node\Entity\Node $node
* The node.
* @param string $view_mode
* The view mode.
* @param string $content
* The content to get (either layout builder or summary)
* @param array $featured_image
* Whether this node has a featured image or not.
*
* @return array
* Array of content to get from the node.
*/
public function getNodeContent(Node $node, string $view_mode, string $content, array $featured_image): array {
// Get the flags for the node.
$node_flags = $this->getNodeFlags($node, $view_mode, $content, $featured_image);
Eric Bremner
committed
// Setup the node data array, based on flags.
Eric Bremner
committed
switch ($node->getType()) {
case 'uw_ct_blog':
Eric Bremner
committed
$content_data = $this->getBlogContent($node_flags);
Eric Bremner
committed
break;
case 'uw_ct_event':
$content_data = $this->getEventContent($node_flags);
break;
case 'uw_ct_news_item':
Eric Bremner
committed
$content_data = $this->getNewsContent($node_flags);
Eric Bremner
committed
break;
case 'uw_ct_web_page':
Eric Bremner
committed
$content_data = $this->getWebPageContent($node_flags);
Eric Bremner
committed
break;
case 'uw_ct_catalog_item':
Eric Bremner
committed
$content_data = $this->getCatalogItemContent($node_flags);
Eric Bremner
committed
break;
case 'uw_ct_contact':
Eric Bremner
committed
$content_data = $this->getContactContent($node_flags);
Eric Bremner
committed
break;
case 'uw_ct_profile':
Eric Bremner
committed
$content_data = $this->getProfileContent($node_flags);
Eric Bremner
committed
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
break;
}
return $this->uwNodeData->getNodeData($node, $view_mode, $content_data);
}
/**
* Get the flags for the node.
*
* @param \Drupal\node\Entity\Node $node
* The node.
* @param string $view_mode
* The view mode.
* @param string $content
* The content to get (layout builder or summary).
* @param array $featured_image
* Whether this node has a featured image.
*
* @return array
* Array of flags for the node.
*/
public function getNodeFlags(Node $node, string $view_mode, string $content, array $featured_image): array {
// Flags for getting teaser content.
$node_flags['get_header'] = FALSE;
$node_flags['get_footer'] = FALSE;
$node_flags['get_image'] = FALSE;
$node_flags['get_content'] = FALSE;
$node_flags['get_title'] = TRUE;
// Setup flags based on teaser content argument.
if ($content == 'all') {
$node_flags['get_header'] = TRUE;
$node_flags['get_footer'] = TRUE;
$node_flags['get_content'] = TRUE;
if ($view_mode == 'teaser') {
$node_flags['get_image'] = TRUE;
}
if ($view_mode == 'full') {
$node_flags['get_title'] = FALSE;
if (in_array($node->getType(), array_keys($featured_image))) {
$node_flags['get_image'] = TRUE;
$node_flags['get_title'] = TRUE;
}
}
}
else {
if ($content == 'header') {
$node_flags['get_header'] = TRUE;
$node_flags['get_image'] = TRUE;
}
if ($content == 'footer') {
$node_flags['get_footer'] = TRUE;
$node_flags['get_title'] = FALSE;
}
}
return $node_flags;
}
Eric Bremner
committed
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
/**
* Get the node content for blog content type.
*
* @param array $node_flags
* The flags for the node.
*
* @return array
* Array of content to get from the node.
*/
public function getBlogContent(array $node_flags): array {
// The list of tags for blogs.
$tag_list = [
'field_uw_blog_tags',
'field_uw_audience',
];
return [
'title' => $node_flags['get_title'] ? TRUE : NULL,
'url' => TRUE,
'date' => $node_flags['get_header'] ? 'field_uw_blog_date' : NULL,
'author' => $node_flags['get_header'] ? TRUE : NULL,
'sources' => $node_flags['get_image'] ? 'field_uw_blog_listing_page_image' : NULL,
'hero' => $node_flags['get_image'] ? 'field_uw_hero_image' : NULL,
'content' => $node_flags['get_content'] ? 'field_uw_blog_summary' : NULL,
'tags' => $node_flags['get_footer'] ? $tag_list : NULL,
];
}
Eric Bremner
committed
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
/**
* Get the node content for event content type.
*
* @param array $node_flags
* The flags for the node.
*
* @return array
* Array of content to get from the node.
*/
public function getEventContent(array $node_flags): array {
$content_data['url'] = [
'type' => 'url',
];
if ($node_flags['get_title']) {
$content_data['title'] = [
'type' => 'title',
];
}
if ($node_flags['get_header']) {
$content_data['date'] = [
'type' => 'date',
'field' => 'field_uw_event_date',
];
}
if ($node_flags['get_image']) {
$content_data['sources'] = [
'type' => 'sources',
'field' => 'field_uw_event_listing_page_img',
];
}
if ($node_flags['get_content']) {
$content_data['content'] = [
'type' => 'content',
'field' => 'field_uw_event_summary',
];
}
if ($node_flags['get_footer']) {
$content_data['additional_info'] = [
'has_children' => TRUE,
'host' => [
'type' => 'link',
'field' => 'field_uw_event_host',
'label' => 'Host',
],
'event_website' => [
'type' => 'link',
'field' => 'field_uw_event_website',
'label' => 'Event website',
],
'cost' => [
'type' => 'plain_text',
'field' => 'field_uw_event_cost',
'label' => 'Cost',
],
];
$content_data['location_info'] = [
'has_children' => TRUE,
'address' => [
'type' => 'address',
'field' => 'field_uw_event_location_address',
'name' => 'Location address',
],
'map' => [
'type' => 'map',
'field' => 'field_uw_event_location_coord',
'name' => 'Location coordinates',
],
];
$content_data['tags'] = [
'type' => 'terms',
'field' => [
'field_uw_event_tags',
'field_uw_audience',
'field_uw_event_type',
],
];
}
return $content_data;
}
Eric Bremner
committed
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
/**
* Get the node content for news content type.
*
* @param array $node_flags
* The flags for the node.
*
* @return array
* Array of content to get from the node.
*/
public function getNewsContent(array $node_flags): array {
// The list of tags for news.
$tag_list = [
'field_uw_news_tags',
'field_uw_audience',
];
return [
'title' => $node_flags['get_title'] ? TRUE : NULL,
'url' => TRUE,
'date' => $node_flags['get_header'] ? 'field_uw_news_date' : NULL,
'sources' => $node_flags['get_image'] ? 'field_uw_news_listing_page_image' : NULL,
'hero' => $node_flags['get_image'] ? 'field_uw_hero_image' : NULL,
'content' => $node_flags['get_content'] ? 'field_uw_news_summary' : NULL,
'tags' => $node_flags['get_footer'] ? $tag_list : NULL,
];
}
/**
* Get the node content for web page content type.
*
* @param array $node_flags
* The flags for the node.
*
* @return array
* Array of content to get from the node.
*/
public function getWebPageContent(array $node_flags): array {
return [
'title' => $node_flags['get_title'] ? TRUE : NULL,
'content' => $node_flags['get_content'] ? 'layout_builder__layout' : NULL,
];
}
/**
* Get the node content for catalog item content type.
*
* @param array $node_flags
* The flags for the node.
*
* @return array
* Array of content to get from the node.
*/
public function getCatalogItemContent(array $node_flags): array {
$tags = [
'Category' => 'field_uw_catalog_category',
'Faculty' => 'field_uw_catalog_faculty',
'Audience' => 'field_uw_audience',
];
return [
'title' => $node_flags['get_title'] ? TRUE : NULL,
'content' => $node_flags['get_content'] ? 'layout_builder__layout' : NULL,
'catalog_tags' => $node_flags['get_footer'] ? $tags : NULL,
];
}
/**
* Get the node content for catalog item content type.
*
* @param array $node_flags
* The flags for the node.
*
* @return array
* Array of content to get from the node.
*/
public function getContactContent(array $node_flags): array {
return [
'title' => $node_flags['get_title'] ? TRUE : NULL,
'position' => $node_flags['get_header'] ? 'field_uw_ct_contact_title' : NULL,
'affiliation' => $node_flags['get_header'] ? 'field_uw_ct_contact_affiliation' : NULL,
'image' => $node_flags['get_image'] ? 'field_uw_ct_contact_image' : NULL,
'content' => $node_flags['get_content'] ? 'layout_builder__layout' : NULL,
'email' => $node_flags['get_footer'] ? 'field_uw_ct_contact_email' : NULL,
'location' => $node_flags['get_footer'] ? 'field_uw_ct_contact_location' : NULL,
'phone' => $node_flags['get_footer'] ? 'field_uw_ct_contact_phone' : NULL,
'additional_info' => $node_flags['get_footer'] ? 'field_uw_ct_contact_info' : NULL,
'link_profile' => $node_flags['get_footer'] ? 'field_uw_ct_contact_link_profile' : NULL,
'personal_webpage' => $node_flags['get_footer'] ? 'field_uw_ct_contact_link_persona' : NULL,
'contact_for' => $node_flags['get_footer'] ? 'field_uw_ct_contact_contact_for' : NULL,
'groups' => $node_flags['get_footer'] ? 'field_uw_ct_contact_group' : NULL,
'url' => TRUE,
];
}
/**
* Get the node content for profile content type.
*
* @param array $node_flags
* The flags for the node.
*
* @return array
* Array of content to get from the node.
*/
public function getProfileContent(array $node_flags): array {
$tag_list = [
'field_uw_ct_profile_type',
];
return [
'title' => $node_flags['get_title'] ? TRUE : NULL,
'position' => $node_flags['get_header'] ? 'field_uw_ct_profile_title' : NULL,
'affiliation' => $node_flags['get_header'] ? 'field_uw_ct_profile_affiliation' : NULL,
'content' => $node_flags['get_content'] ? 'field_uw_profile_summary' : NULL,
'image' => $node_flags['get_header'] ? 'field_uw_ct_profile_image' : NULL,
'sources' => $node_flags['get_image'] ? 'field_uw_ct_profile_image' : NULL,
'tags' => $node_flags['get_footer'] ? $tag_list : NULL,
'link_profile' => $node_flags['get_footer'] ? 'field_uw_ct_profile_info_link' : NULL,
'personal_webpage' => $node_flags['get_footer'] ? 'field_uw_ct_profile_link_persona' : NULL,
'url' => TRUE,
];
}