You are here

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

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

Class

BrightcoveCustomField
Defines the Brightcove Custom Field.

Namespace

Drupal\brightcove\Entity

Code

public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
  $fields['bccfid'] = BaseFieldDefinition::create('integer')
    ->setLabel(t('ID'))
    ->setDescription(t('The Drupal entity ID of the Brightcove Custom Field.'))
    ->setReadOnly(TRUE);
  $fields['uuid'] = BaseFieldDefinition::create('uuid')
    ->setLabel(t('UUID'))
    ->setDescription(t('The Brightcove Custom Field UUID.'))
    ->setReadOnly(TRUE);
  $fields['name'] = BaseFieldDefinition::create('string')
    ->setLabel(t('Custom Field name'))
    ->setDescription(t('The name of the Brightcove Custom Field.'));
  $fields['langcode'] = BaseFieldDefinition::create('language')
    ->setLabel(t('Language code'))
    ->setDescription(t('The language code for the Brightcove Custom Field.'));
  $fields['api_client'] = BaseFieldDefinition::create('entity_reference')
    ->setLabel(t('API Client'))
    ->setDescription(t('API Client where the Custom Field belongs.'))
    ->setRequired(TRUE)
    ->setSetting('target_type', 'brightcove_api_client');
  $fields['uid'] = BaseFieldDefinition::create('entity_reference')
    ->setLabel(t('Authored by'))
    ->setDescription(t('The username of the Brightcove Custom Field author.'))
    ->setSetting('target_type', 'user')
    ->setDefaultValueCallback('Drupal\\brightcove\\Entity\\BrightcoveCustomField::getCurrentUserId')
    ->setTranslatable(TRUE);
  $fields['created'] = BaseFieldDefinition::create('created')
    ->setLabel(t('Created'))
    ->setDescription(t('The time that the Brightcove Custom Field was created.'))
    ->setTranslatable(TRUE);
  $fields['changed'] = BaseFieldDefinition::create('changed')
    ->setLabel(t('Changed'))
    ->setDescription(t('The time that the Brightcove Custom Field was last edited.'))
    ->setTranslatable(TRUE);
  $fields['status'] = BaseFieldDefinition::create('boolean')
    ->setLabel(t('Status'))
    ->setRequired(TRUE)
    ->setDefaultValue(TRUE)
    ->setSettings([
    'on_label' => t('Active'),
    'off_label' => t('Inactive'),
  ]);
  $fields['custom_field_id'] = BaseFieldDefinition::create('string')
    ->setLabel(t('Custom Field ID'))
    ->setDescription(t('Unique Custom Field ID assigned by Brightcove.'))
    ->setReadOnly(TRUE);
  $fields['description'] = BaseFieldDefinition::create('string')
    ->setLabel(t('Description'));
  $fields['enum_values'] = BaseFieldDefinition::create('string')
    ->setLabel(t('Enum values'))
    ->setDescription(t('Max 150 enum value per custom field'))
    ->setCardinality(FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
  $fields['required'] = BaseFieldDefinition::create('boolean')
    ->setLabel(t('Required'))
    ->setDefaultValue(FALSE);
  $fields['type'] = BaseFieldDefinition::create('string')
    ->setLabel(t('Type'));
  return $fields;
}