function BaseFieldDefinition::createFromFieldStorageDefinition

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/Field/BaseFieldDefinition.php \Drupal\Core\Field\BaseFieldDefinition::createFromFieldStorageDefinition()
  2. 8.9.x core/lib/Drupal/Core/Field/BaseFieldDefinition.php \Drupal\Core\Field\BaseFieldDefinition::createFromFieldStorageDefinition()
  3. 10 core/lib/Drupal/Core/Field/BaseFieldDefinition.php \Drupal\Core\Field\BaseFieldDefinition::createFromFieldStorageDefinition()

Creates a new field definition based upon a field storage definition.

In cases where one needs a field storage definitions to act like full field definitions, this creates a new field definition based upon the (limited) information available. That way it is possible to use the field definition in places where a full field definition is required; e.g., with widgets or formatters.

Parameters

\Drupal\Core\Field\FieldStorageDefinitionInterface $definition: The field storage definition to base the new field definition upon.

Return value

$this

2 calls to BaseFieldDefinition::createFromFieldStorageDefinition()
FieldAPIHandlerTrait::getFieldDefinition in core/modules/views/src/FieldAPIHandlerTrait.php
Gets the field definition.
FieldStorageConfig::getOptionsProvider in core/modules/field/src/Entity/FieldStorageConfig.php
Gets an options provider for the given field item property.

File

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

Class

BaseFieldDefinition
A class for defining entity fields.

Namespace

Drupal\Core\Field

Code

public static function createFromFieldStorageDefinition(FieldStorageDefinitionInterface $definition) {
    return static::create($definition->getType())
        ->setCardinality($definition->getCardinality())
        ->setConstraints($definition->getConstraints())
        ->setCustomStorage($definition->hasCustomStorage())
        ->setDescription($definition->getDescription())
        ->setLabel($definition->getLabel())
        ->setName($definition->getName())
        ->setProvider($definition->getProvider())
        ->setRevisionable($definition->isRevisionable())
        ->setSettings($definition->getSettings())
        ->setTargetEntityTypeId($definition->getTargetEntityTypeId())
        ->setTranslatable($definition->isTranslatable());
}

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