X-Git-Url: http://aleph1.co.uk/gitweb/?a=blobdiff_plain;f=web%2Fcore%2Fmodules%2Flayout_builder%2Flayout_builder.post_update.php;h=1fcd74d4373496cfe6561e2143bfcc47d5a7ee7d;hb=4f1b9b4ab48a8498afac9e2213a02a23ccf4a06c;hp=9a2b85800e3c2b57300ca647a2a6a898b957791e;hpb=af6d1fb995500ae68849458ee10d66abbdcfb252;p=yaffs-website diff --git a/web/core/modules/layout_builder/layout_builder.post_update.php b/web/core/modules/layout_builder/layout_builder.post_update.php index 9a2b85800..1fcd74d43 100644 --- a/web/core/modules/layout_builder/layout_builder.post_update.php +++ b/web/core/modules/layout_builder/layout_builder.post_update.php @@ -5,6 +5,9 @@ * Post update functions for Layout Builder. */ +use Drupal\Core\Config\Entity\ConfigEntityUpdater; +use Drupal\layout_builder\Entity\LayoutEntityDisplayInterface; + /** * Rebuild plugin dependencies for all entity view displays. */ @@ -24,3 +27,34 @@ function layout_builder_post_update_rebuild_plugin_dependencies(&$sandbox = NULL $sandbox['#finished'] = empty($sandbox['ids']) ? 1 : ($sandbox['count'] - count($sandbox['ids'])) / $sandbox['count']; } + +/** + * Ensure all extra fields are properly stored on entity view displays. + * + * Previously + * \Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplay::setComponent() + * was not correctly setting the configuration for extra fields. This function + * calls setComponent() for all extra field components to ensure the updated + * logic is invoked on all extra fields to correct the settings. + */ +function layout_builder_post_update_add_extra_fields(&$sandbox = NULL) { + $entity_field_manager = \Drupal::service('entity_field.manager'); + \Drupal::classResolver(ConfigEntityUpdater::class)->update($sandbox, 'entity_view_display', function (LayoutEntityDisplayInterface $display) use ($entity_field_manager) { + if (!$display->isLayoutBuilderEnabled()) { + return FALSE; + } + + $extra_fields = $entity_field_manager->getExtraFields($display->getTargetEntityTypeId(), $display->getTargetBundle()); + $components = $display->getComponents(); + // Sort the components to avoid them being reordered by setComponent(). + uasort($components, 'Drupal\Component\Utility\SortArray::sortByWeightElement'); + $result = FALSE; + foreach ($components as $name => $component) { + if (isset($extra_fields['display'][$name])) { + $display->setComponent($name, $component); + $result = TRUE; + } + } + return $result; + }); +}