Drupal 8 entities & felds

Embed Size (px)

Citation preview

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

EntityInterfaceContentEntityInterfaceConfigEntityInterface

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: articlename: Articlebase: node_contentmodule: nodedisabled: '0'locked: '0'custom: '1'status: '1'langcode: und

description: 'Use articles 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

MenuBlock config vs Block content Content

ContentEntityInterface

ConfigEntityInterface
getOriginalID() + setStatus()

Language Entity or Class

Each entity containsUUID - Universally unique identifier for this entity. (128)

LANGCODE - varchar(12)

Modules:Locale

language

translation @deprecated

translation_entity

Entity translation in core

Entity = Plugin (wtf)
Drupal\user\Plugin\Core\Entity\User

/** * Defines the user entity class. * * @EntityType( * id = "user", * label = @Translation("User"), * module = "user", * controllers = { * "storage" = "Drupal\user\UserStorageController", * "access" = "Drupal\user\UserAccessController", * "render" = "Drupal\Core\Entity\EntityRenderController", * "form" = { * "profile" = "Drupal\user\ProfileFormController", * "register" = "Drupal\user\RegisterFormController" * }, * "translation" = "Drupal\user\ProfileTranslationController" * },

* 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 RenderControllerViewMode

EntityDisplay

EntityFormDisplay

Entity API

Controllers:EntityStorageControllerInterface

EntityAccessControllerInterface

EntityRenderControllerInterface

EntityFormControllerInterface many

EntityTranslationControllerInterface

Entity NG

Why Drupal 8 slow (x4) => entityBCdecorator