Skip to content
Snippets Groups Projects
Commit 05ddb76a authored by christian.wiedemann's avatar christian.wiedemann Committed by Edouard Cunibil
Browse files

ISSUE-3251489: Add update hook to migrate layout builder fields to new format.

parent abb7a77f
No related branches found
No related tags found
No related merge requests found
......@@ -5,6 +5,7 @@
* UI Patterns Field Formatters updates.
*/
use Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplay;
use Drupal\ui_patterns\Form\PatternDisplayFormTrait;
/**
......@@ -43,3 +44,48 @@ 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) {
if (!\Drupal::moduleHandler()->moduleExists('layout_builder')) {
return;
}
$displayStorage = \Drupal::entityTypeManager()->getStorage('entity_view_display');
if (!isset($sandbox['total'])) {
$sandbox['ids'] = $displayStorage->getQuery()->execute();
$sandbox['total'] = count($sandbox['ids']);
$sandbox['progress'] = 0;
}
$id = array_pop($sandbox['ids']);
$display = $displayStorage->load($id);
if ($display instanceof 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'];
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment