This repository has been archived by the owner on Jul 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 111
/
openy.profile
796 lines (741 loc) · 25 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
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
<?php
/**
* @file
* Defines the Open Y Profile install screen by modifying the install form.
*/
use Drupal\openy\Form\ConfigureProfileForm;
use Drupal\openy\Form\ContentSelectForm;
use Drupal\openy\Form\SearchSelectForm;
use Drupal\openy\Form\SearchSolrForm;
use Drupal\openy\Form\TermsOfUseForm;
use Drupal\openy\Form\ThemeSelectForm;
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(&$install_state) {
return [
'openy_terms_of_use' => [
'display_name' => t('Terms and Conditions'),
'display' => TRUE,
'run' => INSTALL_TASK_RUN_IF_REACHED
],
'openy_select_search' => [
'display_name' => t('Select search service'),
'display' => TRUE,
'type' => 'form',
'function' => SearchSelectForm::class,
],
'openy_install_search' => [
'display_name' => t('Install search'),
'type' => 'batch',
],
'openy_solr_search' => [
'display_name' => t('Configure Solr Search'),
'display' => TRUE,
'type' => 'form',
'function' => SearchSolrForm::class,
],
'openy_google_search' => [
'type' => 'batch',
],
'openy_select_features' => [
'display_name' => t('Select installation type'),
'display' => TRUE,
'type' => 'form',
'function' => ConfigureProfileForm::class,
],
'openy_install_features' => [
'type' => 'batch',
],
'openy_select_theme' => [
'display_name' => t('Select theme'),
'display' => TRUE,
'type' => 'form',
'function' => ThemeSelectForm::class,
],
'openy_install_theme' => [
'type' => 'batch',
],
'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',
],
'openy_install_finish' => [
'type' => 'batch',
],
'openy_terms_and_condition_db_save' => [
'display' => FALSE,
],
];
}
/**
* Create Google Translate block content.
* Block already added from Open Y 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',
'openy_carnation' => '32fa8958-20d7-41e0-9e7c-a5768bf6dfac',
];
/** @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 installation presets to demo content.
$map = [
'core' => [
'openy_demo_taxonomy',
'openy_demo_tcolor',
],
'complete' => [
'openy_demo_nalert',
'openy_demo_nbranch',
'openy_demo_ncamp',
'openy_demo_nblog',
'openy_demo_nnews',
'openy_demo_nevent',
'openy_demo_nfacility',
'openy_demo_nlanding',
'openy_demo_nmbrshp',
'openy_demo_nprogram',
'openy_demo_ncategory',
'openy_demo_nclass',
'openy_demo_nsessions',
'openy_demo_menu',
'openy_demo_menu_main',
'openy_demo_menu_footer',
'openy_demo_webform',
'openy_demo_ahb',
'openy_demo_nsocial_post',
'openy_demo_tarea',
'openy_demo_tblog',
'openy_demo_tnews',
'openy_demo_tfacility',
'openy_demo_tamenities',
'openy_demo_bmicrosites_menu',
'openy_demo_addthis',
'openy_demo_bsimple',
'openy_demo_bamenities',
'openy_demo_tfitness',
],
'standard' => [
'openy_demo_nalert',
'openy_demo_nlanding',
'openy_demo_menu',
'openy_demo_nnews',
'openy_demo_menu_main',
'openy_demo_menu_footer',
'openy_demo_webform',
'openy_demo_ahb',
'openy_demo_tcolor',
'openy_demo_tamenities',
'openy_demo_taxonomy',
],
'extended' => [
'openy_demo_nalert',
'openy_demo_nbranch',
'openy_demo_nevent',
'openy_demo_nnews',
'openy_demo_nlanding',
'openy_demo_nmbrshp',
'openy_demo_menu',
'openy_demo_menu_main',
'openy_demo_menu_footer',
'openy_demo_webform',
'openy_demo_ahb',
'openy_demo_tnews',
'openy_demo_tcolor',
'openy_demo_tarea',
'openy_demo_tamenities',
'openy_demo_addthis',
'openy_demo_bsimple',
'openy_demo_bamenities',
'openy_demo_taxonomy',
],
];
return array_key_exists($key, $map) ? $map[$key] : [];
}
/**
* Create batch for enabling features.
*
* @param array $install_state
* Installation parameters.
*
* @return array
* Batch.
*/
function openy_install_features(array &$install_state) {
$module_operations = [];
$preset = $install_state['openy']['preset'];
\Drupal::state()->set('openy_preset', $preset);
$modules = ConfigureProfileForm::getModulesToInstallWithDependencies($preset);
foreach ($modules as $module) {
$module_operations[] = ['openy_enable_module', (array) $module];
}
return ['operations' => $module_operations];
}
/**
* Create batch for installing search.
*
* @param array $install_state
* Installation parameters.
*
* @return array
* Batch.
*/
function openy_install_search(array &$install_state) {
$state = \Drupal::state();
$module = $install_state['openy']['search']['service'];
$files = \Drupal::service('extension.list.module')->getList();
if (isset($install_state['openy']['search']['search_api_server'])) {
$server = $install_state['openy']['search']['search_api_server'];
if ($module == 'openy_search_api' && $server == 'solr') {
$state->set('openy_show_solr_config', '1');
}
};
if (isset($install_state['openy']['search']['google_search_engine_id'])) {
$state->set('google_search_engine_id', $install_state['openy']['search']['google_search_engine_id']);
};
if ($files[$module]->requires) {
$modules = array_merge(array_keys($files[$module]->requires), (array) $module);
}
foreach ($modules as $module) {
$module_operations[] = ['openy_enable_module', (array) $module];
}
// todo: install search_api_solr_legacy.
$module_operations[] = ['openy_enable_search_api_solr_legacy', []];
return ['operations' => $module_operations];
}
/**
* Create batch for write google custom search id to configuration.
*
* @param array $install_state
* Installation parameters.
*/
function openy_google_search(array &$install_state) {
// Set Google Custom Search Engine ID.
if (!empty(\Drupal::state()->get('google_search_engine_id'))) {
$config_factory = \Drupal::configFactory();
$config = $config_factory->getEditable('openy_google_search.settings');
$config->set('google_engine_id', \Drupal::state()->get('google_search_engine_id'));
$config->save();
}
}
/**
* Create batch for install and set default theme.
*
* @param array $install_state
* Installation parameters.
*
* @return array
* Batch.
*/
function openy_install_theme(array &$install_state) {
// Import blocks needed for themes.
$module_operations[] = ['openy_enable_module', (array) 'openy_demo_bfooter'];
$migrate_operations[] = ['openy_import_migration', (array) 'openy_demo_block_content_footer'];
$uninstall_operations[] = ['openy_uninstall_module', (array) 'openy_demo_bfooter'];
$theme = $install_state['openy']['theme'];
if (function_exists( 'drush_print')) {
drush_print(dt('Theme: %theme', ['%theme' => $theme]));
}
$config_factory = Drupal::configFactory();
// Set the default theme.
$config_factory
->getEditable('system.theme')
->set('default', $theme)
->save(TRUE);
$theme_operations[] = ['openy_enable_theme', (array) $theme];
return ['operations' => array_merge($module_operations, $migrate_operations, $uninstall_operations, $theme_operations)];
}
/**
* 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 = [];
$uninstall_operations = [];
$preset = \Drupal::state()->get('openy_preset') ?: 'complete';
if (function_exists('drush_print')) {
drush_print(dt('Preset: %preset', ['%preset' => $preset]));
}
$preset_tags = [
'standard' => 'openy_standard_installation',
'extended' => 'openy_extended_installation',
'complete' => 'openy_complete_installation',
];
$migration_tag = $preset_tags[$preset];
// Add core demo content.
_openy_import_content_helper($module_operations, 'core', 'enable');
$migrate_operations[] = ['openy_import_migration', ['openy_core_installation']];
if ($install_state['openy']['content']) {
// If option has been selected build demo modules installation operations array.
_openy_import_content_helper($module_operations, $preset, 'enable');
// Add migration import by tag to migration operations array.
$migrate_operations[] = ['openy_import_migration', (array) $migration_tag];
if ($preset == 'complete') {
// Add demo content Program Event Framework landing pages manually.
// Do it as the last step so menu items are in place.
$migrate_operations[] = ['openy_demo_nlanding_pef_pages', []];
// Add demo content Activity Finder landing pages manually.
// Do it as the last step so menu items are in place.
$migrate_operations[] = ['openy_demo_nlanding_af_pages', []];
}
// Build demo modules uninstall array to disable migrations with demo content.
_openy_import_content_helper($uninstall_operations, $preset, 'uninstall');
if (function_exists('drush_print')) {
drush_print(dt('Demo content enabled'));
}
}
else {
// Add homepage alternative if demo content is not enabled.
$module_operations[] = ['openy_enable_module', (array) 'openy_demo_nhome_alt'];
$migrate_operations[] = ['openy_import_migration', (array) 'openy_demo_home_alt'];
$uninstall_operations[] = ['openy_uninstall_module', (array) 'openy_demo_home_alt'];
}
// Uninstall core demo content modules.
_openy_import_content_helper($uninstall_operations, 'core', 'uninstall');
// Combine operations module enable before of migrations.
return ['operations' => array_merge($module_operations, $migrate_operations, $uninstall_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', 'Open Y');
$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) {
if (!\Drupal::database()->schema()->tableExists($table)) {
continue;
}
// 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'
);
$process_paragraphs([
'paragraph__field_prgf_location_finder',
'paragraph_revision__field_prgf_location_finder',
],
'field_prgf_location_finder_plugin_id',
'field_prgf_location_finder_plugin_configuration'
);
$process_paragraphs([
'paragraph__field_prgf_location_finder',
'paragraph_revision__field_prgf_location_finder',
],
'field_prgf_location_finder_plugin_id',
'field_prgf_location_finder_plugin_configuration'
);
$process_paragraphs([
'paragraph__field_branch_contacts_info',
'paragraph_revision__field_branch_contacts_info',
],
'field_branch_contacts_info_plugin_id',
'field_branch_contacts_info_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) {
if (!\Drupal::database()->schema()->tableExists($table)) {
continue;
}
$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();
}
}
}
/**
* Run final Open Y profile install procedures.
*/
function openy_install_finish(array &$install_state) {
// Rerun install all available optional config that appeared after
// installation of Open Y modules and themes.
// We need to run this because during a drupal installation
// optional configuration is installed only once at the
// end of the core installation process.
// \Drupal::service('config.installer')->installOptionalConfig();
// Disable the default 'frontpage' Views configuration since it is unused. Due to the fact that this Views
// configuration is stored in the optional folder there is no way to disable it before optional configs are installed.
$view = \Drupal::entityTypeManager()->getStorage('view')->load('frontpage');
if ($view) {
$view->disable();
$view->save();
}
}
/**
* Demo content import helper.
*
* @param array $module_operations
* List of module operations.
* @param string $key
* Key of the section in the mapping.
* @param string $action
* Action for demo content modules: enable|uninstall.
*/
function _openy_import_content_helper(array &$module_operations, string $key, string $action) {
$modules = openy_demo_content_configs_map($key);
if (empty($modules)) {
return;
}
foreach ($modules as $module) {
$module_operations[] = ['openy_' . $action . '_module', (array) $module];
}
}
/**
* Enable module.
*
* @param string $module_name
* Module name.
*
* @throws \Drupal\Core\Extension\MissingDependencyException
*/
function openy_enable_module($module_name) {
/** @var \Drupal\Core\Extension\ModuleInstaller $service */
$service = \Drupal::service('module_installer');
$service->install([$module_name]);
}
/**
* Enable theme.
*
* @param string $theme_name
* Module name.
*
* @throws \Drupal\Core\Extension\ExtensionNameLengthException
*/
function openy_enable_theme($theme_name) {
/** @var \Drupal\Core\Extension\ThemeInstaller $service */
$service = \Drupal::service('theme_installer');
$service->install([$theme_name]);
}
/**
* Uninstall module.
*
* @param string $module_name
* Module name.
*/
function openy_uninstall_module($module_name) {
/** @var \Drupal\Core\Extension\ModuleInstaller $service */
$service = \Drupal::service('module_installer');
$service->uninstall([$module_name]);
}
/**
* Import migrations with specified tag.
*
* @param string $migration_tag
* Migration tag.
*/
function openy_import_migration($migration_tag) {
$importer = \Drupal::service('openy_migrate.importer');
$importer->importByTag($migration_tag);
}
/**
* 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;
}
}
/**
* Implements hook_form_FORM_ID_alter.
*
* Add description how to use CSS Editor on the theme configuration page.
*/
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;
}
}
/**
* Implements hook_help().
*
* Add description how to use CSS Editor to help.
*/
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;
}
}
/**
* Implements hook_install_tasks_alter().
*/
function openy_install_tasks_alter(&$tasks, &$install_state) {
$new_tasks = [];
// Looks like we don't have another way to put T&C on the first page.
$new_tasks['openy_terms_of_use'] = $tasks['openy_terms_of_use'];
$tasks = array_merge($new_tasks, $tasks);
// Remove 3rd party services installation task for standard preset.
if (!empty(\Drupal::state()->get('openy_preset')) &&
\Drupal::state()->get('openy_preset') == 'standard' &&
isset($tasks["openy_third_party_services"])) {
unset($tasks["openy_third_party_services"]);
}
// Remove Solr configure installation task for non search_api sorl service.
if (!\Drupal::state()->get('openy_show_solr_config')) {
unset($tasks["openy_solr_search"]);
}
if (isset($install_state['openy']['search']['service']) &&
$install_state['openy']['search']['service'] == 'none' ) {
unset($tasks["openy_install_search"]);
unset($tasks["openy_solr_search"]);
}
}
/**
* Displays the Terms and Conditions form.
*
* @param $install_state
* An array of information about the current installation state. The T&C flag
* will be added here.
*
* @return mixed
* A T&C form if T&C has not been accepted.
*/
function openy_terms_of_use(&$install_state) {
// Open Y classes are not included yet on the first installation page,
// because profile is not installed.
// That's why we should include T&C form manually.
if (!class_exists('\Drupal\openy\Form\TermsOfUseForm')) {
$path = drupal_get_path('profile', 'openy');
require_once $path . '/src/Form/TermsOfUseForm.php';
}
if (!empty($install_state['parameters']['terms_and_conditions'])) {
return;
}
if ($install_state['interactive']) {
return install_get_form('Drupal\openy\Form\TermsOfUseForm', $install_state);
}
}
/**
* Saves T&C accepted version to db. We can't do it on the first step,
* because db is not configured yet.
*
* @param $install_state
* An array of information about the current installation state.
*/
function openy_terms_and_condition_db_save(&$install_state) {
$config_factory = \Drupal::configFactory();
$config = $config_factory->getEditable('openy.terms_and_conditions.schema');
$config->set('version', TermsOfUseForm::TERMS_OF_USE_VERSION);
$config->set('accepted_version', time());
$config->save();
}
/**
* Enables Search API Solr Legacy if Solr 4.x backend is detected.
*
* @return bool
* TRUE if the legacy module was enabled.
*/
function openy_enable_search_api_solr_legacy() {
$moduleHandler = \Drupal::service('module_handler');
if (!$moduleHandler->moduleExists('search_api_solr')) {
return;
}
$storage = \Drupal::entityTypeManager()
->getStorage('search_api_server');
$search_api_servers = $storage->getQuery()->execute();
foreach ($search_api_servers as $search_api_server_id) {
$search_api_server = $storage->load($search_api_server_id);
if ($search_api_server->getBackendId() !== 'search_api_solr') {
continue;
}
if (!$search_api_server->hasValidBackend()) {
continue;
}
$connector = $search_api_server->getBackend()->getSolrConnector();
$solr_version = $connector->getSolrVersion();
$solr_version_forced = $connector->getSolrVersion(TRUE);
if (preg_match('/[45]{1}\.[0-9]+\.[0-9]+/', $solr_version)
|| preg_match('/[45]{1}\.[0-9]+\.[0-9]+/', $solr_version_forced)) {
// Solr 4.x or 5.x found, install the Search API Solr Legacy module.
\Drupal::service('module_installer')->install(['search_api_solr_legacy']);
return TRUE;
}
}
return FALSE;
}