A file field is an entity reference field pointing to the File
entity (or in D8.4 to the Media
entity). To build such a file field extend FileItem
(which parent is EntityReferenceItem
). An example for this would be the image field ImageItem
, which is a compound field adding properties like title, alt, height and width:
ImageItem::propertyDefinitions()
public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition) {
$properties = parent::propertyDefinitions($field_definition);
unset($properties['display']);
unset($properties['description']);
$properties['alt'] = DataDefinition::create('string')
->setLabel(t('Alternative text'))
->setDescription(t("Alternative image text, for the image's 'alt' attribute."));
$properties['title'] = DataDefinition::create('string')
->setLabel(t('Title'))
->setDescription(t("Image title text, for the image's 'title' attribute."));
$properties['width'] = DataDefinition::create('integer')
->setLabel(t('Width'))
->setDescription(t('The width of the image in pixels.'));
$properties['height'] = DataDefinition::create('integer')
->setLabel(t('Height'))
->setDescription(t('The height of the image in pixels.'));
return $properties;
}
The properties for the referencing part are inherited from the parent.