function layout_builder_restrictions_update_8212 in Layout Builder Restrictions 8.2
Relocate 'allowed_blocks' to 'whitelisted_blocks'.
File
- ./
layout_builder_restrictions.install, line 131 - Contains install and update functions for Layout Builder Restrictions.
Code
function layout_builder_restrictions_update_8212(&$sandbox) {
// When upgrading to 2.6, configuration for 'allowed_blocks'
// is relocated to 'whitelisted_blocks' to distinguish from newly available
// 'blacklisted_blocks' (which will default to an empty array for existing
// sites).
$config_factory = \Drupal::configFactory();
if (!isset($sandbox['count'])) {
$sandbox['ids'] = $config_factory
->listAll('core.entity_view_display.');
$sandbox['count'] = count($sandbox['ids']);
}
$ids = array_splice($sandbox['ids'], 0, 50);
foreach ($ids as $id) {
$display = $config_factory
->getEditable($id);
if ($display
->get('third_party_settings.layout_builder_restrictions')) {
$allowed_blocks_by_category = $display
->get('third_party_settings.layout_builder_restrictions.entity_view_mode_restriction.allowed_blocks');
$display
->clear('third_party_settings.layout_builder_restrictions.entity_view_mode_restriction.allowed_blocks')
->set('third_party_settings.layout_builder_restrictions.entity_view_mode_restriction.whitelisted_blocks', $allowed_blocks_by_category)
->set('third_party_settings.layout_builder_restrictions.entity_view_mode_restriction.blacklisted_blocks', [])
->save();
}
}
$sandbox['#finished'] = empty($sandbox['ids']) ? 1 : ($sandbox['count'] - count($sandbox['ids'])) / $sandbox['count'];
}