public static File::baseFieldDefinitions(EntityTypeInterface $entity_type)
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\EntityManagerInterface::getFieldDefinitions()
\Drupal\Core\Entity\FieldableEntityInterface::bundleFieldDefinitions()
File
- core/modules/file/src/Entity/File.php, line 222
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['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'] = BaseFieldDefinition::create('entity_reference') ->setLabel(t('User ID')) ->setDescription(t('The user ID of the file.')) ->setSetting('target_type', 'user'); $fields['filename'] = BaseFieldDefinition::create('string') ->setLabel(t('Filename')) ->setDescription(t('Name of the file with no path components.')); $fields['uri'] = BaseFieldDefinition::create('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; }
Please login to continue.