function system_post_update_extra_fields_form_display

Same name in other branches
  1. 9 core/modules/system/system.post_update.php \system_post_update_extra_fields_form_display()

Update all entity form displays that contain extra fields.

File

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

Code

function system_post_update_extra_fields_form_display(&$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_form_display', $callback);
}

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