Entity API and Field API. Writing own
fields and entities in Drupal 8
by Alexei Goja
HELLO!
I am Alexei Goja
I am here because I love Drupal 8 =)
email: agoja@adyax.com / Skype: ag.medvedi
What We’re Talking About
› How entities are used in Drupal 7
› Improvements to the entity API
› Improvements to the field API
› Other new things that are made easier, or possible, by these
improvements
› Demo
Drupal 7 Entities & Fields
› Fields and properties are handled differently
› EntityFieldQuery is limited in
functionality
› Enhancements in contributed entity module
Drupal	8
Everything Is an Entity
› Universal API for data CRUD
› All content is stored as entities
› Complex configuration is stored as entities
› Your data should be stored as entities
Entities
› Entities are typed objects
› YourEntity implements EntityInterface
› EntityManager for interacting with entities of
any type
› Everything is a field
Fields
› Base fields vs. bundle fields
› Consistent API for accessing field values
› Widget & formatters work for all fields
› Chainable, and smart about relationships
CODE EXAMPLES






CODE EXAMPLES






CODE EXAMPLES






CODE EXAMPLES


Field Type annotation 



CODE EXAMPLES


Entity annotation



Handlers
› Entities represent a piece of data, handlers are responsible for acting
on that data
› Declared per entity type
› Use the defaults, or extend them for customizations
Handlers are used for:
• Storage
• Form
• Access control
• Listing
• Rendering
• etc.
EntityQuery
› Improved EntityFieldQuery
› No more propertyCondition() vs
fieldCondition()
› Don’t query the database, extend the
storage handler and add your own methods
Translations
› Native support for translation of all entity content
› Easily access translated values for an entire
entity or individual fields
What Do I Need to Know?
› Basic object-oriented PHP to use existing entities
› Drupal 8’s plugin system to create new entity
types
› Annotations
Demo
THANKS!
Any questions?




You can find me at:
agoja@adyax.com

Entity api and field api 2