public static function WorkspacePointer::baseFieldDefinitions in Workspace 8
Provides base field definitions for an entity type.
Implementations typically use the class \Drupal\Core\Field\BaseFieldDefinition for creating the field definitions; for example a 'name' field could be defined as the following:
$fields['name'] = BaseFieldDefinition::create('string')
  ->setLabel(t('Name'));By definition, base fields are fields that exist for every bundle. To provide definitions for fields that should only exist on some bundles, use \Drupal\Core\Entity\FieldableEntityInterface::bundleFieldDefinitions().
The definitions returned by this function can be overridden for all bundles by hook_entity_base_field_info_alter() or overridden on a per-bundle basis via 'base_field_override' configuration entities.
Parameters
\Drupal\Core\Entity\EntityTypeInterface $entity_type: The entity type definition. Useful when a single class is used for multiple, possibly dynamic entity types.
Return value
\Drupal\Core\Field\FieldDefinitionInterface[] An array of base field definitions for the entity type, keyed by field name.
Overrides ContentEntityBase::baseFieldDefinitions
See also
\Drupal\Core\Entity\EntityFieldManagerInterface::getFieldDefinitions()
\Drupal\Core\Entity\FieldableEntityInterface::bundleFieldDefinitions()
File
- src/Entity/ WorkspacePointer.php, line 171 
Class
- WorkspacePointer
- Defines the Workspace pointer entity.
Namespace
Drupal\workspace\EntityCode
public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
  $fields['id'] = BaseFieldDefinition::create('integer')
    ->setLabel(t('ID'))
    ->setDescription(t('The ID of the Workspace pointer entity.'))
    ->setReadOnly(TRUE);
  $fields['uuid'] = BaseFieldDefinition::create('uuid')
    ->setLabel(t('UUID'))
    ->setDescription(t('The UUID of the Workspace pointer entity.'))
    ->setReadOnly(TRUE);
  $fields['revision_id'] = BaseFieldDefinition::create('integer')
    ->setLabel(t('Revision ID'))
    ->setDescription(t('The revision ID of the workspace pointer entity.'))
    ->setReadOnly(TRUE)
    ->setSetting('unsigned', TRUE);
  $fields['name'] = BaseFieldDefinition::create('string')
    ->setLabel(t('Name'))
    ->setDescription(t('The name of the Workspace pointer entity.'))
    ->setSettings([
    'max_length' => 512,
    'text_processing' => 0,
  ])
    ->setRevisionable(TRUE)
    ->setDefaultValue('')
    ->setDisplayConfigurable('form', FALSE)
    ->setDisplayConfigurable('view', FALSE);
  $fields['created'] = BaseFieldDefinition::create('created')
    ->setLabel(t('Created'))
    ->setDescription(t('The time that the entity was created.'))
    ->setRevisionable(TRUE);
  $fields['changed'] = BaseFieldDefinition::create('changed')
    ->setLabel(t('Changed'))
    ->setDescription(t('The time that the entity was last edited.'))
    ->setRevisionable(TRUE);
  $fields['workspace_pointer'] = BaseFieldDefinition::create('entity_reference')
    ->setLabel(t('Workspace'))
    ->setDescription(t('A reference to the workspace'))
    ->setSetting('target_type', 'workspace')
    ->setRevisionable(TRUE);
  // This field will keep the information about the availability of the
  // remote workspace, which is checked on every cron run. This value is not
  // used when doing the replication, because during replication the
  // availability of the remote workspaces is checked with HTTP requests.
  // This value is used to restrict the user to select from UI a remote
  // workspace as target when it is not available.
  $fields['workspace_available'] = BaseFieldDefinition::create('boolean')
    ->setLabel(new TranslatableMarkup('Workspace available'))
    ->setDescription(t('Keeps the availability of the referenced ' . 'workspace, this flag might not be accurate, the availability should ' . 'be checked regularly (it is checked on cron run).'))
    ->setRevisionable(TRUE)
    ->setDefaultValue(TRUE);
  return $fields;
}