You are here

Drupal 8 (alpha 11) Field class hierarchy

I was getting so lost that that I had to step back for a few hours and create this map. It was extremely useful!

TypedData (has a $definition)
 - Any (not used)
 - Language
 - PrimitiveBase
   - String
     - Email
   - Boolean
   - Integer
     - TimeStamp
   - Float
   - Binary 
 - ItemList
   - FieldItemlist has $entity property and instance settings
     - DateTimeFieldItemList //list_class for the datetime fieldAPI field.
     - FileFieldItemList //list_class for file and image fieldAPI fields
     - TaxonomyTermReferenceFieldItemList //this is the list_class for the taxonomy term fieldAPI field
     - ConfigurableEntityReferenceFieldItemList //this is the list_class for the entity reference fieldAPI field
     -WORTHFIELDITEMLIST
 - Map, has propertydefinitions
   - FieldItemBase implements FieldItemInterface "an entity field item" each of these has a schema() and getEntity() 
     - BooleanItem
     - ListBooleanItem
     - ListItemBase
       - ListTextItem
       - ListIntegerItem
       - ListFloatItem
     - NumericItemBase
       - DecimalItem
       - Floatitem
       - IntegerItem 
     - EntityReferenceItem
       - TaxonomyTermReferenceItem
       - ConfigurableEntityReferenceItem
       - FileItem
     - DateTimeItem
     - PathItem
     - TimestampItem
       - CreatedItem
         - ChangedItem
     - MapItem (not used)
     - EmailItem
     - StringItem
       - UuidItem
       - StringLongItem
       - UriItem
     - LanguageItem
     - WORTHITEM
   - DataReferenceBase
     - LanguageReference

DataDefinition

 - FieldItemDataDefinition, has method createFromDataType(field_item:something) 
 - ListDataDefinition, has method createFromItemType($item_type) 
   - FieldDefinition, has method create($type);//The type of the field.
 - DataReferenceDefinition has a method create($type). and createFromDataType
 - ComplexDataDefinitionBase
   - MapDataDefinition, has method createFromDataType()
   - EntityDataDefinition, has method createFromDataType('entity:user')
In each case the argument for createFromDataType() must have a dataDefinition, or listDataDefinition

Field Widgets

PluginSettingsBase
 - WidgetBase
   - StringWidget
   - UriWidget
   - NumberWidget
   - EmailDefaultWidget

Creating fields

When we FieldDefinition::create($type) in an Content Entity's baseFieldDefinitions(). $type must be a @FieldType, which is to say the class must implement FieldItemInterface. The fieldAPI '@fieldtype' definitions can specify a list_class property which will be automatically applied. E.g

/**
 * Plugin implementation of the 'datetime' field type.
 *
 * @FieldType(
 *   id = "datetime",
 *   label = @Translation("Date"),
 *   description = @Translation("Create and store date values."),
 *   default_widget = "datetime_default",
 *   default_formatter = "datetime_default",
 *   list_class = "\Drupal\datetime\Plugin\Field\FieldType\DateTimeFieldItemList"
 * )
 */
will automatically apply the list class when the datetime field is added to an entity by user 1.

As far as I can see it is not possible to create entities with list class and multiple field cardinality, to an entitybaseDefinition because each entity has one base table which cannot store multiple values for a field.

Add new comment

Theme by Danetsoft and Danang Probo Sayekti inspired by Maksimer