You are here

public static function Workspace::baseFieldDefinitions in Opigno Moxtra 8

Same name and namespace in other branches
  1. 3.x src/Entity/Workspace.php \Drupal\opigno_moxtra\Entity\Workspace::baseFieldDefinitions()

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/Workspace.php, line 191

Class

Workspace
Defines the Workspace entity.

Namespace

Drupal\opigno_moxtra\Entity

Code

public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
  $fields['id'] = BaseFieldDefinition::create('integer')
    ->setLabel(t('ID'))
    ->setDescription(t('The ID of the Workspace entity.'))
    ->setReadOnly(TRUE);
  $fields['uuid'] = BaseFieldDefinition::create('uuid')
    ->setLabel(t('UUID'))
    ->setDescription(t('The UUID of the Workspace entity.'))
    ->setReadOnly(TRUE);
  $fields['user_id'] = BaseFieldDefinition::create('entity_reference')
    ->setLabel(t('Owner'))
    ->setDescription(t('The owner of the Workspace entity.'))
    ->setSettings([
    'handler' => 'default',
    'target_type' => 'user',
  ])
    ->setReadOnly(TRUE);
  $fields['name'] = BaseFieldDefinition::create('string')
    ->setLabel(t('Name'))
    ->setDescription(t('The name of the Workspace entity.'))
    ->setSettings([
    'default_value' => '',
    'max_length' => 255,
    'text_processing' => 0,
  ])
    ->setRequired(TRUE);
  $fields['binder_id'] = BaseFieldDefinition::create('string')
    ->setLabel(t('Binder ID'))
    ->setDescription(t('The ID of the Moxtra binder of the Workspace entity.'))
    ->setSettings([
    'max_length' => 255,
    'text_processing' => 0,
  ]);
  $fields['auto_register'] = BaseFieldDefinition::create('boolean')
    ->setLabel(t('Automatically register'))
    ->setDescription(t('Automatically register all users of that workspace.'))
    ->setRevisionable(TRUE)
    ->setTranslatable(TRUE)
    ->setDefaultValue(TRUE);
  $fields['members'] = BaseFieldDefinition::create('entity_reference')
    ->setLabel(t('Members'))
    ->setDescription(t('The members of the Workspace entity.'))
    ->setSettings([
    'handler' => 'default',
    'target_type' => 'user',
  ])
    ->setCardinality(FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
  $fields['training'] = BaseFieldDefinition::create('entity_reference')
    ->setLabel(t('Training'))
    ->setDescription(t('The related Training of the Workspace entity.'))
    ->setSettings([
    'target_type' => 'group',
    'handler' => 'default:group',
    'handler_settings' => [
      'target_bundles' => [
        'learning_path' => 'learning_path',
      ],
      'sort' => [
        'field' => '_none',
      ],
    ],
    'default_value' => 0,
  ])
    ->setCardinality(FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
  return $fields;
}