You are here

function system_entity_form_display_presave in Drupal 8

Implements hook_ENTITY_TYPE_presave() for entity_form_display entities.

Provides a BC layer for modules providing old configurations.

@todo Remove this hook in Drupal 9.0.x https://www.drupal.org/project/drupal/issues/3086388

File

core/modules/system/system.module, line 1434
Configuration system that lets administrators modify the workings of the site.

Code

function system_entity_form_display_presave(EntityFormDisplayInterface $display) {

  /** @var \Drupal\Core\Field\WidgetPluginManager $field_widget_manager */
  $field_widget_manager = \Drupal::service('plugin.manager.field.widget');
  foreach ($display
    ->getComponents() as $field_name => $component) {
    if (empty($component['type'])) {
      continue;
    }
    $plugin_definition = $field_widget_manager
      ->getDefinition($component['type'], FALSE);
    if (!is_a($plugin_definition['class'], EntityReferenceAutocompleteWidget::class, TRUE)) {
      continue;
    }
    if (!isset($component['settings']['match_limit'])) {
      @trigger_error(sprintf('Any entity_reference_autocomplete component of an entity_form_display must have a match_limit setting. The %s field on the %s form display is missing it. This BC layer will be removed before 9.0.0. See https://www.drupal.org/node/2863188', $field_name, $display
        ->id()), E_USER_DEPRECATED);
      $component['settings']['match_limit'] = 10;
      $display
        ->setComponent($field_name, $component);
    }
  }
}