You are here

public static function ILT::baseFieldDefinitions in Opigno Instructor-led Trainings 3.x

Same name and namespace in other branches
  1. 8 src/Entity/ILT.php \Drupal\opigno_ilt\Entity\ILT::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/ILT.php, line 362

Class

ILT
Defines the ILT entity.

Namespace

Drupal\opigno_ilt\Entity

Code

public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
  $fields['id'] = BaseFieldDefinition::create('integer')
    ->setLabel(t('ID'))
    ->setDescription(t('The ID of the ILT entity.'))
    ->setReadOnly(TRUE);
  $fields['uuid'] = BaseFieldDefinition::create('uuid')
    ->setLabel(t('UUID'))
    ->setDescription(t('The UUID of the ILT entity.'))
    ->setReadOnly(TRUE);
  $fields['user_id'] = BaseFieldDefinition::create('entity_reference')
    ->setLabel(t('Owner'))
    ->setDescription(t('The owner of the ILT entity.'))
    ->setSettings([
    'target_type' => 'user',
    'handler' => 'default',
  ])
    ->setReadOnly(TRUE);
  $fields['title'] = BaseFieldDefinition::create('string')
    ->setLabel(t('Title'))
    ->setDescription(t('The title of the ILT entity.'))
    ->setSettings([
    'default_value' => '',
    'max_length' => 255,
    'text_processing' => 0,
  ])
    ->setRequired(TRUE)
    ->setDisplayConfigurable('form', TRUE)
    ->setDisplayConfigurable('view', TRUE);
  $fields['date'] = BaseFieldDefinition::create('daterange')
    ->setName('date')
    ->setLabel(t('Date'))
    ->setRequired(TRUE)
    ->setDisplayConfigurable('form', TRUE)
    ->setDisplayConfigurable('view', TRUE);
  $fields['place'] = BaseFieldDefinition::create('string')
    ->setLabel(t('Place'))
    ->setDescription(t('The address of the ILT entity.'))
    ->setSettings([
    'default_value' => '',
    'max_length' => 255,
    'text_processing' => 0,
  ])
    ->setRequired(TRUE)
    ->setDisplayConfigurable('form', TRUE)
    ->setDisplayConfigurable('view', TRUE);
  $fields['trainer'] = BaseFieldDefinition::create('entity_reference')
    ->setLabel(t('Trainer'))
    ->setDescription(t('The trainer of the ILT entity.'))
    ->setSettings([
    'target_type' => 'user',
    'handler' => 'default',
  ])
    ->setReadOnly(TRUE);
  $fields['training'] = BaseFieldDefinition::create('entity_reference')
    ->setLabel(t('Related training'))
    ->setDescription(t('The related training of the ILT entity.'))
    ->setSettings([
    'target_type' => 'group',
    'handler' => 'default:group',
    'handler_settings' => [
      'target_bundles' => [
        'learning_path' => 'learning_path',
      ],
      'sort' => [
        'field' => '_none',
      ],
    ],
  ]);
  $fields['calendar_event'] = BaseFieldDefinition::create('entity_reference')
    ->setLabel(t('Related calendar event'))
    ->setDescription(t('The related calendar event of the ILT entity.'))
    ->setSettings([
    'target_type' => 'opigno_calendar_event',
    'handler' => 'default',
  ]);
  $fields['members'] = BaseFieldDefinition::create('entity_reference')
    ->setLabel(t('Members'))
    ->setDescription(t('The members of the ILT entity.'))
    ->setSettings([
    'target_type' => 'user',
    'handler' => 'default',
  ])
    ->setCardinality(FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
  $fields['notified_members'] = BaseFieldDefinition::create('entity_reference')
    ->setLabel(t('Notified Members'))
    ->setDescription(t('Members of the ILT entity that marked as notified by email.'))
    ->setSettings([
    'target_type' => 'user',
    'handler' => 'default',
  ])
    ->setCardinality(FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
  return $fields;
}