function Media::baseFieldDefinitions

Same name in other branches
  1. 9 core/modules/media/src/Entity/Media.php \Drupal\media\Entity\Media::baseFieldDefinitions()
  2. 8.9.x core/modules/media/src/Entity/Media.php \Drupal\media\Entity\Media::baseFieldDefinitions()
  3. 11.x core/modules/media/src/Entity/Media.php \Drupal\media\Entity\Media::baseFieldDefinitions()

Overrides EditorialContentEntityBase::baseFieldDefinitions

File

core/modules/media/src/Entity/Media.php, line 478

Class

Media
Defines the media entity class.

Namespace

Drupal\media\Entity

Code

public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
    $fields = parent::baseFieldDefinitions($entity_type);
    $fields += static::ownerBaseFieldDefinitions($entity_type);
    $fields['name'] = BaseFieldDefinition::create('string')->setLabel(t('Name'))
        ->setRequired(TRUE)
        ->setTranslatable(TRUE)
        ->setRevisionable(TRUE)
        ->setDefaultValue('')
        ->setSetting('max_length', 255)
        ->setDisplayOptions('form', [
        'type' => 'string_textfield',
        'weight' => -5,
    ])
        ->setDisplayConfigurable('form', TRUE)
        ->setDisplayConfigurable('view', TRUE);
    $fields['thumbnail'] = BaseFieldDefinition::create('image')->setLabel(t('Thumbnail'))
        ->setDescription(t('The thumbnail of the media item.'))
        ->setRevisionable(TRUE)
        ->setTranslatable(TRUE)
        ->setDisplayOptions('view', [
        'type' => 'image',
        'weight' => 5,
        'label' => 'hidden',
        'settings' => [
            'image_style' => 'thumbnail',
        ],
    ])
        ->setDisplayConfigurable('view', TRUE)
        ->setReadOnly(TRUE);
    $fields['uid']->setLabel(t('Authored by'))
        ->setDescription(t('The user ID of the author.'))
        ->setRevisionable(TRUE)
        ->setDisplayOptions('form', [
        'type' => 'entity_reference_autocomplete',
        'weight' => 5,
        'settings' => [
            'match_operator' => 'CONTAINS',
            'size' => '60',
            'autocomplete_type' => 'tags',
            'placeholder' => '',
        ],
    ])
        ->setDisplayConfigurable('form', TRUE)
        ->setDisplayOptions('view', [
        'label' => 'hidden',
        'type' => 'author',
        'weight' => 0,
    ])
        ->setDisplayConfigurable('view', TRUE);
    $fields['status']->setDisplayOptions('form', [
        'type' => 'boolean_checkbox',
        'settings' => [
            'display_label' => TRUE,
        ],
        'weight' => 100,
    ])
        ->setDisplayConfigurable('form', TRUE);
    $fields['created'] = BaseFieldDefinition::create('created')->setLabel(t('Authored on'))
        ->setDescription(t('The time the media item was created.'))
        ->setTranslatable(TRUE)
        ->setRevisionable(TRUE)
        ->setDefaultValueCallback(static::class . '::getRequestTime')
        ->setDisplayOptions('form', [
        'type' => 'datetime_timestamp',
        'weight' => 10,
    ])
        ->setDisplayConfigurable('form', TRUE)
        ->setDisplayOptions('view', [
        'label' => 'hidden',
        'type' => 'timestamp',
        'weight' => 0,
    ])
        ->setDisplayConfigurable('view', TRUE);
    $fields['changed'] = BaseFieldDefinition::create('changed')->setLabel(t('Changed'))
        ->setDescription(t('The time the media item was last edited.'))
        ->setTranslatable(TRUE)
        ->setRevisionable(TRUE);
    return $fields;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.