Skip to content
Snippets Groups Projects

Issue #3251489: updb doesn't check layout builder fields.

1 file
+ 43
0
Compare changes
  • Side-by-side
  • Inline
@@ -43,3 +43,46 @@ function ui_patterns_field_formatters_update_9001(&$sandbox) {
$sandbox['#finished'] = $sandbox['progress'] / $sandbox['total'];
}
/**
* Clean up existing formatters settings placed by layout builder.
*/
function ui_patterns_field_formatters_update_9002(&$sandbox) {
$displayStorage = \Drupal::entityTypeManager()->getStorage('entity_view_display');
if (!isset($sandbox['total'])) {
$sandbox['ids'] = $displayStorage->getQuery()->execute();
$sandbox['total'] = count($sandbox['ids']);
$sandbox['progress'] = 0;
}
if (\Drupal::moduleHandler()->moduleExists('layout_builder')) {
$id = array_pop($sandbox['ids']);
$display = $displayStorage->load($id);
if ($display instanceof \Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplay) {
$sections = $display->getSections();
foreach ($sections as $section) {
foreach ($section->getComponents() as $component) {
$component_array = $component->toArray();
if (isset($component_array['configuration']['formatter']['type'])) {
$definition = &$component_array['configuration']['formatter'];
if (
$definition['type'] === 'pattern_formatter' ||
$definition['type'] === 'pattern_wrapper_entity_reference_formatter'
) {
PatternDisplayFormTrait::processFormStateValues($definition['settings']);
$component->setConfiguration($component_array['configuration']);
$changed = TRUE;
}
}
}
}
}
if (!empty($changed)) {
$display->save();
}
}
$sandbox['progress']++;
$sandbox['#finished'] = $sandbox['progress'] / $sandbox['total'];
}
Loading