You are here

function system_post_update_entity_reference_autocomplete_match_limit in Drupal 8

Populate the new 'match_limit' setting for the ER autocomplete widget.

File

core/modules/system/system.post_update.php, line 248
Post update functions for System.

Code

function system_post_update_entity_reference_autocomplete_match_limit(&$sandbox = NULL) {
  $config_entity_updater = \Drupal::classResolver(ConfigEntityUpdater::class);

  /** @var \Drupal\Core\Field\WidgetPluginManager $field_widget_manager */
  $field_widget_manager = \Drupal::service('plugin.manager.field.widget');
  $callback = function (EntityDisplayInterface $display) use ($field_widget_manager) {
    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)) {
        return TRUE;
      }
    }
    return FALSE;
  };
  $config_entity_updater
    ->update($sandbox, 'entity_form_display', $callback);
}