You are here

public static function BrightcoveTextTrack::baseFieldDefinitions in Brightcove Video Connect 8

Same name and namespace in other branches
  1. 8.2 src/Entity/BrightcoveTextTrack.php \Drupal\brightcove\Entity\BrightcoveTextTrack::baseFieldDefinitions()
  2. 3.x src/Entity/BrightcoveTextTrack.php \Drupal\brightcove\Entity\BrightcoveTextTrack::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/BrightcoveTextTrack.php, line 295

Class

BrightcoveTextTrack
Defines the Brightcove Text Track entity.

Namespace

Drupal\brightcove\Entity

Code

public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
  $weight = -30;
  $fields['bcttid'] = BaseFieldDefinition::create('integer')
    ->setLabel(t('ID'))
    ->setDescription(t('The ID of the Brightcove Text Track entity.'))
    ->setReadOnly(TRUE);
  $fields['name'] = BaseFieldDefinition::create('string')
    ->setLabel(t('Name'))
    ->setDescription(t('Generated name for the Text Track.'))
    ->setRequired(TRUE);
  $fields['uuid'] = BaseFieldDefinition::create('uuid')
    ->setLabel(t('UUID'))
    ->setDescription(t('The UUID of the Brightcove Text Track entity.'))
    ->setReadOnly(TRUE);
  $fields['text_track_id'] = BaseFieldDefinition::create('string')
    ->setLabel(t('Text Track ID'))
    ->setDescription(t('Unique Text Track ID assigned by Brightcove.'))
    ->setReadOnly(TRUE)
    ->setDisplayOptions('view', [
    'type' => 'string',
    'label' => 'inline',
    'weight' => ++$weight,
  ])
    ->setDisplayConfigurable('view', TRUE);
  $fields['webvtt_file'] = BaseFieldDefinition::create('file')
    ->setLabel(t('WebVTT file'))
    ->setRequired(TRUE)
    ->setSettings([
    'file_extensions' => 'vtt',
    'file_directory' => '[random:hash:md5]',
  ])
    ->setDisplayOptions('form', [
    'type' => 'file_generic',
    'weight' => ++$weight,
  ])
    ->setDisplayOptions('view', [
    'type' => 'file_url_plain',
    'label' => 'inline',
    'weight' => $weight,
  ])
    ->setDisplayConfigurable('form', TRUE)
    ->setDisplayConfigurable('view', TRUE);
  $fields['source'] = BaseFieldDefinition::create('link')
    ->setLabel(t('Source'))
    ->setDescription(t('Source text track.'))
    ->setSettings([
    'max_length' => 500,
    'link_type' => LinkItemInterface::LINK_GENERIC,
    'title' => DRUPAL_DISABLED,
  ])
    ->setDisplayOptions('view', [
    'type' => 'link',
    'label' => 'above',
    'weight' => $weight,
    'settings' => [
      'rel' => TRUE,
      'target' => '_blank',
    ],
  ])
    ->setDisplayConfigurable('view', TRUE);
  $fields['source_language'] = BaseFieldDefinition::create('string')
    ->setLabel(t('Language'))
    ->setDescription(t('ISO-639-1 language code with optional ISO-3166 country name (en, en-US, de, de-DE).'))
    ->setRequired(TRUE)
    ->setSettings([
    'max_length' => 10,
    'text_processing' => 0,
  ])
    ->setDisplayOptions('view', [
    'label' => 'inline',
    'type' => 'string',
    'weight' => ++$weight,
  ])
    ->setDisplayOptions('form', [
    'type' => 'string_textfield',
    'weight' => $weight,
  ])
    ->setDisplayConfigurable('form', TRUE)
    ->setDisplayConfigurable('view', TRUE);
  $fields['label'] = BaseFieldDefinition::create('string')
    ->setLabel(t('Label'))
    ->setDescription(t('Title to be displayed in the player menu.'))
    ->setSettings([
    'max_length' => 255,
    'text_processing' => 0,
  ])
    ->setDefaultValue('')
    ->setDisplayOptions('view', [
    'label' => 'above',
    'type' => 'string',
    'weight' => ++$weight,
  ])
    ->setDisplayOptions('form', [
    'type' => 'string_textfield',
    'weight' => $weight,
  ])
    ->setDisplayConfigurable('form', TRUE)
    ->setDisplayConfigurable('view', TRUE);
  $fields['kind'] = BaseFieldDefinition::create('list_string')
    ->setLabel(t('Kind'))
    ->setDescription(t('How the vtt file is meant to be used.'))
    ->setRequired(TRUE)
    ->setDefaultValue(self::KIND_CAPTIONS)
    ->setSetting('allowed_values', [
    self::KIND_CAPTIONS => 'captions',
    self::KIND_SUBTITLES => 'subtitles',
    self::KIND_DESCRIPTION => 'descriptions',
    self::KIND_CHAPTERS => 'chapters',
    self::KIND_METADATA => 'metadata',
  ])
    ->setDisplayOptions('form', [
    'type' => 'options_select',
    'weight' => ++$weight,
  ])
    ->setDisplayOptions('view', [
    'type' => 'string',
    'label' => 'inline',
    'weight' => $weight,
  ])
    ->setDisplayConfigurable('form', TRUE)
    ->setDisplayConfigurable('view', TRUE);
  $fields['mime_type'] = BaseFieldDefinition::create('string')
    ->setLabel(t('MIME type'))
    ->setDescription(t('MIME type of the source text track.'))
    ->setReadOnly(TRUE)
    ->setDisplayOptions('view', [
    'type' => 'string',
    'label' => 'inline',
    'weight' => ++$weight,
  ])
    ->setDisplayConfigurable('view', TRUE);
  $fields['asset_id'] = BaseFieldDefinition::create('string')
    ->setLabel(t('Asset ID'))
    ->setDescription(t('Asset ID assigned by Brightcove.'))
    ->setReadOnly(TRUE)
    ->setDisplayOptions('view', [
    'type' => 'string',
    'label' => 'inline',
    'weight' => ++$weight,
  ])
    ->setDisplayConfigurable('view', TRUE);
  $fields['sources'] = BaseFieldDefinition::create('link')
    ->setLabel(t('Sources'))
    ->setDescription(t('Address of the track file(s).'))
    ->setCardinality(FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED)
    ->setSettings([
    'max_length' => 500,
    'link_type' => LinkItemInterface::LINK_GENERIC,
    'title' => DRUPAL_DISABLED,
  ])
    ->setDisplayOptions('view', [
    'type' => 'link',
    'label' => 'above',
    'weight' => $weight,
    'settings' => [
      'rel' => TRUE,
      'target' => '_blank',
    ],
  ])
    ->setDisplayConfigurable('view', TRUE);
  $fields['default_text_track'] = BaseFieldDefinition::create('boolean')
    ->setLabel(t('Default'))
    ->setDescription(t('Setting this to true makes this the default captions file in the player menu.'))
    ->setDefaultValue(FALSE)
    ->setSettings([
    'on_label' => t('Yes'),
    'off_label' => t('No'),
  ])
    ->setDisplayOptions('form', [
    'type' => 'boolean_checkbox',
    'weight' => ++$weight,
    'settings' => [
      'display_label' => TRUE,
    ],
  ])
    ->setDisplayOptions('view', [
    'type' => 'string',
    'label' => 'inline',
    'weight' => $weight,
  ])
    ->setDisplayConfigurable('form', TRUE)
    ->setDisplayConfigurable('view', TRUE);
  $fields['status'] = BaseFieldDefinition::create('boolean')
    ->setLabel(t('Publishing status'))
    ->setDescription(t('A boolean indicating whether the Brightcove Text Track is published.'))
    ->setDefaultValue(TRUE);
  $fields['uid'] = BaseFieldDefinition::create('entity_reference')
    ->setLabel(t('Authored by'))
    ->setDescription(t('The username of the Brightcove Playlist author.'))
    ->setSetting('target_type', 'user')
    ->setDefaultValueCallback(self::class . '::getCurrentUserId')
    ->setTranslatable(TRUE)
    ->setDisplayOptions('form', [
    'type' => 'entity_reference_autocomplete',
    'weight' => ++$weight,
    'settings' => [
      'match_operator' => 'CONTAINS',
      'size' => '60',
      'autocomplete_type' => 'tags',
      'placeholder' => '',
    ],
  ])
    ->setDisplayOptions('view', [
    'type' => 'author',
    'label' => 'inline',
    'weight' => $weight,
  ])
    ->setDisplayConfigurable('form', TRUE)
    ->setDisplayConfigurable('view', TRUE);
  $fields['langcode'] = BaseFieldDefinition::create('language')
    ->setLabel(t('Language code'))
    ->setDescription(t('The language code for the Brightcove Text Track entity.'))
    ->setDisplayOptions('form', [
    'type' => 'language_select',
    'weight' => ++$weight,
  ])
    ->setDisplayConfigurable('form', TRUE);
  $fields['created'] = BaseFieldDefinition::create('created')
    ->setLabel(t('Created'))
    ->setDescription(t('The time that the entity was created.'));
  $fields['changed'] = BaseFieldDefinition::create('changed')
    ->setLabel(t('Changed'))
    ->setDescription(t('The time that the entity was last edited.'));
  return $fields;
}