W3cubDocs

/Drupal 8

public function BaseFieldDefinition::getOptionsProvider

public BaseFieldDefinition::getOptionsProvider($property_name, FieldableEntityInterface $entity)

Gets an options provider for the given field item property.

Parameters

string $property_name: The name of the property to get options for; e.g., 'value'.

\Drupal\Core\Entity\FieldableEntityInterface $entity: The entity for which the options should be provided.

Return value

\Drupal\Core\TypedData\OptionsProviderInterface|null An options provider, or NULL if no options are defined.

Overrides FieldStorageDefinitionInterface::getOptionsProvider

File

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

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->getFieldItemClass(), OptionsProviderInterface::class)) {
    $items = $entity->get($this->getName());
    return \Drupal::service('plugin.manager.field.field_type')->createFieldItem($items, 0);
  }
  // @todo: Allow setting custom options provider, see
  // https://www.drupal.org/node/2002138.
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Field!BaseFieldDefinition.php/function/BaseFieldDefinition::getOptionsProvider/8.1.x