You are here

public function EntityTypeInfo::entityBaseFieldInfo in Drupal 8

Same name in this branch
  1. 8 core/modules/content_moderation/src/EntityTypeInfo.php \Drupal\content_moderation\EntityTypeInfo::entityBaseFieldInfo()
  2. 8 core/modules/workspaces/src/EntityTypeInfo.php \Drupal\workspaces\EntityTypeInfo::entityBaseFieldInfo()
Same name and namespace in other branches
  1. 9 core/modules/workspaces/src/EntityTypeInfo.php \Drupal\workspaces\EntityTypeInfo::entityBaseFieldInfo()

Provides custom base field definitions for a content entity type.

Parameters

\Drupal\Core\Entity\EntityTypeInterface $entity_type: The entity type definition.

Return value

\Drupal\Core\Field\FieldDefinitionInterface[] An array of field definitions, keyed by field name.

See also

hook_entity_base_field_info()

File

core/modules/workspaces/src/EntityTypeInfo.php, line 125

Class

EntityTypeInfo
Manipulates entity type information.

Namespace

Drupal\workspaces

Code

public function entityBaseFieldInfo(EntityTypeInterface $entity_type) {
  if ($this->workspaceManager
    ->isEntityTypeSupported($entity_type)) {

    // Disable the BC layer to prevent a recursion, this only needs the
    // workspace key that is always set.
    $field_name = $entity_type
      ->getRevisionMetadataKeys(FALSE)['workspace'];
    $fields[$field_name] = BaseFieldDefinition::create('entity_reference')
      ->setLabel(new TranslatableMarkup('Workspace'))
      ->setDescription(new TranslatableMarkup('Indicates the workspace that this revision belongs to.'))
      ->setSetting('target_type', 'workspace')
      ->setInternal(TRUE)
      ->setTranslatable(FALSE)
      ->setRevisionable(TRUE);
    return $fields;
  }
}