You are here

public static function DynamicEntityReferenceItem::propertyDefinitions in Dynamic Entity Reference 8

Same name and namespace in other branches
  1. 8.2 src/Plugin/Field/FieldType/DynamicEntityReferenceItem.php \Drupal\dynamic_entity_reference\Plugin\Field\FieldType\DynamicEntityReferenceItem::propertyDefinitions()

Defines field item properties.

Properties that are required to constitute a valid, non-empty item should be denoted with \Drupal\Core\TypedData\DataDefinition::setRequired().

Return value

\Drupal\Core\TypedData\DataDefinitionInterface[] An array of property definitions of contained properties, keyed by property name.

Overrides EntityReferenceItem::propertyDefinitions

See also

\Drupal\Core\Field\BaseFieldDefinition

File

src/Plugin/Field/FieldType/DynamicEntityReferenceItem.php, line 75

Class

DynamicEntityReferenceItem
Defines the 'dynamic_entity_reference' entity field type.

Namespace

Drupal\dynamic_entity_reference\Plugin\Field\FieldType

Code

public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition) {
  $properties['target_id'] = DataReferenceTargetDefinition::create('integer')
    ->setLabel(t('Entity ID'))
    ->setSetting('unsigned', TRUE)
    ->setRequired(TRUE);
  $properties['target_type'] = DataReferenceTargetDefinition::create('string')
    ->setLabel(new TranslatableMarkup('Target Entity Type'))
    ->setRequired(TRUE);
  $properties['entity'] = DataDynamicReferenceDefinition::create('entity')
    ->setLabel(t('Entity'))
    ->setDescription(new TranslatableMarkup('The referenced entity'))
    ->setComputed(TRUE)
    ->setReadOnly(FALSE);
  return $properties;
}