SlideShare a Scribd company logo
Drupal 8 Entities
Content vs Configuration
Andy Postnikov, 2013
Entity? Node != Content?
Drupal 7 entities
● Node
● Comment
● User
● Term
● Vocabulary
●
● Contrib … Commerce, Message, ECK, ...
●
● Entity API, Rules, DS
Drupal 8 entities
Ctools + Entity API + DS + Rules
EntityInterface
ContentEntityInterface
ConfigEntityInterface
Entity
Taxonomy vocabulary
D8 entity - taxonomy_vocabulary
core/profiles/standard/config/taxonomy.vocabulary.tags.yml
● vid: tags
● name: Tags
● description: 'Use tags to group articles on similar topics into categories.'
● hierarchy: '0'
● weight: '0'
● status: '1'
● langcode: en
Role — Drupal 8 changes!
Role = user_role config
/core/profiles/standard
/config/user.role.administrator.yml
● id: administrator
● label: Administrator
● weight: 2
● langcode: en
Node & NodeType
type: article
name: Article
base: node_content
module: node
disabled: '0'
locked: '0'
custom: '1'
status: '1'
langcode: und
description: 'Use
<em>articles</em> for
time-sensitive content like
news, press releases or
blog posts.'
help: ''
has_title: '1'
title_label: Title
settings:
node:
preview: '1'
options:
status: status
promote: promote
sticky: '0'
revision: '0'
submitted: '1'
Node = nid, uuid, vid, type, langcode [tnid, translate]
{node_field_data} + {node_field_revision} = title, uid...
NodeType http://dgo.to/111715 - conversion
Content vs Config
● Contact
● Vocabulary
● View
● Custom block
● Role
● Menu
Block config vs Block content → Content
ContentEntityInterface
ConfigEntityInterface
getOriginalID() + setStatus()
Language Entity or Class
● Each entity contains
– UUID - Universally unique identifier for this entity. (128)
– LANGCODE - varchar(12)
● Modules:
– Locale
– language
– translation @deprecated
– translation_entity
Entity translation in core
Entity = Plugin (wtf)
DrupaluserPluginCoreEntityUser
/**
* Defines the user entity class.
*
* @EntityType(
* id = "user",
* label = @Translation("User"),
* module = "user",
* controllers = {
* "storage" =
"DrupaluserUserStorageController",
* "access" =
"DrupaluserUserAccessController",
* "render" =
"DrupalCoreEntityEntityRenderController",
* "form" = {
* "profile" =
"DrupaluserProfileFormController",
* "register" =
"DrupaluserRegisterFormController"
* },
* "translation" =
"DrupaluserProfileTranslationController"
* },
* default_operation = "profile",
* base_table = "users",
* uri_callback = "user_uri",
* route_base_path =
"admin/config/people/accounts",
* label_callback = "user_label",
* fieldable = TRUE,
* translatable = TRUE,
* entity_keys = {
* "id" = "uid",
* "uuid" = "uuid"
* }
* )
*/
class User extends EntityNG implements
UserInterface {
…
interface UserInterface extends
EntityInterface {}
class Entity implements
IteratorAggregate, EntityInterface {}
class EntityNG extends Entity {}
Entity API
● Definition:
– Annotation @EntityType
– hook_entity_info(&$entity_info) +
hook_entity_info_alter(&$entity_info)
– hook_entity_bundle_info() +
hook_entity_bundle_info_alter(&$bundles)
– Display entity via RenderController
● ViewMode
● EntityDisplay
● EntityFormDisplay
Entity API
● Controllers:
– EntityStorageControllerInterface
– EntityAccessControllerInterface
– EntityRenderControllerInterface
– EntityFormControllerInterface — many
– EntityTranslationControllerInterface
Entity NG
● Why Drupal 8 slow (x4) => entityBCdecorator
<?php
/**
* @file
* Contains DrupalCoreEntityEntity.
*/
/**
* Implements DrupalCoreEntityEntityInterface::getBCEntity().
*/
public function getBCEntity() {
return $this;
}
/**
* Implements DrupalCoreEntityEntityInterface::getNGEntity().
*/
public function getNGEntity() {
return $this;
}
Entity NG - BC
● Magic methods vs native properties
<?php
/**
* @file
* Contains DrupalCoreEntityEntityNG.
*/
/**
* Overrides Entity::getBCEntity().
*/
public function getBCEntity() {
if (!isset($this->bcEntity)) {
// Initialize field definitions so that we can pass them by reference.
$this->getPropertyDefinitions();
$this->bcEntity = new EntityBCDecorator($this, $this->fieldDefinitions);
}
return $this->bcEntity;
}
Fields NG
● Bundles are separated from entity definition
● Field and Field instance are config objects
● Todo:
– Replace most field-hooks with TypedData
– Review mega patches in sandboxes
– Allow use widgets and formatters for any data
object (none-configurable field)
Fields for menu links
● * @EntityType(
● * id = "menu",
● * label = @Translation("Menu"),
● * module = "system",
● * controllers = {
● * "storage" = "DrupalCoreConfigEntityConfigStorageController"
● * },
● * config_prefix = "menu.menu",
● * entity_keys = {
● * "id" = "id",
● * "label" = "label",
● * "uuid" = "uuid"
● * }
TypedData
Validation
● #2002152 by fago, amateescu: Implement
entity validation based on symfony validator.
●
● Make formatters and widgets work on
nonconfigurable fields
https://drupal.org/node/1950632
Todo
● [meta] Unified Entity Field API
– https://drupal.org/node/1346214
● Move entity-type specific storage logic into
entity classes
– https://drupal.org/node/1893772
● [META] Unify entity fields and field API
– https://drupal.org/node/1949932
Questions
● http://entity.worldempire.ch
● http://realize.be/field-api/
● http://buytaert.net/want-more-features-in-drupal-8-h

More Related Content

PDF
Configuration Entities in Drupal 8
PDF
What's New in Drupal 8: Entity Field API
PDF
Drupal 8: Entities
PDF
Top Ten Reasons to Use EntityFieldQuery in Drupal
PDF
RequireJS & Handlebars
PDF
Jquery plugin development
PDF
Drupal 7 Entity & Entity API
PDF
JQuery plugin development fundamentals
Configuration Entities in Drupal 8
What's New in Drupal 8: Entity Field API
Drupal 8: Entities
Top Ten Reasons to Use EntityFieldQuery in Drupal
RequireJS & Handlebars
Jquery plugin development
Drupal 7 Entity & Entity API
JQuery plugin development fundamentals

What's hot (20)

PDF
Field api.From d7 to d8
ODP
Jquery Plugin
PDF
Filtering data with D2W
PDF
Drupal Field API. Practical usage
PDF
Domain-driven Design in PHP and Symfony - Drupal Camp Wroclaw!
PDF
Drupal 8: Forms
PDF
DrupalJam 2018 - Maintaining a Drupal Module: Keep It Small and Simple
PDF
Migrating Drupal 7 to Drupal 8
PDF
Migrating to-Drupal-8 by Bryan Manalo
PDF
Handlebars.js
PPT
Introduction to hibernate
PPT
Intro To Hibernate
PPT
Hibernate Tutorial
PDF
Web internship Yii Framework
KEY
Intro to IndexedDB (Beta)
PPT
Java Persistence API (JPA) Step By Step
PPT
Scorware - Spring Introduction
PDF
Java persistence api 2.1
ODP
Multilingual drupal 7
PDF
Meet Magento Sweden - Magento 2 Layout and Code Compilation for Performance
Field api.From d7 to d8
Jquery Plugin
Filtering data with D2W
Drupal Field API. Practical usage
Domain-driven Design in PHP and Symfony - Drupal Camp Wroclaw!
Drupal 8: Forms
DrupalJam 2018 - Maintaining a Drupal Module: Keep It Small and Simple
Migrating Drupal 7 to Drupal 8
Migrating to-Drupal-8 by Bryan Manalo
Handlebars.js
Introduction to hibernate
Intro To Hibernate
Hibernate Tutorial
Web internship Yii Framework
Intro to IndexedDB (Beta)
Java Persistence API (JPA) Step By Step
Scorware - Spring Introduction
Java persistence api 2.1
Multilingual drupal 7
Meet Magento Sweden - Magento 2 Layout and Code Compilation for Performance
Ad

Similar to Drupal 8 entities & felds (20)

ODP
TangoWithDjango - ch8
PDF
Entity api
PDF
Writing Gadgets with the WSO2 Gadget Server
PDF
Thinking in Components
PDF
Entities in drupal 7
PDF
Java on Google App engine
PDF
Rest application
PPTX
Dgeni documentation generator
PDF
.Net template solution architecture
ODP
Angular js-crash-course
PDF
2016 stop writing javascript frameworks by Joe Gregorio
PDF
Understanding the Entity API Module
PDF
Utilising the data attribute
PDF
Practical JavaScript Programming - Session 4/8
PDF
Modern frontend development with VueJs
PDF
Test02
PDF
Five android architecture
PDF
[Srijan Wednesday Webinars] Ruling Drupal 8 with #d8rules
PPTX
08ui.pptx
PPT
Synapse india reviews on drupal 7 entities (stanford)
TangoWithDjango - ch8
Entity api
Writing Gadgets with the WSO2 Gadget Server
Thinking in Components
Entities in drupal 7
Java on Google App engine
Rest application
Dgeni documentation generator
.Net template solution architecture
Angular js-crash-course
2016 stop writing javascript frameworks by Joe Gregorio
Understanding the Entity API Module
Utilising the data attribute
Practical JavaScript Programming - Session 4/8
Modern frontend development with VueJs
Test02
Five android architecture
[Srijan Wednesday Webinars] Ruling Drupal 8 with #d8rules
08ui.pptx
Synapse india reviews on drupal 7 entities (stanford)
Ad

Recently uploaded (20)

PDF
Spectral efficient network and resource selection model in 5G networks
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Advanced IT Governance
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Machine learning based COVID-19 study performance prediction
PPT
Teaching material agriculture food technology
PDF
Approach and Philosophy of On baking technology
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
KodekX | Application Modernization Development
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Network Security Unit 5.pdf for BCA BBA.
Spectral efficient network and resource selection model in 5G networks
The AUB Centre for AI in Media Proposal.docx
NewMind AI Weekly Chronicles - August'25 Week I
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
The Rise and Fall of 3GPP – Time for a Sabbatical?
“AI and Expert System Decision Support & Business Intelligence Systems”
Chapter 3 Spatial Domain Image Processing.pdf
Advanced IT Governance
Per capita expenditure prediction using model stacking based on satellite ima...
Mobile App Security Testing_ A Comprehensive Guide.pdf
20250228 LYD VKU AI Blended-Learning.pptx
Machine learning based COVID-19 study performance prediction
Teaching material agriculture food technology
Approach and Philosophy of On baking technology
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
KodekX | Application Modernization Development
Unlocking AI with Model Context Protocol (MCP)
Network Security Unit 5.pdf for BCA BBA.

Drupal 8 entities & felds

  • 1. Drupal 8 Entities Content vs Configuration Andy Postnikov, 2013
  • 2. Entity? Node != Content?
  • 3. Drupal 7 entities ● Node ● Comment ● User ● Term ● Vocabulary ● ● Contrib … Commerce, Message, ECK, ... ● ● Entity API, Rules, DS
  • 4. Drupal 8 entities Ctools + Entity API + DS + Rules EntityInterface ContentEntityInterface ConfigEntityInterface Entity
  • 6. D8 entity - taxonomy_vocabulary core/profiles/standard/config/taxonomy.vocabulary.tags.yml ● vid: tags ● name: Tags ● description: 'Use tags to group articles on similar topics into categories.' ● hierarchy: '0' ● weight: '0' ● status: '1' ● langcode: en
  • 7. Role — Drupal 8 changes!
  • 8. Role = user_role config /core/profiles/standard /config/user.role.administrator.yml ● id: administrator ● label: Administrator ● weight: 2 ● langcode: en
  • 9. Node & NodeType type: article name: Article base: node_content module: node disabled: '0' locked: '0' custom: '1' status: '1' langcode: und description: 'Use <em>articles</em> for time-sensitive content like news, press releases or blog posts.' help: '' has_title: '1' title_label: Title settings: node: preview: '1' options: status: status promote: promote sticky: '0' revision: '0' submitted: '1' Node = nid, uuid, vid, type, langcode [tnid, translate] {node_field_data} + {node_field_revision} = title, uid... NodeType http://dgo.to/111715 - conversion
  • 10. Content vs Config ● Contact ● Vocabulary ● View ● Custom block ● Role ● Menu Block config vs Block content → Content
  • 13. Language Entity or Class ● Each entity contains – UUID - Universally unique identifier for this entity. (128) – LANGCODE - varchar(12) ● Modules: – Locale – language – translation @deprecated – translation_entity
  • 15. Entity = Plugin (wtf) DrupaluserPluginCoreEntityUser /** * Defines the user entity class. * * @EntityType( * id = "user", * label = @Translation("User"), * module = "user", * controllers = { * "storage" = "DrupaluserUserStorageController", * "access" = "DrupaluserUserAccessController", * "render" = "DrupalCoreEntityEntityRenderController", * "form" = { * "profile" = "DrupaluserProfileFormController", * "register" = "DrupaluserRegisterFormController" * }, * "translation" = "DrupaluserProfileTranslationController" * }, * default_operation = "profile", * base_table = "users", * uri_callback = "user_uri", * route_base_path = "admin/config/people/accounts", * label_callback = "user_label", * fieldable = TRUE, * translatable = TRUE, * entity_keys = { * "id" = "uid", * "uuid" = "uuid" * } * ) */ class User extends EntityNG implements UserInterface { … interface UserInterface extends EntityInterface {} class Entity implements IteratorAggregate, EntityInterface {} class EntityNG extends Entity {}
  • 16. Entity API ● Definition: – Annotation @EntityType – hook_entity_info(&$entity_info) + hook_entity_info_alter(&$entity_info) – hook_entity_bundle_info() + hook_entity_bundle_info_alter(&$bundles) – Display entity via RenderController ● ViewMode ● EntityDisplay ● EntityFormDisplay
  • 17. Entity API ● Controllers: – EntityStorageControllerInterface – EntityAccessControllerInterface – EntityRenderControllerInterface – EntityFormControllerInterface — many – EntityTranslationControllerInterface
  • 18. Entity NG ● Why Drupal 8 slow (x4) => entityBCdecorator <?php /** * @file * Contains DrupalCoreEntityEntity. */ /** * Implements DrupalCoreEntityEntityInterface::getBCEntity(). */ public function getBCEntity() { return $this; } /** * Implements DrupalCoreEntityEntityInterface::getNGEntity(). */ public function getNGEntity() { return $this; }
  • 19. Entity NG - BC ● Magic methods vs native properties <?php /** * @file * Contains DrupalCoreEntityEntityNG. */ /** * Overrides Entity::getBCEntity(). */ public function getBCEntity() { if (!isset($this->bcEntity)) { // Initialize field definitions so that we can pass them by reference. $this->getPropertyDefinitions(); $this->bcEntity = new EntityBCDecorator($this, $this->fieldDefinitions); } return $this->bcEntity; }
  • 20. Fields NG ● Bundles are separated from entity definition ● Field and Field instance are config objects ● Todo: – Replace most field-hooks with TypedData – Review mega patches in sandboxes – Allow use widgets and formatters for any data object (none-configurable field)
  • 21. Fields for menu links ● * @EntityType( ● * id = "menu", ● * label = @Translation("Menu"), ● * module = "system", ● * controllers = { ● * "storage" = "DrupalCoreConfigEntityConfigStorageController" ● * }, ● * config_prefix = "menu.menu", ● * entity_keys = { ● * "id" = "id", ● * "label" = "label", ● * "uuid" = "uuid" ● * }
  • 23. Validation ● #2002152 by fago, amateescu: Implement entity validation based on symfony validator. ● ● Make formatters and widgets work on nonconfigurable fields https://drupal.org/node/1950632
  • 24. Todo ● [meta] Unified Entity Field API – https://drupal.org/node/1346214 ● Move entity-type specific storage logic into entity classes – https://drupal.org/node/1893772 ● [META] Unify entity fields and field API – https://drupal.org/node/1949932