forked from dpc-sdp/tide_landing_page
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtide_landing_page.module
64 lines (57 loc) · 2.32 KB
/
tide_landing_page.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
<?php
/**
* @file
* Tide Landing Page module functionality.
*/
use Drupal\field\Entity\FieldConfig;
use Drupal\workflows\Entity\Workflow;
/**
* Implements hook_entity_bundle_create().
*/
function tide_landing_page_entity_bundle_create($entity_type_id, $bundle) {
/** @var \Drupal\Core\Extension\ModuleHandlerInterface $moduleHandler */
$moduleHandler = \Drupal::service('module_handler');
if ($entity_type_id == 'node') {
// Support the new content type in the Referenced Content field
// of the Card automated paragraphs.
$supported_paragraph_types = [
'card_navigation_featured_auto',
'card_navigation_auto',
'card_promotion_auto',
];
foreach ($supported_paragraph_types as $supported_paragraph_type) {
$field_config = FieldConfig::loadByName("paragraph", $supported_paragraph_type, "field_paragraph_reference");
if ($field_config) {
$handler_settings = $field_config->getSetting('handler_settings');
$handler_settings['target_bundles'][$bundle] = $bundle;
$field_config->setSetting('handler_settings', $handler_settings);
$field_config->save();
}
}
// Enable Editorial workflow for landing page if workflow module is enabled.
if ($bundle == 'landing_page') {
if ($moduleHandler->moduleExists('workflows')) {
$editorial_workflow = Workflow::load('editorial');
if ($editorial_workflow) {
$editorial_workflow->getTypePlugin()
->addEntityTypeAndBundle('node', 'landing_page');
$editorial_workflow->save();
}
}
}
}
// Add the Featured News paragraph to Landing Page component if exists.
if ($entity_type_id == 'paragraph') {
$field_config = FieldConfig::loadByName('node', 'landing_page', 'field_landing_page_component');
if ($field_config) {
$handler_settings = $field_config->getSetting('handler_settings');
$is_featured_news = ($bundle == 'featured_news' && $moduleHandler->moduleExists('tide_news'));
$is_embedded_webform = ($bundle == 'embedded_webform' && $moduleHandler->moduleExists('tide_webform'));
if ($is_featured_news || $is_embedded_webform) {
$handler_settings['target_bundles'][$bundle] = $bundle;
$field_config->setSetting('handler_settings', $handler_settings);
$field_config->save();
}
}
}
}