function File::baseFieldDefinitions

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

Overrides ContentEntityBase::baseFieldDefinitions

File

core/modules/file/src/Entity/File.php, line 226

Class

File
Defines the file entity class.

Namespace

Drupal\file\Entity

Code

public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
    
    /** @var \Drupal\Core\Field\BaseFieldDefinition[] $fields */
    $fields = parent::baseFieldDefinitions($entity_type);
    $fields += static::ownerBaseFieldDefinitions($entity_type);
    $fields['fid']->setLabel(t('File ID'))
        ->setDescription(t('The file ID.'));
    $fields['uuid']->setDescription(t('The file UUID.'));
    $fields['langcode']->setLabel(t('Language code'))
        ->setDescription(t('The file language code.'));
    $fields['uid']->setDescription(t('The user ID of the file.'));
    $fields['filename'] = BaseFieldDefinition::create('string')->setLabel(t('Filename'))
        ->setDescription(t('Name of the file with no path components.'));
    $fields['uri'] = BaseFieldDefinition::create('file_uri')->setLabel(t('URI'))
        ->setDescription(t('The URI to access the file (either local or remote).'))
        ->setSetting('max_length', 255)
        ->setSetting('case_sensitive', TRUE)
        ->addConstraint('FileUriUnique');
    $fields['filemime'] = BaseFieldDefinition::create('string')->setLabel(t('File MIME type'))
        ->setSetting('is_ascii', TRUE)
        ->setDescription(t("The file's MIME type."));
    $fields['filesize'] = BaseFieldDefinition::create('integer')->setLabel(t('File size'))
        ->setDescription(t('The size of the file in bytes.'))
        ->setSetting('unsigned', TRUE)
        ->setSetting('size', 'big');
    $fields['status'] = BaseFieldDefinition::create('boolean')->setLabel(t('Status'))
        ->setDescription(t('The status of the file, temporary (FALSE) and permanent (TRUE).'))
        ->setDefaultValue(FALSE);
    $fields['created'] = BaseFieldDefinition::create('created')->setLabel(t('Created'))
        ->setDescription(t('The timestamp that the file was created.'));
    $fields['changed'] = BaseFieldDefinition::create('changed')->setLabel(t('Changed'))
        ->setDescription(t('The timestamp that the file was last changed.'));
    return $fields;
}

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