This repository has been archived by the owner on Sep 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtide_search.install
119 lines (107 loc) · 4.4 KB
/
tide_search.install
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
<?php
/**
* @file
* Install file.
*/
use Drupal\tide_search\TideSearchOperation;
/**
* Implements hook_install().
*/
function tide_search_install() {
$tideSearchOperation = new TideSearchOperation();
$tideSearchOperation->removeTideAlertFromDatasource();
}
/**
* Implements hook_update_dependencies().
*/
function tide_search_update_dependencies() {
$dependencies = [];
$dependencies['tide_search'][10004] = ['tide_core' => 10005];
return $dependencies;
}
/**
* Install module tide_data_pipeline.
*/
function tide_search_update_10001() {
if (!\Drupal::moduleHandler()->moduleExists('tide_data_pipeline')) {
$module_installer = \Drupal::service('module_installer');
$module_installer->install(['tide_data_pipeline']);
}
}
/**
* Add secondary campaign to search listing.
*/
function tide_search_update_10002() {
\Drupal::moduleHandler()->loadInclude('tide_core', 'inc', 'includes/helpers');
$config_location = [\Drupal::service('extension.list.module')->getPath('tide_search') . '/config/optional'];
$config = 'field.field.node.tide_search_listing.field_landing_page_c_secondary';
$type = 'field_config';
$config_read = _tide_read_config($config, $config_location);
$storage = \Drupal::entityTypeManager()->getStorage($type);
$id = substr($config, strrpos($config, '.') + 1);
if ($storage->load($id) == NULL) {
$config_entity = $storage->createFromStorageRecord($config_read);
$config_entity->save();
}
$form_configs = [
'core.entity_view_display.node.tide_search_listing.default',
'core.entity_form_display.node.tide_search_listing.default',
'core.entity_view_display.node.tide_search_listing.teaser',
];
foreach ($form_configs as $form_config) {
$config = \Drupal::configFactory()->getEditable($form_config);
$config_read = _tide_read_config($form_config, $config_location, FALSE);
$config->set('dependencies', $config_read['dependencies']);
$config->set('content', $config_read['content']);
$config->set('hidden', $config_read['hidden']);
$config->save();
}
}
/**
* Adds field_above_results_content field to search listing.
*/
function tide_search_update_10003() {
module_load_include('inc', 'tide_core', 'includes/helpers');
$config_location = [\Drupal::service('extension.list.module')->getPath('tide_search') . '/config/optional'];
$configs = [
'field.storage.node.field_above_results_content' => 'field_storage_config',
'field.field.node.tide_search_listing.field_above_results_content' => 'field_config',
];
// Check if field already exported to config/sync.
foreach ($configs as $config => $type) {
$config_read = _tide_read_config($config, $config_location, TRUE);
$storage = \Drupal::entityTypeManager()->getStorage($type);
$config_entity = $storage->createFromStorageRecord($config_read);
$config_entity->save();
}
$form_configs = [
'core.entity_form_display.node.tide_search_listing.default',
'core.entity_view_display.node.tide_search_listing.default',
'core.entity_view_display.node.tide_search_listing.teaser',
];
foreach ($form_configs as $form_config) {
$config = \Drupal::configFactory()->getEditable($form_config);
$config_read = _tide_read_config($form_config, $config_location, FALSE);
$config->set('dependencies', $config_read['dependencies']);
$config->set('content', $config_read['content']);
$config->set('hidden', $config_read['hidden']);
$config->save();
}
}
/**
* Imports field_content_category field for existing sites.
*/
function tide_search_update_10004() {
\Drupal::moduleHandler()->loadInclude('tide_core', 'inc', 'includes/helpers');
$config_location = [\Drupal::service('extension.list.module')->getPath('tide_search') . '/config/optional'];
$config_read = _tide_read_config('field.field.node.tide_search_listing.field_content_category', $config_location, TRUE);
$storage = \Drupal::entityTypeManager()->getStorage('field_config');
$id = $storage->getIDFromConfigName('field.field.node.tide_search_listing.field_content_category', $storage->getEntityType()->getConfigPrefix());
if ($storage->load($id) == NULL) {
$config_entity = $storage->createFromStorageRecord($config_read);
$config_entity->save();
}
\Drupal::moduleHandler()->loadInclude('tide_core', 'inc', 'includes/updates');
_tide_core_field_content_category_default_value('tide_search_listing', 'Search listing');
_tide_core_content_category_form_display('tide_search_listing');
}