Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. File.php

function 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;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal