forked from ymcatwincities/openy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathopeny.profile
560 lines (522 loc) · 16.5 KB
/
openy.profile
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
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
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
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
<?php
/**
* @file
* Defines the OpenY Profile install screen by modifying the install form.
*/
use Drupal\openy\Form\ContentSelectForm;
use Drupal\openy\Form\ThirdPartyServicesForm;
use Drupal\openy\Form\UploadFontMessageForm;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Routing\RouteMatchInterface;
/**
* Implements hook_install_tasks().
*/
function openy_install_tasks() {
return [
'openy_select_content' => [
'display_name' => t('Import demo content'),
'display' => TRUE,
'type' => 'form',
'function' => ContentSelectForm::class,
],
'openy_import_content' => [
'type' => 'batch',
],
'openy_set_frontpage' => [
'type' => 'batch',
],
'openy_discover_broken_paragraphs' => [
'type' => 'batch',
],
'openy_fix_configured_paragraph_blocks' => [
'type' => 'batch',
],
'openy_third_party_services' => [
'display_name' => t('3rd party services'),
'display' => TRUE,
'type' => 'form',
'function' => ThirdPartyServicesForm::class,
],
'openy_upload_font_message' => [
'display_name' => t('Read font info'),
'display' => TRUE,
'type' => 'form',
'function' => UploadFontMessageForm::class,
],
'openy_gtranslate_place_blocks' => [
'type' => 'batch',
],
];
}
/**
* Create Google Translate block content.
* Block already added from OpenY Google Translate module configs.
*/
function openy_gtranslate_place_blocks(array &$install_state) {
$moduleHandler = \Drupal::service('module_handler');
if (!$moduleHandler->moduleExists('openy_gtranslate')) {
return ['operations' => []];
}
$themes_list = [
'openy_rose' => '5a698466-f499-4dda-a084-4d61c1d0e902',
'openy_lily' => '5a698466-f499-4dda-a084-4d61c1d0e777',
];
/** @var \Drupal\Core\Entity\EntityTypeManager $entityTypeManager */
$entityTypeManager = \Drupal::service('entity_type.manager');
foreach ($themes_list as $theme => $uuid) {
/** @var \Drupal\block_content\Entity\BlockContent $blockContent */
$blockContent = $entityTypeManager->getStorage('block_content')->create([
'type' => 'openy_gtranslate_block',
'info' => t('Google Translate Block'),
'uuid' => $uuid,
]);
$blockContent->save();
}
return ['operations' => []];
}
/**
* Mapping for demo content configs.
*
* @param null|string $key
* Name of the section with demo content.
*
* @return array
* Mapping array.
*/
function openy_demo_content_configs_map($key = NULL) {
// Maps selection to migrations.
$map = [
'required' => [],
'optional' => [
'openy_demo_ahb' => [
'openy_demo_entity_ahb',
],
'openy_demo_nsocial_post' => [
'openy_demo_node_social_post',
],
'openy_demo_tcolor' => [
'openy_demo_taxonomy_term_color',
],
'openy_demo_tarea' => [
'openy_demo_taxonomy_term_area',
],
'openy_demo_tblog' => [
'openy_demo_taxonomy_term_blog_category',
],
'openy_demo_tnews' => [
'openy_demo_taxonomy_term_news_category',
],
'openy_demo_tfacility' => [
'openy_demo_taxonomy_term_facility_type',
],
'openy_demo_tfitness' => [
'openy_demo_taxonomy_term_fitness_category',
],
'openy_demo_tamenities' => [
'openy_demo_taxonomy_term_amenities',
],
'openy_demo_bfooter' => [
'openy_demo_block_content_footer',
],
'openy_demo_bmicrosites_menu' => [
'openy_demo_block_microsites_menu',
],
'openy_demo_addthis' => [],
'openy_demo_bsimple' => [
'openy_demo_block_content_simple',
],
'openy_demo_bamenities' => [
'openy_demo_block_content_amenities',
],
],
'alerts' => [
'openy_demo_nalert' => [
'openy_demo_node_alert',
],
],
'branches' => [
'openy_demo_nbranch' => [
'openy_demo_node_branch',
],
],
'camps' => [
'openy_demo_ncamp' => [
'openy_demo_node_camp',
'openy_demo_node_camp_blog',
],
],
'blog' => [
'openy_demo_nblog' => [
'openy_demo_node_blog',
],
],
'news' => [
'openy_demo_nnews' => [
'openy_demo_node_news',
'openy_demo_news_landing',
'openy_demo_menu_link_footer_news',
],
],
'event' => [
'openy_demo_nevent' => [
'openy_demo_node_event',
'openy_demo_event_landing',
],
],
'facility' => [
'openy_demo_nfacility' => [
'openy_demo_node_facility',
],
],
'landing' => [
'openy_demo_nlanding' => [
'openy_demo_node_landing',
],
],
/*
'campaign' => [
'openy_demo_ncampaign' => [
'openy_demo_node_campaign_page',
'openy_demo_node_campaign',
],
],
'interstitial' => [
'openy_demo_ninterstitial' => [
'openy_demo_node_interstitial_page',
],
],
*/
'membership' => [
'openy_demo_nmbrshp' => [
'openy_demo_node_membership',
],
],
'programs' => [
'openy_demo_nprogram' => [
'openy_demo_node_program',
],
],
'categories' => [
'openy_demo_ncategory' => [
'openy_demo_node_program_subcategory',
],
],
'activities' => [
'openy_demo_nclass' => [
'openy_demo_node_activity'
]
],
'classes_01' => [
'openy_demo_nclass' => [
'openy_demo_node_class_01',
],
],
'classes_02' => [
'openy_demo_nclass' => [
'openy_demo_node_class_02',
],
],
'sessions_01' => [
'openy_demo_nsessions' => [
'openy_demo_node_session_01',
],
],
'sessions_02' => [
'openy_demo_nsessions' => [
'openy_demo_node_session_02',
],
],
'sessions_03' => [
'openy_demo_nsessions' => [
'openy_demo_node_session_03',
],
],
'sessions_04' => [
'openy_demo_nsessions' => [
'openy_demo_node_session_04',
],
],
'home_alt' => [
'openy_demo_nhome_alt' => [
'openy_demo_node_home_alt_landing',
],
],
'menus' => [
'openy_demo_menu_main' => [
'openy_demo_menu_link_main',
],
'openy_demo_menu_footer' => [
'openy_demo_menu_link_footer',
],
],
'webform' => [
'openy_demo_webform' => [
'openy_demo_webform_content',
],
],
];
return array_key_exists($key, $map) ? $map[$key] : [];
}
/**
* Create batch for content import.
*
* @param array $install_state
* Installation parameters.
*
* @return array
* Batch.
*/
function openy_import_content(array &$install_state) {
$module_operations = [];
$migrate_operations = [];
if (!empty($install_state['openy']['content']['webform'])) {
// Install webform feature - it's not handled as content migration.
openy_enable_module('openy_demo_webform');
unset($install_state['openy']['content']['webform']);
}
// Import GroupExPro classes. They are not handled as content migration.
$importGxp = !empty($install_state['openy']['content']['gxp']);
unset($install_state['openy']['content']['gxp']);
// Build required migrations operations arrays.
_openy_import_content_helper($module_operations, $migrate_operations, 'required');
// Build optional migrations operations arrays, only if at least one option
// has been selected.
if (!empty($install_state['openy']['content'])) {
_openy_import_content_helper($module_operations, $migrate_operations, 'optional');
}
// Add home_alt if landing is not included.
if (!in_array('landing', $install_state['openy']['content'])) {
$install_state['openy']['content'][] = 'home_alt';
}
if (in_array('programs', $install_state['openy']['content'])) {
$install_state['openy']['content'][] = 'categories';
$install_state['openy']['content'][] = 'activities';
$install_state['openy']['content'][] = 'classes_01';
$install_state['openy']['content'][] = 'classes_02';
$install_state['openy']['content'][] = 'sessions_01';
$install_state['openy']['content'][] = 'sessions_02';
$install_state['openy']['content'][] = 'sessions_03';
$install_state['openy']['content'][] = 'sessions_04';
$install_state['openy']['content'][] = 'interstitial';
}
// Campaign requires Landing.
if (in_array('campaign', $install_state['openy']['content']) && !in_array('landing', $install_state['openy']['content'])) {
$install_state['openy']['content'][] = 'landing';
}
// Build migrations operations arrays, for selected content.
foreach ($install_state['openy']['content'] as $content) {
_openy_import_content_helper($module_operations, $migrate_operations, $content);
}
// Add demo content Program Event Framework landing pages manually. Do it as
// so last step so menu items are in place.
$migrate_operations[] = ['openy_demo_nlanding_pef_pages', []];
if ($importGxp) {
openy_enable_module('openy_gxp');
$migrate_operations[] = ['openy_gxp_import_tc', []];
}
// Combine operations module enable before of migrations.
return ['operations' => array_merge($module_operations, $migrate_operations)];
}
/**
* Set the homepage whether from demo content or default one.
*/
function openy_set_frontpage(array &$install_state) {
// Set homepage by node id but checking it first by title only.
$query = \Drupal::entityQuery('node')
->condition('status', 1)
->condition('title', 'OpenY');
$nids = $query->execute();
$config_factory = Drupal::configFactory();
$config_factory->getEditable('system.site')->set('page.front', '/node/' . reset($nids))->save();
return ['operations' => []];
}
/**
* Fix broken paragraphs which for some reason weren't discovered.
*
* @see https://www.drupal.org/node/2889297
* @see https://www.drupal.org/node/2889298
*/
function openy_discover_broken_paragraphs(array &$install_state) {
/**
* Reset data for broken paragraphs using block fields from plugin module.
*
* @param array $tables
* @param string $plugin_id_field
* @param string $config_field
*/
$process_paragraphs = function (array $tables, $plugin_id_field, $config_field) {
foreach ($tables as $table) {
// Select all paragraphs that have "broken" as plugin_id.
$query = \Drupal::database()->select($table, 'ptable');
$query->fields('ptable');
$query->condition('ptable.' . $plugin_id_field, 'broken');
$broken_paragraphs = $query->execute()->fetchAll();
// Update to correct plugin_id based on data array.
foreach ($broken_paragraphs as $paragraph) {
$data = unserialize($paragraph->{$config_field});
$query = \Drupal::database()->update($table);
$query->fields([
$plugin_id_field => $data['id'],
]);
$query->condition('bundle', $paragraph->bundle);
$query->condition('entity_id', $paragraph->entity_id);
$query->condition('revision_id', $paragraph->revision_id);
$query->condition('langcode', $paragraph->langcode);
$query->execute();
}
}
};
$process_paragraphs([
'paragraph__field_prgf_block',
'paragraph_revision__field_prgf_block',
],
'field_prgf_block_plugin_id',
'field_prgf_block_plugin_configuration'
);
$process_paragraphs([
'paragraph__field_prgf_schedules_ref',
'paragraph_revision__field_prgf_schedules_ref',
],
'field_prgf_schedules_ref_plugin_id',
'field_prgf_schedules_ref_plugin_configuration'
);
}
/**
* Add Block configuration to Branch demo content Group Schedules paragraphs.
*
* @see openy_discover_broken_paragraphs().
*/
function openy_fix_configured_paragraph_blocks(array &$install_state) {
$tables = [
'paragraph__field_prgf_schedules_ref',
'paragraph_revision__field_prgf_schedules_ref',
];
foreach ($tables as $table) {
$query = \Drupal::database()
->select($table, 'ptable');
$query->fields('ptable');
$query->condition('ptable.bundle', 'group_schedules');
$query->join('node__field_content', 'content', 'content.field_content_target_id = ptable.entity_id');
$query->condition('content.bundle', 'branch');
$group_schedule_paragraphs = $query->execute()->fetchAll();
$location_ids = ['1036', '204', '203', '202'];
// Update to correct plugin_id based on data array.
foreach ($group_schedule_paragraphs as $paragraph) {
$data = unserialize($paragraph->field_prgf_schedules_ref_plugin_configuration);
$data['enabled_locations'] = array_pop($location_ids);
$data['label_display'] = 0;
$query = \Drupal::database()->update($table);
$query->fields([
'field_prgf_schedules_ref_plugin_configuration' => serialize($data),
]);
$query->condition('bundle', $paragraph->bundle);
$query->condition('entity_id', $paragraph->entity_id);
$query->condition('revision_id', $paragraph->revision_id);
$query->condition('langcode', $paragraph->langcode);
$query->execute();
}
}
}
/**
* Demo content import helper.
*
* @param array $module_operations
* List of module operations.
* @param array $migrate_operations
* List of migrate operations.
* @param string $key
* Key of the section in the mapping.
*/
function _openy_import_content_helper(array &$module_operations, array &$migrate_operations, $key) {
$modules = openy_demo_content_configs_map($key);
if (empty($modules)) {
return;
}
foreach ($modules as $key => $migrations) {
$module_operations[] = ['openy_enable_module', (array) $key];
foreach ($migrations as $migration) {
$migrate_operations[] = ['openy_import_migration', (array) $migration];
}
}
}
/**
* Enable module with demo content.
*
* @param string $module_name
* Module name.
*/
function openy_enable_module($module_name) {
/** @var \Drupal\Core\Extension\ModuleInstaller $service */
$service = \Drupal::service('module_installer');
$service->install([$module_name]);
}
/**
* Import single migration (with dependencies).
*
* @param string $migration_id
* Migration ID.
*/
function openy_import_migration($migration_id) {
$importer = \Drupal::service('openy_migrate.importer');
$importer->import($migration_id);
}
/**
* Implements hook_form_FORM_ID_alter.
*
* This will change the description text for the site slogan field.
*
* @param $form
* @param \Drupal\Core\Form\FormStateInterface $form_state
* @param $form_id
*/
function openy_form_system_site_information_settings_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {
$form['site_information']['site_slogan']['#description'] = t("This will display your association name in the header as per Y USA brand guidelines. Try to use less than 27 characters. The text may get cut off on smaller devices.");
}
/**
* Implements hook_preprocess_block().
*/
function openy_preprocess_block(&$variables) {
$variables['base_path'] = base_path();
// Prevent some blocks from caching
$preventCacheBlocks = [
'system_breadcrumb_block',
];
if (in_array($variables['plugin_id'], $preventCacheBlocks)) {
$variables['#cache']['max-age'] = 0;
}
}
function openy_form_system_theme_settings_alter(&$form, FormStateInterface $form_state, $form_id) {
if (isset($form['css_editor'])) {
// Add short manual how to use CSS Editor inside the theme.
$types = \Drupal::entityTypeManager()->getStorage('node_type')->loadMultiple();
$css_node_selectors = array_map(function ($type) {
return str_replace('_', '-', $type);
}, array_keys($types));
$css_editor_info = [
'#prefix' => '<div class="description">',
'#markup' => t('In order to change CSS on each particular page you
should use the following selectors:<br/>
- .page-node-type-{node type};<br/>
- .node-id-{node ID};<br/>
- .path-frontpage.<br/><br/>
The existing node types are: ' . implode($css_node_selectors, ', ') .'.
'),
'#suffix' => '</div>'
];
$form['css_editor']['css_editor_info'] = $css_editor_info;
}
}
function openy_help($route_name, RouteMatchInterface $route_match) {
switch ($route_name) {
case 'system.theme_settings_theme':
$theme = $route_match->getParameter('theme');
$config = \Drupal::configFactory()->getEditable('css_editor.theme.' . $theme);
if ($config->get('enabled')) {
return '<p>' . t('If you need to change CSS on some pages independently, you may use Custom CSS configuration.') . '</p>';
}
else {
return '<p>' . t('If you need to change CSS on some pages independently, you should enable Custom CSS functionality.') . '</p>';
}
break;
}
}