function Workspace::baseFieldDefinitions

Same name in other branches
  1. 9 core/modules/workspaces/src/Entity/Workspace.php \Drupal\workspaces\Entity\Workspace::baseFieldDefinitions()
  2. 8.9.x core/modules/workspaces/src/Entity/Workspace.php \Drupal\workspaces\Entity\Workspace::baseFieldDefinitions()
  3. 11.x core/modules/workspaces/src/Entity/Workspace.php \Drupal\workspaces\Entity\Workspace::baseFieldDefinitions()

Overrides ContentEntityBase::baseFieldDefinitions

File

core/modules/workspaces/src/Entity/Workspace.php, line 76

Class

Workspace
The workspace entity class.

Namespace

Drupal\workspaces\Entity

Code

public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
    $fields = parent::baseFieldDefinitions($entity_type);
    $fields += static::ownerBaseFieldDefinitions($entity_type);
    $fields['id'] = BaseFieldDefinition::create('string')->setLabel(new TranslatableMarkup('Workspace ID'))
        ->setDescription(new TranslatableMarkup('The workspace ID.'))
        ->setSetting('max_length', 128)
        ->setRequired(TRUE)
        ->addConstraint('UniqueField')
        ->addConstraint('DeletedWorkspace')
        ->addPropertyConstraints('value', [
        'Regex' => [
            'pattern' => '/^[a-z0-9_]+$/',
        ],
    ]);
    $fields['label'] = BaseFieldDefinition::create('string')->setLabel(new TranslatableMarkup('Workspace name'))
        ->setDescription(new TranslatableMarkup('The workspace name.'))
        ->setRevisionable(TRUE)
        ->setSetting('max_length', 128)
        ->setRequired(TRUE);
    $fields['uid']->setLabel(new TranslatableMarkup('Owner'))
        ->setDescription(new TranslatableMarkup('The workspace owner.'))
        ->setDisplayOptions('form', [
        'type' => 'entity_reference_autocomplete',
        'weight' => 5,
    ])
        ->setDisplayConfigurable('form', TRUE);
    $fields['parent'] = BaseFieldDefinition::create('entity_reference')->setLabel(new TranslatableMarkup('Parent'))
        ->setDescription(new TranslatableMarkup('The parent workspace.'))
        ->setSetting('target_type', 'workspace')
        ->setReadOnly(TRUE)
        ->setDisplayConfigurable('form', TRUE)
        ->setDisplayOptions('form', [
        'type' => 'options_select',
        'weight' => 10,
    ]);
    $fields['changed'] = BaseFieldDefinition::create('changed')->setLabel(new TranslatableMarkup('Changed'))
        ->setDescription(new TranslatableMarkup('The time that the workspace was last edited.'))
        ->setRevisionable(TRUE);
    $fields['created'] = BaseFieldDefinition::create('created')->setLabel(new TranslatableMarkup('Created'))
        ->setDescription(new TranslatableMarkup('The time that the workspace was created.'));
    return $fields;
}

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