forked from YCloudYUSA/y_lb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
y_lb.install
223 lines (202 loc) · 7.68 KB
/
y_lb.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
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
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
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
<?php
/**
* @file
*/
use Drupal\Core\Field\BaseFieldDefinition;
/**
* Implements hook_install().
*/
function y_lb_install() {
// Import generic bootstrap styles configuration.
$path = \Drupal::service('extension.list.module')->getPath('y_lb') . '/config/optional';
$config_importer = \Drupal::service('config_import.importer');
$config_importer->setDirectory($path);
$config_importer->importConfigs([
'bootstrap_styles.settings',
]);
// Install Node fields.
_y_lb_install_node_additional_fields();
}
/**
* Implements hook_uninstall().
*/
function y_lb_uninstall() {
$fields = [
'override_styles',
'styles',
];
$update_manager = \Drupal::entityDefinitionUpdateManager();
foreach ($fields as $field) {
$definition = $update_manager->getFieldStorageDefinition($field, 'node');
$update_manager->uninstallFieldStorageDefinition($definition);
}
}
/**
* Add color for layout builder.
*/
function y_lb_update_9001(&$sandbox) {
$path = \Drupal::service('extension.list.module')->getPath('y_lb') . '/config/optional';
/** @var \Drupal\config_import\ConfigImporterService $config_importer */
$config_importer = \Drupal::service('config_import.importer');
$config_importer->setDirectory($path);
$config_importer->importConfigs([
'bootstrap_styles.settings',
]);
}
/**
* Add border color for layout builder.
*/
function y_lb_update_9002(&$sandbox) {
$path = \Drupal::service('extension.list.module')->getPath('y_lb') . '/config/optional';
/** @var \Drupal\config_import\ConfigImporterService $config_importer */
$config_importer = \Drupal::service('config_import.importer');
$config_importer->setDirectory($path);
$config_importer->importConfigs([
'bootstrap_styles.settings',
]);
}
/**
* Add node_revision_delete configuration.
*/
function y_lb_update_9003(&$sandbox) {
\Drupal::service('module_installer')->install(['node_revision_delete']);
$path = \Drupal::service('extension.list.module')->getPath('y_lb') . '/config/install';
/** @var \Drupal\config_import\ConfigImporterService $config_importer */
$config_importer = \Drupal::service('config_import.importer');
$config_importer->setDirectory($path);
$config_importer->importConfigs([
'node.type.landing_page_lb',
]);
}
/**
* Helper function to update Node base field definition with new fields.
*/
function _y_lb_install_node_additional_fields() {
$update_manager = \Drupal::entityDefinitionUpdateManager();
$override_styles_storage = BaseFieldDefinition::create('boolean')
->setLabel(t('Override default y Styles'))
->setDescription(t('Whether or not the node should override the default Y styles (e.g. Color scheme, etc.).'))
->setRevisionable(TRUE)
->setDefaultValue(FALSE)
->setInitialValue(FALSE)
->setDisplayConfigurable('form', FALSE)
->setDisplayConfigurable('view', FALSE);
$styles_storage = BaseFieldDefinition::create('string_long')
->setLabel(t('Y Styles'))
->setDescription(t('Node specific Y Styles to be applied.'))
->setRevisionable(TRUE)
->setInitialValue(serialize([]))
->setSetting('case_sensitive', TRUE)
->setDisplayConfigurable('form', FALSE)
->setDisplayConfigurable('view', FALSE);
$update_manager->installFieldStorageDefinition('override_styles', 'node', 'node', $override_styles_storage);
$update_manager->installFieldStorageDefinition('styles', 'node', 'node', $styles_storage);
}
/**
* Install Node additional fields - override_styles and styles.
*/
function y_lb_update_9004(&$sandbox) {
_y_lb_install_node_additional_fields();
}
/**
* Add the footer section to the Landing page Layout.
*/
function y_lb_update_9005(&$sandbox) {
\Drupal::service('module_installer')->install(['node_revision_delete']);
$path = \Drupal::service('extension.list.module')->getPath('y_lb') . '/config/install';
/** @var \Drupal\config_import\ConfigImporterService $config_importer */
$config_importer = \Drupal::service('config_import.importer');
$config_importer->setDirectory($path);
$config_importer->importConfigs([
'field.storage.node.field_meta_description',
'field.storage.node.field_meta_image',
'field.storage.node.field_meta_tags',
'field.field.node.landing_page_lb.field_meta_description',
'field.field.node.landing_page_lb.field_meta_image',
'field.field.node.landing_page_lb.field_meta_tags',
'core.entity_form_display.node.landing_page_lb.default',
'core.entity_view_display.node.landing_page_lb.default',
]);
}
/**
* Remove deprecated classes from LB styles
*/
function y_lb_update_9006(&$sandbox) {
$path = \Drupal::service('extension.list.module')->getPath('y_lb') . '/config/optional';
/** @var \Drupal\config_import\ConfigImporterService $config_importer */
$config_importer = \Drupal::service('config_import.importer');
$config_importer->setDirectory($path);
$config_importer->importConfigs([
'bootstrap_styles.settings',
]);
}
/**
* Add pathauto aliases.
*/
function y_lb_update_9007(&$sandbox) {
$path = \Drupal::service('extension.list.module')->getPath('y_lb') . '/config/install';
/** @var \Drupal\config_import\ConfigImporterService $config_importer */
$config_importer = \Drupal::service('config_import.importer');
$config_importer->setDirectory($path);
$config_importer->importConfigs([
'pathauto.pattern.landing_page_lb',
'bootstrap_styles.settings',
]);
}
/**
* Add layout_builder_operation_link to add Layout to Content Admin dropdown.
*/
function y_lb_update_9008(&$sandbox) {
\Drupal::service('module_installer')->install(['layout_builder_operation_link']);
}
/**
* Add layout_builder_save_and_edit to add "Save and edit layout" button.
*/
function y_lb_update_9009(&$sandbox) {
\Drupal::service('module_installer')->install(['layout_builder_save_and_edit']);
}
/**
* Update Default view for Landing page.
*/
function y_lb_update_9010(&$sandbox) {
$path = \Drupal::service('extension.list.module')->getPath('y_lb') . '/config/install';
/** @var \Drupal\config_import\ConfigImporterService $config_importer */
$config_importer = \Drupal::service('config_import.importer');
$config_importer->setDirectory($path);
$config_importer->importConfigs([
'field.storage.node.field_meta_description',
'field.storage.node.field_meta_image',
'field.storage.node.field_meta_tags',
'field.field.node.landing_page_lb.field_meta_description',
'field.field.node.landing_page_lb.field_meta_image',
'field.field.node.landing_page_lb.field_meta_tags',
'core.entity_form_display.node.landing_page_lb.default',
'core.entity_view_display.node.landing_page_lb.default',
]);
}
/**
* Add metadata helper fields and enable meta tags
*/
function y_lb_update_9011(&$sandbox) {
$configs = [
'field.storage.node.field_meta_description',
'field.storage.node.field_meta_image',
'field.storage.node.field_meta_tags',
'field.field.node.landing_page_lb.field_meta_description',
'field.field.node.landing_page_lb.field_meta_image',
'field.field.node.landing_page_lb.field_meta_tags',
'core.entity_form_display.node.landing_page_lb.default',
'core.entity_view_display.node.landing_page_lb.default',
];
// Only import the metatag config if it's not already configured.
$active_config = \Drupal::configFactory()->getEditable('metatag.metatag_defaults.node__landing_page_lb');
$settings = $active_config->get('tags');
if (!isset($settings)) {
$configs[] = 'metatag.metatag_defaults.node__landing_page_lb';
}
$path = \Drupal::service('extension.list.module')->getPath('y_lb') . '/config/install';
/** @var \Drupal\config_import\ConfigImporterService $config_importer */
$config_importer = \Drupal::service('config_import.importer');
$config_importer->setDirectory($path);
$config_importer->importConfigs($configs);
}