You are here

public static function EntityReferenceRevisionsItem::propertyDefinitions in Entity Reference Revisions 8

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/EntityReferenceRevisionsItem.php, line 105

Class

EntityReferenceRevisionsItem
Defines the 'entity_reference_revisions' entity field type.

Namespace

Drupal\entity_reference_revisions\Plugin\Field\FieldType

Code

public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition) {
  $settings = $field_definition
    ->getSettings();
  $target_type_info = \Drupal::entityTypeManager()
    ->getDefinition($settings['target_type']);
  $properties = parent::propertyDefinitions($field_definition);
  if ($target_type_info
    ->getKey('revision')) {
    $target_revision_id_definition = DataReferenceTargetDefinition::create('integer')
      ->setLabel(t('@label revision ID', array(
      '@label' => $target_type_info
        ->getLabel(),
    )))
      ->setSetting('unsigned', TRUE);
    $target_revision_id_definition
      ->setRequired(TRUE);
    $properties['target_revision_id'] = $target_revision_id_definition;
  }
  $properties['entity'] = DataReferenceDefinition::create('entity_revision')
    ->setLabel($target_type_info
    ->getLabel())
    ->setDescription(t('The referenced entity revision'))
    ->setComputed(TRUE)
    ->setReadOnly(FALSE)
    ->setTargetDefinition(EntityDataDefinition::create($settings['target_type']));
  return $properties;
}