forked from dpc-sdp/tide_core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tide_core.install
1242 lines (1142 loc) · 38.9 KB
/
tide_core.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
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
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* @file
* Installation functions for Tide Core.
*/
use Drupal\filter\Entity\FilterFormat;
use Drupal\paragraphs\Entity\ParagraphsType;
use Drupal\pathauto\Entity\PathautoPattern;
use Drupal\taxonomy\Entity\Term;
use Drupal\user\Entity\User;
use Drupal\workflows\Entity\Workflow;
use Drupal\Core\Config\FileStorage;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\field\Entity\FieldConfig;
use Drupal\scheduled_transitions\ScheduledTransitionsPermissions;
use Drupal\user\Entity\Role;
use Drupal\user\UserInterface;
use Drupal\node\Entity\NodeType;
use Drupal\views\Entity\View;
/**
* Implements hook_install().
*/
function tide_core_install() {
// Assign user 1 the "administrator" role.
$user = User::load(1);
$user->roles[] = 'administrator';
$user->save();
// Override default Plain Text format from Core.
try {
$plain_text = FilterFormat::load('plain_text');
if ($plain_text) {
module_load_include('inc', 'tide_core', 'includes/helpers');
$config_location = [drupal_get_path('module', 'tide_core') . '/config/optional'];
_tide_import_single_config('filter.format.plain_text', $config_location);
}
}
catch (Exception $exception) {
watchdog_exception('tide_core', $exception);
}
// Don't do anything else during config sync.
if (\Drupal::isConfigSyncing()) {
return;
}
// Restrict user registration to admin role creation.
\Drupal::configFactory()
->getEditable('user.settings')
->set('register', USER_REGISTER_ADMINISTRATORS_ONLY)
->save(TRUE);
// Creates terms for Topic vocabulary.
_tide_core_create_topic_terms();
// Update default Editorial workflow of Content Moderation.
_tide_core_update_editorial_workflow();
$excluded = [
'tide_core_update_8015',
'tide_core_update_8038',
'tide_core_update_8043',
];
$functions = get_defined_functions();
foreach ($functions['user'] as $function) {
if (strpos($function, 'tide_core_update_') === 0) {
// We don't want the tide_core_update_8015 to run during the CI.
if (in_array($function, $excluded)) {
continue;
}
call_user_func($function);
}
}
}
/**
* Creates terms for Topic vocabulary.
*/
function _tide_core_create_topic_terms() {
$vid = 'topic';
$terms = [
'Arts',
'Business',
'Education',
];
foreach ($terms as $term) {
Term::create([
'name' => $term,
'vid' => $vid,
'parent' => [],
])->save();
}
}
/**
* Update default Editorial workflow of Content Moderation.
*/
function _tide_core_update_editorial_workflow() {
$editorial_workflow = Workflow::load('editorial');
if ($editorial_workflow) {
$type_settings = [
'states' => [
'draft' => [
'label' => 'Draft',
'published' => FALSE,
'default_revision' => FALSE,
'weight' => -10,
],
'needs_review' => [
'published' => FALSE,
'default_revision' => FALSE,
'label' => 'Needs Review',
'weight' => -9,
],
'published' => [
'label' => 'Published',
'published' => TRUE,
'default_revision' => TRUE,
'weight' => -8,
],
'archived' => [
'label' => 'Archived',
'weight' => -7,
'published' => FALSE,
'default_revision' => TRUE,
],
'archive_pending' => [
'label' => 'Archive pending',
'published' => FALSE,
'default_revision' => FALSE,
'weight' => -6,
],
],
'transitions' => [
'create_archive_pending' => [
'label' => 'Archive pending',
'from' => ['draft', 'published', 'needs_review'],
'to' => 'archive_pending',
'weight' => -11,
],
'create_new_draft' => [
'label' => 'Create New Draft',
'from' => ['draft', 'published', 'archive_pending'],
'to' => 'draft',
'weight' => -10,
],
'needs_review' => [
'label' => 'Needs Review',
'from' => ['draft', 'archive_pending'],
'to' => 'needs_review',
'weight' => -9,
],
'needs_review_draft' => [
'label' => 'Send back to Draft',
'from' => ['needs_review'],
'to' => 'draft',
'weight' => -8,
],
'publish' => [
'label' => 'Publish',
'from' => ['draft', 'needs_review', 'published'],
'to' => 'published',
'weight' => -7,
],
'archive' => [
'label' => 'Archive',
'from' => ['published'],
'to' => 'archived',
'weight' => -6,
],
'archived_draft' => [
'label' => 'Restore to Draft',
'from' => ['archived'],
'to' => 'draft',
'weight' => -5,
],
'archived_published' => [
'label' => 'Restore',
'from' => ['archived', 'archive_pending'],
'to' => 'published',
'weight' => -4,
],
],
'entity_types' => [],
];
$editorial_workflow->set('type_settings', $type_settings);
$editorial_workflow->save();
}
}
/**
* Implements hook_update_dependencies().
*/
function tide_core_update_dependencies() {
$dependencies['tide_core'][8007] = ['system' => 8805];
$dependencies['tide_core'][8016] = ['system' => 8805];
return $dependencies;
}
/**
* Add field storage for Show Related Content and Show Social Sharing.
*/
function tide_core_update_8001() {
module_load_include('inc', 'tide_core', 'includes/helpers');
$config_location = [drupal_get_path('module', 'tide_core') . '/config/install'];
_tide_import_single_config('field.storage.node.field_show_related_content', $config_location);
_tide_import_single_config('field.storage.node.field_show_social_sharing', $config_location);
}
/**
* Add field storage for Featured Image.
*/
function tide_core_update_8002() {
module_load_include('inc', 'tide_core', 'includes/helpers');
$config_location = [drupal_get_path('module', 'tide_core') . '/config/install'];
_tide_import_single_config('field.storage.node.field_featured_image', $config_location);
}
/**
* Enable Pathauto with default config.
*/
function tide_core_update_8003() {
/** @var \Drupal\Core\Extension\ModuleInstallerInterface $module_installer */
$module_installer = \Drupal::service('module_installer');
$module_installer->install(['pathauto']);
module_load_include('inc', 'tide_core', 'includes/helpers');
$config_location = [drupal_get_path('module', 'tide_core') . '/config/optional'];
_tide_import_single_config('pathauto.pattern.content_title', $config_location);
}
/**
* Import ClamAV default config.
*/
function tide_core_update_8004() {
module_load_include('inc', 'tide_core', 'includes/helpers');
$config_location = [drupal_get_path('module', 'tide_core') . '/config/optional'];
_tide_import_single_config('clamav.settings', $config_location);
}
/**
* Enable PRLP with default config.
*/
function tide_core_update_8005() {
/** @var \Drupal\Core\Extension\ModuleInstallerInterface $module_installer */
$module_installer = \Drupal::service('module_installer');
$module_installer->install(['prlp']);
module_load_include('inc', 'tide_core', 'includes/helpers');
$config_location = [drupal_get_path('module', 'tide_core') . '/config/optional'];
_tide_import_single_config('prlp.settings', $config_location);
}
/**
* Enable the blockquote template available to all Node types.
*/
function tide_core_update_8006() {
if ($wysiwyg_template = \Drupal::entityTypeManager()
->getStorage('wysiwyg_template')
->load('blockquote')) {
if (count($wysiwyg_template->getNodeTypes()) > 0) {
$wysiwyg_template->set('node_types', [])->save();
}
}
}
/**
* Delete and uninstall all scheduled_update entities.
*/
function tide_core_update_8007() {
if (\Drupal::moduleHandler()->moduleExists('scheduled_updates')) {
// Delete content entities.
$scheduled_updates = \Drupal::entityTypeManager()
->getStorage('scheduled_update')
->loadMultiple();
foreach ($scheduled_updates as $scheduled_update) {
$scheduled_update->delete();
}
// Delete configs.
$scheduled_fields = ['scheduled_archiving', 'scheduled_publishing'];
foreach ($scheduled_fields as $scheduled_field) {
$field_storage = FieldStorageConfig::loadByName('node', $scheduled_field);
if (!empty($field_storage)) {
$bundles = $field_storage->getBundles();
foreach ($bundles as $bundle) {
$field = FieldConfig::loadByName('node', $bundle, $scheduled_field);
if (!empty($field)) {
$field->delete();
}
}
field_purge_batch(10);
}
}
}
}
/**
* Change %uid token to %user in login redirect URL of PRLP settings.
*/
function tide_core_update_8008() {
// Issue https://www.drupal.org/project/prlp/issues/2785087 was fixed.
$config = \Drupal::configFactory()->getEditable('prlp.settings');
$login_destination = $config->get('login_destination');
if (!empty($login_destination) && strpos($login_destination, '%uid') !== FALSE) {
$login_destination = str_replace('%uid', '%user', $login_destination);
$config->set('login_destination', $login_destination)->save();
}
}
/**
* Create pathauto pattern for Taxonomy terms.
*/
function tide_core_update_8009() {
if (!PathautoPattern::load('taxonomy_term')) {
$pattern = PathautoPattern::create([
'id' => 'taxonomy_term',
'label' => 'Taxonomy term',
'type' => 'canonical_entities:taxonomy_term',
'pattern' => '[term:vocabulary:machine-name]/[term:name]',
'weight' => 0,
]);
$pattern->save();
}
$batch = [
'title' => 'Bulk updating Term URL aliases',
'operations' => [
['Drupal\pathauto\Form\PathautoBulkUpdateForm::batchStart', []],
[
'Drupal\pathauto\Form\PathautoBulkUpdateForm::batchProcess',
[
'canonical_entities:taxonomy_term',
'all',
],
],
],
'finished' => 'Drupal\pathauto\Form\PathautoBulkUpdateForm::batchFinished',
'progressive' => FALSE,
];
batch_set($batch);
batch_process();
}
/**
* Enable scheduled_transitions module.
*/
function tide_core_update_8010() {
if (!\Drupal::moduleHandler()->moduleExists('scheduled_transitions')) {
$module_installer = \Drupal::service('module_installer');
$module_installer->install(['scheduled_transitions']);
}
}
/**
* Update og:image metatag for node.
*/
function tide_core_update_8011() {
$metatag = \Drupal::configFactory()->getEditable('metatag.metatag_defaults.node');
$og_image = $metatag->get('tags.og_image');
if (!$og_image) {
$metatag->set('tags.og_image', '[node:field_featured_image:entity:field_media_image:entity:url]')
->save();
}
}
/**
* Imports default permissions to approver and site_admin.
*/
function tide_core_update_8012() {
$roles = ['approver', 'site_admin'];
$node_types = \Drupal::entityTypeManager()
->getStorage('node_type')
->loadMultiple();
foreach ($roles as $role) {
$permissions = [];
foreach ($node_types as $type => $details) {
$permissions[] = ScheduledTransitionsPermissions::viewScheduledTransitionsPermission('node', $type);
$permissions[] = ScheduledTransitionsPermissions::addScheduledTransitionsPermission('node', $type);
}
$permissions[] = 'view all scheduled transitions';
user_role_grant_permissions(Role::load($role)->id(), $permissions);
}
}
/**
* Fix permissions for Previewers.
*/
function tide_core_update_8013() {
$role = Role::load('previewer');
if ($role) {
$role->grantPermission('view all revisions');
$role->grantPermission('view any unpublished content');
$role->grantPermission('view latest version');
$role->save();
}
}
/**
* Enable link_field_autocomplete_filter module.
*/
function tide_core_update_8014() {
if (!\Drupal::moduleHandler()->moduleExists('link_field_autocomplete_filter')) {
$module_installer = \Drupal::service('module_installer');
$module_installer->install(['link_field_autocomplete_filter']);
}
}
/**
* ClamAV configuration is updated to use central service.
*/
function tide_core_update_8015() {
if (\Drupal::moduleHandler()->moduleExists('clamav')) {
$config_factory = \Drupal::configFactory();
$config = $config_factory->getEditable('clamav.settings');
if ($config->isNew()) {
return;
}
$config->set('scan_mode', 0);
$config->set('mode_daemon_tcpip.hostname', 'clamav.sdp-central-clamav-master.svc.cluster.local');
$config->save();
}
}
/**
* Fix permissions for to access video entity browser.
*/
function tide_core_update_8016() {
$role = Role::load('approver');
if ($role) {
$role->grantPermission('access tide_embedded_video_browser entity browser pages');
$role->save();
}
$role = Role::load('editor');
if ($role) {
$role->grantPermission('access tide_embedded_video_browser entity browser pages');
$role->save();
}
$role = Role::load('site_admin');
if ($role) {
$role->grantPermission('access tide_embedded_video_browser entity browser pages');
$role->save();
}
}
/**
* Uninstall Scheduled Update modules.
*/
function tide_core_update_8017() {
$modules = [
'scheduled_updates',
'content_moderation_scheduled_updates',
];
$module_installer = \Drupal::service('module_installer');
$module_installer->uninstall($modules);
}
/**
* Update Scheduled Transitions View.
*/
function tide_core_update_8018() {
$title_fields = [
'label',
'display.default.display_options.title',
];
$config_factory = \Drupal::configFactory();
$config = $config_factory->getEditable('views.view.scheduled_transitions');
if ($config->isNew()) {
return;
}
// Update field labels/titles.
foreach ($title_fields as $field) {
$config->set($field, 'Scheduled update list');
}
// Update empty View results.
$config->set('display.default.display_options.empty.area.content.value', 'There are no scheduled updates yet.');
$config->save();
}
/**
* Update workflow to add archive pending SDPA-3781.
*/
function tide_core_update_8019() {
$config_factory = \Drupal::configFactory();
// Updating the workflow states & transitions.
$base_states = 'type_settings.states.';
$base_transitions = 'type_settings.transitions.';
$config = $config_factory->getEditable('workflows.workflow.editorial');
if (!$config->isNew()) {
$from_fields = [
'archive.from',
'archived_published.from',
'create_new_draft.from',
'needs_review.from',
];
foreach ($from_fields as $field) {
$form_value = [];
$form_value = $config->get($base_transitions . $field);
$form_value[] = 'archive_pending';
$config->set($base_transitions . $field, $form_value);
}
$config->set($base_states . 'archive_pending', [
'label' => 'Archive pending',
'published' => FALSE,
'default_revision' => FALSE,
'weight' => -6,
]);
$config->set($base_transitions . 'archive_pending', [
'label' => 'Archive pending',
'from' => [
'draft',
'published',
'needs_review',
],
'to' => 'archive_pending',
'weight' => -11,
]);
$config->save();
}
// Updating the tide_workflow_notification.
$notification_status = [
'draft_needs_review',
'draft_published',
'needs_review_draft',
'needs_review_published',
'published_archived',
];
$current_string = ['([node:url])', '(https://www.vic.gov.au/how-publish-content-vicgovau).'];
$replacement_string = [' - [node:url]', ' https://www.vic.gov.au/how-publish-content-vicgovau'];
$notification_fields = [
'draft_archive_pending',
'needs_review_archive_pending',
'published_archive_pending',
'archive_pending_archived',
];
if (\Drupal::moduleHandler()->moduleExists('tide_workflow_notification')) {
$config_notification = $config_factory->getEditable('tide_workflow_notification.settings');
if (!$config_notification->isNew()) {
// Update existing email template to fix link issue SDPSUP-1309.
foreach ($notification_status as $status) {
$current_status_message = $config_notification->get()['notifications'][$status]['message'];
$updated_status_message = str_replace($current_string,
$replacement_string, $current_status_message);
$config_notification->set('notifications.' . $status . '.message',
$updated_status_message);
}
// Add new email templates SDPA-3781.
foreach ($notification_fields as $field) {
$status = '';
if ($field == 'draft_archive_pending') {
$status = 'Draft';
}
if ($field == 'needs_review_archive_pending') {
$status = 'Needs Review';
}
if ($field == 'published_archive_pending') {
$status = 'Published';
}
$common_message = "Hi, [workflow-notification:recipient:display-name],\n\nThe status of the web content [node:title] - [node:url] has changed from " . $status . " to Archive pending.\n\nRemember to remove all menu links and navigation links to the page as well.\n\nNeed help? Read about workflow and roles https://www.vic.gov.au/publishing-workflow-Drupal-CMS\n";
$archive_pending_message = "Hi [workflow-notification:recipient:display-name],\n\nThe status of your web content at [node:title] - [node:url] has changed from Archive pending to Archived. This is because:\n• your approver approved your request to archive it\n• the content had a scheduled archive date\n\nWhen a page is archived, it is no longer available to view on the internet, but SDP CMS users can still find it. If you have reason to make sure noone can access a page, you should request to have the content deleted from the CMS.\n\nNeed help? Read about workflow and roles https://www.vic.gov.au/publishing-workflow-Drupal-CMS\n";
$config_notification->set('notifications.' . $field, [
'enabled' => 1,
'subject' => ($field !== 'archive_pending_archived') ? 'Archive of web content required: [node:title]' : 'Your web content has been archived: [node:title]',
'message' => ($field !== 'archive_pending_archived') ? $common_message : $archive_pending_message,
]);
}
$config_notification->save();
}
}
// Add required permissions.
$role = Role::load('editor');
if ($role) {
$role->grantPermission('use editorial transition archive_pending');
$role->save();
}
$role = Role::load('site_admin');
if ($role) {
$role->grantPermission('use editorial transition archive_pending');
$role->save();
}
}
/**
* Disable moderated_content view.
*/
function tide_core_update_8020() {
$view = \Drupal::entityTypeManager()->getStorage('view')->load('moderated_content');
if ($view) {
$view->setStatus(FALSE)->save();
}
}
/**
* Import tide_core_moderated_content_filters.
*/
function tide_core_update_8021() {
$view = 'views.view.tide_core_moderated_content_filters';
$config_path = drupal_get_path('module', 'tide_core') . '/config/install';
$source = new FileStorage($config_path);
$config_storage = \Drupal::service('config.storage');
$config_storage->write($view, $source->read($view));
}
/**
* Update accordion name and content fields to be mandatory.
*/
function tide_core_update_8022() {
$config_factory = \Drupal::configFactory();
$fields = [
'field.field.paragraph.accordion_content.field_paragraph_accordion_name',
'field.field.paragraph.accordion_content.field_paragraph_accordion_body',
];
foreach ($fields as $field) {
$config = $config_factory->getEditable($field);
if ($config->isNew()) {
continue;
}
$config->set('required', TRUE);
$config->save();
}
}
/**
* Changes the order of transitions list.
*/
function tide_core_update_8023() {
$order = [
'Create New Draft',
'Needs Review',
'Send back to Draft',
'Publish',
'Archive pending',
'Archive',
'Restore to Draft',
'Published',
];
$editorial_workflow = Workflow::load('editorial');
$type_settings = $editorial_workflow->get('type_settings');
if (isset($type_settings['transitions']) && !empty($type_settings['transitions'])) {
$keys = array_flip($order);
foreach ($keys as $label => $key) {
foreach ($type_settings['transitions'] as &$transition) {
if ($label == $transition['label']) {
$transition['weight'] = $key;
continue;
}
}
}
$editorial_workflow->set('type_settings', $type_settings);
$editorial_workflow->save();
}
}
/**
* Clean up cloudflare module.
*/
function tide_core_update_8024() {
$module_handler = \Drupal::moduleHandler();
$module_exist = $module_handler->moduleExists('cloudflare');
if ($module_exist) {
\Drupal::service('module_installer')->uninstall(['cloudflare']);
}
}
/**
* Make user creation require admin approval.
*/
function tide_core_update_8025() {
// Don't do anything else during config sync.
if (\Drupal::isConfigSyncing()) {
return;
}
// Restrict user registration to admin role creation.
\Drupal::configFactory()
->getEditable('user.settings')
->set('register', UserInterface::REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL)
->save(TRUE);
}
/**
* Update Scheduled Transitions View.
*/
function tide_core_update_8026() {
$config_factory = \Drupal::configFactory();
$config = $config_factory->getEditable('views.view.scheduled_transitions');
if ($config->isNew()) {
return;
}
// Update empty View results.
$config->set('display.default.display_options.empty.area.content.format', 'plain_text');
$config->save();
}
/**
* Enable username_enumeration_prevention module.
*/
function tide_core_update_8027() {
if (!\Drupal::moduleHandler()->moduleExists('username_enumeration_prevention')) {
$module_installer = \Drupal::service('module_installer');
$module_installer->install(['username_enumeration_prevention']);
}
}
/**
* Deletes unsupported actions from /admin/contents view.
*/
function tide_core_update_8028() {
// Actions whose provided by drupal core.
$unsupported_actions = [
'system.action.node_make_sticky_action',
'system.action.node_make_unsticky_action',
'system.action.node_promote_action',
'system.action.node_save_action',
'system.action.node_unpromote_action',
'system.action.node_publish_action',
'system.action.node_unpublish_action',
'system.action.pathauto_update_alias_node',
];
$config_storage = \Drupal::service('config.storage');
$config_factory = \Drupal::configFactory();
foreach ($unsupported_actions as $action) {
if ($config_storage->read($action)) {
$config = $config_factory->getEditable($action);
if (!$config->isNew()) {
$config->delete();
}
}
}
}
/**
* Imports custom actions.
*/
function tide_core_update_8029() {
$actions = [
'system.action.tide_core_archive',
'system.action.tide_core_publish',
];
$config_path = drupal_get_path('module', 'tide_core') . '/config/install';
$source = new FileStorage($config_path);
$config_storage = \Drupal::service('config.storage');
foreach ($actions as $action) {
$config_storage->write($action, $source->read($action));
}
}
/**
* Moves introduction up to top.
*/
function tide_core_update_8030() {
$node_types = NodeType::loadMultiple();
$entity_view_display_storage = \Drupal::entityTypeManager()
->getStorage('entity_view_display');
$skipped_items = ['title', 'uuid', 'created'];
foreach ($node_types as $node_type_id => $node_type) {
$order = [];
$entity_view_display_id = 'node.' . $node_type_id . '.default';
$field_name = 'field_' . $node_type_id . '_intro_text';
// Some of fields named as field_{node_type_id}_intro_text,
// so we have to deal with them separately.
$entity_view_display = $entity_view_display_storage->loadByProperties([
'id' => $entity_view_display_id,
'bundle' => $node_type_id,
'content.' . $field_name . '.region' => 'content',
]);
// Some of fields named as field_landing_page_intro_text.
if (!$entity_view_display) {
$field_name = 'field_landing_page_intro_text';
$entity_view_display = $entity_view_display_storage->loadByProperties([
'id' => $entity_view_display_id,
'bundle' => $node_type_id,
'content.' . $field_name . '.region' => 'content',
]);
}
if ($entity_view_display) {
foreach ($content = $entity_view_display[$entity_view_display_id]->get('content') as $key => $item) {
if (in_array($key, $skipped_items)) {
continue;
}
if ($key == 'content_moderation_control') {
continue;
}
if ($key == $field_name) {
$content[$field_name]['weight'] = $content['content_moderation_control']['weight'] + 1;
}
else {
$content[$key]['weight'] += 1;
}
}
$entity_view_display[$entity_view_display_id]->set('content', $content)->save();
}
}
}
/**
* Changes allowed HTML list.
*/
function tide_core_update_8031() {
$config_factory = \Drupal::configFactory();
$filter_ids = [
'filter.format.admin_text',
'filter.format.rich_text',
];
foreach ($filter_ids as $filter_id) {
$filter = $config_factory->getEditable($filter_id);
if ($filter->isNew()) {
continue;
}
$value = $filter->get('filters.filter_html.settings.allowed_html');
$replaced = str_replace('<td>', '<td colspan rowspan align class>', $value);
$replaced = str_replace('<th>', '<th colspan rowspan align class>', $replaced);
$filter->set('filters.filter_html.settings.allowed_html', $replaced);
$filter->save();
}
}
/**
* Changes display of dates in CMS to Australian style DD/MM/YYYY.
*/
function tide_core_update_8032() {
// Changes media view.
$media_view = \Drupal::configFactory()->getEditable('views.view.media');
if ($media_view->isNew()) {
return;
}
$display = $media_view->get('display');
$display['default']['display_options']['fields']['changed']['settings']['date_format'] = 'custom';
$display['default']['display_options']['fields']['changed']['settings']['custom_date_format'] = 'd/m/Y - H:i';
$media_view->set('display', $display)->save();
}
/**
* Enable addition of a second contact block on screen sidebar.
*/
function tide_core_update_8033() {
$config_factory = \Drupal::configFactory();
$config = $config_factory->getEditable('field.storage.node.field_landing_page_contact');
if ($config->isNew()) {
return;
}
$config->set('cardinality', 2);
$config->save();
}
/**
* CMS UI improvements - Accordion.
*/
function tide_core_update_8034() {
// Changes select style.
$entity_form_display = \Drupal::entityTypeManager()
->getStorage('entity_form_display')
->load('paragraph.accordion.default');
$component = $entity_form_display->getComponent('field_paragraph_accordion_style');
$component['type'] = 'options_buttons';
$entity_form_display->setComponent('field_paragraph_accordion_style', $component);
$entity_form_display->save();
// Changes field_paragraph_accordion label.
$field_paragraph_accordion = \Drupal::configFactory()
->getEditable('field.field.paragraph.accordion.field_paragraph_accordion');
$field_paragraph_accordion->set('label', 'Accordion items')->save();
// Changes field_paragraph_title label.
$field_paragraph_title = \Drupal::configFactory()->getEditable('field.field.paragraph.accordion.field_paragraph_title');
$field_paragraph_title->set('label', 'Accordion title')->save();
$field_paragraph_title->set('description', 'Add a heading 2 if you need a heading above your accordions (not mandatory).')->save();
// Changes accordion_content label.
$field_paragraph_accordion_name = \Drupal::configFactory()->getEditable('field.field.paragraph.accordion_content.field_paragraph_accordion_name');
$field_paragraph_accordion_name->set('label', 'Item title')->save();
// Changes field_paragraph_accordion_style label to Style.
$field_paragraph_accordion_style = \Drupal::configFactory()
->getEditable('field.field.paragraph.accordion.field_paragraph_accordion_style');
$field_paragraph_accordion_style->set('label', 'Style');
$field_paragraph_accordion_style->set('required', TRUE);
$field_paragraph_accordion_style->set('description', 'Choose standard or numbered.');
$field_paragraph_accordion_style->save();
// Changes field_paragraph_accordion_style value.
$config = \Drupal::configFactory()
->getEditable('field.storage.paragraph.field_paragraph_accordion_style');
$settings = $config->get('settings');
foreach ($settings['allowed_values'] as $key => &$allowed_value) {
if ($allowed_value['label'] == 'Basic') {
$allowed_value['label'] = 'Standard';
}
}
// Changes field_paragraph_accordion_body label.
$config->set('settings', $settings)->save();
$field_paragraph_accordion_body = \Drupal::configFactory()
->getEditable('field.field.paragraph.accordion_content.field_paragraph_accordion_body');
$field_paragraph_accordion_body->set('label', 'Item content')->save();
}
/**
* Imports new format and editor.
*/
function tide_core_update_8035() {
$configs = [
'filter.format.summary_text' => 'filter_format',
'editor.editor.summary_text' => 'editor',
];
module_load_include('inc', 'tide_core', 'includes/helpers');
$config_location = [drupal_get_path('module', 'tide_core') . '/config/optional'];
// 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);
$id = substr($config, strrpos($config, '.') + 1);
if ($storage->load($id) == NULL) {
$config_entity = $storage->createFromStorageRecord($config_read);
$config_entity->save();
}
}
}
/**
* Approver, site_admin and editor should access to `summary_text` text format.
*/
function tide_core_update_8036() {
$roles = ['approver', 'site_admin', 'editor'];
$permissions[] = 'use text format summary_text';
foreach ($roles as $role) {
user_role_grant_permissions(Role::load($role)->id(), $permissions);
}
}
/**
* Add field storage for field_display_headings.
*/
function tide_core_update_8037() {
module_load_include('inc', 'tide_core', 'includes/helpers');
$config_location = [drupal_get_path('module', 'tide_core') . '/config/install'];
$field_storage = 'field.storage.node.field_node_display_headings';
$storage = \Drupal::entityTypeManager()->getStorage('field_storage_config');
if (empty($storage->load('node.field_node_display_headings'))) {
$config_read = _tide_read_config($field_storage, $config_location, TRUE);
// Obtain the storage manager for field storage bases.
// Create a new field from the yaml configuration and save.
$storage->createFromStorageRecord($config_read)->save();
}
}
/**
* Add Callout template to wysiwyg toolbar.
*/
function tide_core_update_8038() {
$config_factory = \Drupal::configFactory();
$configs = [
'editor.editor.admin_text',
'editor.editor.rich_text',
];
foreach ($configs as $config) {
$editable_config = $config_factory->getEditable($config);
if ($editable_config->isNew()) {
continue;
}
$rows = $editable_config->get('settings.toolbar.rows.0');
if (!isset($rows)) {
continue;
}
$updated_rows = [];
foreach ($rows as $key => $row) {
if ($row['name'] === 'Media' && !in_array('TideCallout', $row['items'])) {
// Insert tide_callout inside Media group toolbar.
array_splice($row['items'], 1, 0, 'TideCallout');
}
$updated_rows[] = $row;
}
$editable_config->set('settings.toolbar.rows.0', $updated_rows);
$editable_config->save();
}
}
/**
* Enable ckeditor_liststyle module.
*/
function tide_core_update_8039() {
if (!\Drupal::moduleHandler()->moduleExists('ckeditor_liststyle')) {
$module_installer = \Drupal::service('module_installer');