function field_field_config_create

Implements hook_ENTITY_TYPE_create() for 'field_config'.

Determine the selection handler plugin ID for an entity reference field.

2 calls to field_field_config_create()
field_field_config_presave in core/modules/field/field.module
Implements hook_ENTITY_TYPE_presave() for 'field_config'.
field_form_field_config_edit_form_entity_builder in core/modules/field/field.module
Entity form builder for field config edit form.

File

core/modules/field/field.module, line 395

Code

function field_field_config_create(FieldConfigInterface $field) {
    if ($field->isSyncing()) {
        return;
    }
    // Act on all sub-types of the entity_reference field type.
    
    /** @var \Drupal\Core\Field\FieldTypePluginManager $field_type_manager */
    $field_type_manager = \Drupal::service('plugin.manager.field.field_type');
    $item_class = 'Drupal\\Core\\Field\\Plugin\\Field\\FieldType\\EntityReferenceItem';
    $class = $field_type_manager->getPluginClass($field->getType());
    if ($class !== $item_class && !is_subclass_of($class, $item_class)) {
        return;
    }
    // If we don't know the target type yet, there's nothing else we can do.
    $target_type = $field->getFieldStorageDefinition()
        ->getSetting('target_type');
    if (empty($target_type)) {
        return;
    }
    // Make sure the selection handler plugin is the correct derivative for the
    // target entity type.
    $selection_manager = \Drupal::service('plugin.manager.entity_reference_selection');
    [
        $current_handler,
    ] = explode(':', $field->getSetting('handler'), 2);
    $field->setSetting('handler', $selection_manager->getPluginId($target_type, $current_handler));
}

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