function EntityReferenceItem::getPreconfiguredOptions

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/Field/Plugin/Field/FieldType/EntityReferenceItem.php \Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem::getPreconfiguredOptions()
  2. 10 core/lib/Drupal/Core/Field/Plugin/Field/FieldType/EntityReferenceItem.php \Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem::getPreconfiguredOptions()
  3. 11.x core/lib/Drupal/Core/Field/Plugin/Field/FieldType/EntityReferenceItem.php \Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem::getPreconfiguredOptions()

Overrides PreconfiguredFieldUiOptionsInterface::getPreconfiguredOptions

1 method overrides EntityReferenceItem::getPreconfiguredOptions()
FileItem::getPreconfiguredOptions in core/modules/file/src/Plugin/Field/FieldType/FileItem.php
Returns preconfigured field options for a field type.

File

core/lib/Drupal/Core/Field/Plugin/Field/FieldType/EntityReferenceItem.php, line 686

Class

EntityReferenceItem
Defines the 'entity_reference' entity field type.

Namespace

Drupal\Core\Field\Plugin\Field\FieldType

Code

public static function getPreconfiguredOptions() {
    $options = [];
    // Add all the commonly referenced entity types as distinct pre-configured
    // options.
    $entity_types = \Drupal::entityTypeManager()->getDefinitions();
    $common_references = array_filter($entity_types, function (EntityTypeInterface $entity_type) {
        return $entity_type->isCommonReferenceTarget();
    });
    
    /** @var \Drupal\Core\Entity\EntityTypeInterface $entity_type */
    foreach ($common_references as $entity_type) {
        $options[$entity_type->id()] = [
            'label' => $entity_type->getLabel(),
            'field_storage_config' => [
                'settings' => [
                    'target_type' => $entity_type->id(),
                ],
            ],
        ];
    }
    return $options;
}

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