function system_post_update_extra_fields

Update all entity view displays that contain extra fields.

File

core/modules/system/system.post_update.php, line 155

Code

function system_post_update_extra_fields(&$sandbox = NULL) {
    $config_entity_updater = \Drupal::classResolver(ConfigEntityUpdater::class);
    $entity_field_manager = \Drupal::service('entity_field.manager');
    $callback = function (EntityDisplayInterface $display) use ($entity_field_manager) {
        $display_context = $display instanceof EntityViewDisplayInterface ? 'display' : 'form';
        $extra_fields = $entity_field_manager->getExtraFields($display->getTargetEntityTypeId(), $display->getTargetBundle());
        // If any extra fields are used as a component, resave the display with the
        // updated component information.
        $needs_save = FALSE;
        if (!empty($extra_fields[$display_context])) {
            foreach ($extra_fields[$display_context] as $name => $extra_field) {
                if ($component = $display->getComponent($name)) {
                    $display->setComponent($name, $component);
                    $needs_save = TRUE;
                }
            }
        }
        return $needs_save;
    };
    $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.