-
Notifications
You must be signed in to change notification settings - Fork 3
/
localgov_directories.post_update.php
51 lines (46 loc) · 1.69 KB
/
localgov_directories.post_update.php
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
<?php
/**
* @file
* Post update hooks for LocalGov Directories.
*/
/**
* Updates the node type visibility condition.
*
* This was inluded in core D9 as block_post_update_replace_node_type_condition
* but we had installed condition plugins with this after it might have run.
* No harm in running this multiple times.
*/
function localgov_directories_post_update_replace_node_type_condition() {
$config_factory = \Drupal::configFactory();
foreach ($config_factory->listAll('block.block.') as $block_config_name) {
$block = $config_factory->getEditable($block_config_name);
if ($block->get('visibility.node_type')) {
$configuration = $block->get('visibility.node_type');
$configuration['id'] = 'entity_bundle:node';
$block->set('visibility.entity_bundle:node', $configuration);
$block->clear('visibility.node_type');
$block->save(TRUE);
}
}
}
/**
* Updates the node type visibility condition again.
*
* Because we'd still been installing old config.
* https://github.com/localgovdrupal/localgov_directories/pull/342/files.
*/
function localgov_directories_post_update_replace_node_type_condition_again() {
$config_factory = \Drupal::configFactory();
foreach ($config_factory->listAll('block.block.') as $block_config_name) {
$block = $config_factory->getEditable($block_config_name);
if ($block->get('visibility.node_type')) {
$configuration = $block->get('visibility.node_type');
if ($configuration['id'] == 'node_type') {
$configuration['id'] = 'entity_bundle:node';
$block->set('visibility.entity_bundle:node', $configuration);
$block->clear('visibility.node_type');
$block->save(TRUE);
}
}
}
}