public static function BrightcovePlaylist::baseFieldDefinitions in Brightcove Video Connect 8
Same name and namespace in other branches
- 8.2 src/Entity/BrightcovePlaylist.php \Drupal\brightcove\Entity\BrightcovePlaylist::baseFieldDefinitions()
- 3.x src/Entity/BrightcovePlaylist.php \Drupal\brightcove\Entity\BrightcovePlaylist::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/ BrightcovePlaylist.php, line 368
Class
- BrightcovePlaylist
- Defines the Brightcove Playlist.
Namespace
Drupal\brightcove\EntityCode
public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
// Set weights based on the real order of the fields.
$weight = -30;
/*
* Drupal-specific fields first.
*
* bcplid - Brightcove Playlist ID (Drupal-internal).
* uuid - UUID.
* - "Playlist type" comes here, but that's a Brightcove-specific field.
* - Title comes here, but that's the "Name" field from Brightcove.
* langcode - Language.
* api_client - Entityreference to BrightcoveAPIClient.
* - Brightcove fields come here.
* uid - Author.
* created - Posted.
* changed - Last modified.
*/
$fields['bcplid'] = BaseFieldDefinition::create('integer')
->setLabel(t('ID'))
->setDescription(t('The Drupal entity ID of the Brightcove Playlist.'))
->setReadOnly(TRUE);
$fields['uuid'] = BaseFieldDefinition::create('uuid')
->setLabel(t('UUID'))
->setDescription(t('The Brightcove Playlist UUID.'))
->setReadOnly(TRUE);
$fields['api_client'] = BaseFieldDefinition::create('entity_reference')
->setLabel(t('API Client'))
->setDescription(t('Brightcove API credentials (account) to use.'))
->setRequired(TRUE)
->setSetting('target_type', 'brightcove_api_client')
->setDisplayOptions('form', [
'type' => 'options_select',
'weight' => ++$weight,
])
->setDisplayOptions('view', [
'type' => 'hidden',
'label' => 'inline',
'weight' => $weight,
])
->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE);
$fields['player'] = BaseFieldDefinition::create('entity_reference')
->setLabel(t('Player'))
->setDescription(t('Brightcove Player to be used for playback.'))
->setSetting('target_type', 'brightcove_player')
->setDisplayOptions('form', [
'type' => 'options_select',
'weight' => ++$weight,
])
->setDisplayOptions('view', [
'type' => 'hidden',
'label' => 'inline',
'weight' => $weight,
])
->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE);
$fields['type'] = BaseFieldDefinition::create('list_string')
->setLabel(t('Playlist Type'))
->setRequired(TRUE)
->setDefaultValue('EXPLICIT')
->setSetting('allowed_values_function', [
self::class,
'typeAllowedValues',
])
->setDisplayOptions('form', [
'type' => 'options_select',
'weight' => ++$weight,
])
->setDisplayOptions('view', [
'type' => 'list_default',
'label' => 'inline',
'weight' => $weight,
])
->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE);
$fields['name'] = BaseFieldDefinition::create('string')
->setLabel(t('Playlist name'))
->setDescription(t('Title of the playlist.'))
->setRequired(TRUE)
->setSettings([
'max_length' => 250,
'text_processing' => 0,
])
->setDisplayOptions('form', [
'type' => 'string_textfield',
'weight' => ++$weight,
])
->setDisplayOptions('view', [
'type' => 'string',
'label' => 'hidden',
'weight' => $weight,
])
->setDisplayConfigurable('form', TRUE);
$fields['langcode'] = BaseFieldDefinition::create('language')
->setLabel(t('Language code'))
->setDescription(t('The language code for the Brightcove Video.'))
->setDisplayOptions('form', [
'type' => 'language_select',
'weight' => ++$weight,
])
->setDisplayConfigurable('form', TRUE);
/*
* Additional Brightcove fields, based on
* @see http://docs.brightcove.com/en/video-cloud/cms-api/references/cms-api/versions/v1/index.html#api-playlistGroup-Get_Playlists
*
* description - string - Playlist description
* favorite - boolean - Whether playlist is in favorites list
* playlist_id - string - The playlist id
* name - string - The playlist name
* reference_id - string - The playlist reference id
* type - string - The playlist type: EXPLICIT or smart playlist type
* videos - entityref/string array of video ids (EXPLICIT playlists only)
* search - string - Search string to retrieve the videos (smart playlists
* only)
*/
$fields['favorite'] = BaseFieldDefinition::create('boolean')
->setLabel(t('Show Playlist in Sidebar'))
->setDescription(t('Whether playlist is in favorites list'))
->setDefaultValue(FALSE)
->setDisplayOptions('view', [
'type' => 'string',
'label' => 'inline',
'weight' => ++$weight,
])
->setDisplayConfigurable('view', TRUE);
$fields['playlist_id'] = BaseFieldDefinition::create('string')
->setLabel(t('Playlist ID'))
->setDescription(t('Unique Playlist ID assigned by Brightcove.'))
->setReadOnly(TRUE)
->setDisplayOptions('view', [
'type' => 'string',
'label' => 'inline',
'weight' => ++$weight,
])
->setDisplayConfigurable('view', TRUE);
$fields['reference_id'] = BaseFieldDefinition::create('string')
->setLabel(t('Reference ID'))
->addConstraint('UniqueField')
->setDescription(t('Value specified must be unique'))
->setSettings([
'max_length' => 150,
'text_processing' => 0,
])
->setDisplayOptions('form', [
'type' => 'string_textfield',
'weight' => ++$weight,
])
->setDisplayOptions('view', [
'type' => 'string',
'label' => 'inline',
'weight' => $weight,
])
->setDefaultValueCallback(static::class . '::getDefaultReferenceId')
->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE);
$fields['description'] = BaseFieldDefinition::create('string_long')
->setLabel(t('Short description'))
->setDisplayOptions('form', [
'type' => 'string_textarea',
'weight' => ++$weight,
])
->setDisplayOptions('view', [
'type' => 'basic_string',
'label' => 'above',
'weight' => $weight,
])
->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE)
->addPropertyConstraints('value', [
'Length' => [
'max' => 250,
],
]);
$fields['tags_search_condition'] = BaseFieldDefinition::create('list_string')
->setLabel(t('Tags search condition'))
->setRequired(TRUE)
->setDefaultValue(self::TAG_SEARCH_CONTAINS_ONE_OR_MORE)
->setSetting('allowed_values', [
self::TAG_SEARCH_CONTAINS_ONE_OR_MORE => t('contains one or more'),
self::TAG_SEARCH_CONTAINS_ALL => t('contains all'),
])
->setDisplayOptions('form', [
'type' => 'options_select',
'weight' => ++$weight,
])
->setDisplayConfigurable('form', TRUE);
$fields['tags'] = BaseFieldDefinition::create('entity_reference')
->setLabel(t('Tags'))
->setCardinality(FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED)
->setSettings([
'target_type' => 'taxonomy_term',
'handler_settings' => [
'target_bundles' => [
BrightcoveVideo::TAGS_VID => BrightcoveVideo::TAGS_VID,
],
'auto_create' => TRUE,
],
])
->setDisplayOptions('form', [
'type' => 'entity_reference_autocomplete',
'weight' => ++$weight,
'settings' => [
'autocomplete_type' => 'tags',
],
])
->setDisplayOptions('view', [
'type' => 'entity_reference_label',
'label' => 'above',
'weight' => $weight,
])
->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE);
$fields['videos'] = BaseFieldDefinition::create('entity_reference')
->setLabel(t('Videos'))
->setDescription(t('Videos in the playlist.'))
->setCardinality(FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED)
->setSettings([
'target_type' => 'brightcove_video',
'handler' => 'views',
'handler_settings' => [
'view' => [
'view_name' => 'brightcove_videos_by_api_client',
'display_name' => 'videos_entity_reference',
'arguments' => [],
],
],
])
->setDisplayOptions('form', [
'type' => 'entity_reference_autocomplete',
'weight' => ++$weight,
])
->setDisplayOptions('view', [
'type' => 'string',
'label' => 'above',
'weight' => $weight,
])
->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', 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('Drupal\\brightcove\\Entity\\BrightcovePlaylist::getCurrentUserId')
->setTranslatable(TRUE)
->setDisplayOptions('view', [
'label' => 'hidden',
'type' => 'author',
'weight' => ++$weight,
])
->setDisplayOptions('form', [
'type' => 'entity_reference_autocomplete',
'weight' => $weight,
'settings' => [
'match_operator' => 'CONTAINS',
'size' => '60',
'autocomplete_type' => 'tags',
'placeholder' => '',
],
])
->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE);
$fields['status'] = BaseFieldDefinition::create('boolean')
->setLabel(t('Publishing status'))
->setDescription(t('A boolean indicating whether the Brightcove Playlist is published.'))
->setDefaultValue(TRUE);
$fields['created'] = BaseFieldDefinition::create('created')
->setLabel(t('Created'))
->setDescription(t('The time that the Brightcove Playlist was created.'))
->setTranslatable(TRUE)
->setDisplayOptions('view', [
'label' => 'inline',
'type' => 'timestamp',
'weight' => ++$weight,
])
->setDisplayConfigurable('view', TRUE);
$fields['changed'] = BaseFieldDefinition::create('changed')
->setLabel(t('Changed'))
->setDescription(t('The time that the Brightcove Playlist was last edited.'))
->setTranslatable(TRUE);
return $fields;
}