function layout_builder_post_update_section_storage_context_mapping

Update view displays that use Layout Builder to add empty context mappings.

File

core/modules/layout_builder/layout_builder.post_update.php, line 45

Code

function layout_builder_post_update_section_storage_context_mapping(&$sandbox = []) {
    $config_entity_updater = \Drupal::classResolver(ConfigEntityUpdater::class);
    $callback = function (EntityViewDisplayInterface $display) {
        $needs_update = FALSE;
        // Only update entity view displays where Layout Builder is enabled.
        if ($display instanceof LayoutEntityDisplayInterface && $display->isLayoutBuilderEnabled()) {
            foreach ($display->getSections() as $section) {
                // Add an empty context mapping to each section where one doesn't exist.
                $section->setLayoutSettings($section->getLayoutSettings() + [
                    'context_mapping' => [],
                ]);
                // Flag this display as needing to be updated.
                $needs_update = TRUE;
            }
        }
        return $needs_update;
    };
    $config_entity_updater->update($sandbox, 'entity_view_display', $callback);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.