I see that there is an ImageType field, machine name 'image'
, with a namespace of Drupal\image\Plugin\Field\FieldType
. However, I can't seem to make use of it when creating a custom field and defining the property in the FieldType
class.
I tried putting DataDefinition::create('image')
but this later causes an abort complaining about the field type not existing, and I notice that the namespace is not referenced.
What are the correct types to use for an image field in the property section of the FieldType
, in the schema of the FieldType
, and in the FieldWidget
?
Exporting an image field config from a bundle yields:
uuid: eecbe6e5-89d5-4708-b9c9-79f77b3cedf8
langcode: en
status: true
dependencies:
module:
- file
- image
- node
_core:
default_config_hash: SkXIPKZYiIMMtnBmfnxk58RYfbZ8cHSw5NZPY_JByME
id: node.field_image
field_name: field_image
entity_type: node
type: image
settings:
uri_scheme: public
default_image:
uuid: null
alt: ''
title: ''
width: null
height: null
target_type: file
display_field: false
display_default: false
module: image
locked: false
cardinality: 1
translatable: true
indexes:
target_id:
- target_id
persist_with_no_fields: false
custom_storage: false
and looking at the image module's fielditem:
* @FieldType(
* id = "image",
* label = @Translation("Image"),
* description = @Translation("This field stores the ID of an image file as an integer value."),
* category = @Translation("Reference"),
* default_widget = "image_image",
* default_formatter = "image",
* column_groups = {
* "file" = {
* "label" = @Translation("File"),
* "columns" = {
* "target_id", "width", "height"
* },
* "require_all_groups_for_translation" = TRUE
* },
* "alt" = {
* "label" = @Translation("Alt"),
* "translatable" = TRUE
* },
* "title" = {
* "label" = @Translation("Title"),
* "translatable" = TRUE
* },
* },
* list_class = "\Drupal\file\Plugin\Field\FieldType\FileFieldItemList",
* constraints = {"ReferenceAccess" = {}, "FileValidation" = {}}
* )
*/
image
, the main property istarget_id
inherited from the file field type. The easiest way to define a custom image field would be to extend the three core image field classes another time, now in the namespace of your module.