function system_entity_view_display_presave

Implements hook_ENTITY_TYPE_presave() for entity_view_display entities.

Provides a BC layer for modules providing old configurations.

@todo Remove this BC layer in drupal:11.0.0.

See also

https://www.drupal.org/node/2993639

File

core/modules/system/system.module, line 1376

Code

function system_entity_view_display_presave(EntityViewDisplayInterface $entity_view_display) : void {
    
    /** @var \Drupal\Core\Field\FormatterPluginManager $field_formatter_manager */
    $field_formatter_manager = \Drupal::service('plugin.manager.field.formatter');
    foreach ($entity_view_display->getComponents() as $name => $component) {
        if (empty($component['type'])) {
            continue;
        }
        if (!($plugin_definition = $field_formatter_manager->getDefinition($component['type'], FALSE))) {
            continue;
        }
        // Check also potential plugins that extends TimestampFormatter.
        if (!is_a($plugin_definition['class'], TimestampFormatter::class, TRUE)) {
            continue;
        }
        if (!isset($component['settings']['tooltip']) || !isset($component['settings']['time_diff'])) {
            @trigger_error("Using the 'timestamp' formatter plugin  without the 'tooltip' and 'time_diff' settings is deprecated in drupal:10.1.0 and is required in drupal:11.0.0. See https://www.drupal.org/node/2993639", E_USER_DEPRECATED);
            $entity_view_display->setComponent($name, $component);
        }
    }
}

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