Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. BaseFieldDefinition.php

function BaseFieldDefinition::getOptionsProvider

Overrides FieldStorageDefinitionInterface::getOptionsProvider

File

core/lib/Drupal/Core/Field/BaseFieldDefinition.php, line 560

Class

BaseFieldDefinition
A class for defining entity fields.

Namespace

Drupal\Core\Field

Code

public function getOptionsProvider($property_name, FieldableEntityInterface $entity) {
    // If the field item class implements the interface, create an orphaned
    // runtime item object, so that it can be used as the options provider
    // without modifying the entity being worked on.
    if (is_subclass_of($this->getItemDefinition()
        ->getClass(), OptionsProviderInterface::class)) {
        $items = $entity->get($this->getName());
        return \Drupal::service('plugin.manager.field.field_type')->createFieldItem($items, 0);
    }
    // @todo Allow setting custom options provider.
    //   https://www.drupal.org/node/2002138
}
RSS feed
Powered by Drupal