Drupal 8 entities & felds

4,215 views
3,948 views

Published on

Drupal Camp Ukraine 2013, Kiev

Published in: Technology, Business
1 Comment
6 Likes
Statistics
Notes
No Downloads
Views
Total views
4,215
On SlideShare
0
From Embeds
0
Number of Embeds
241
Actions
Shares
0
Downloads
26
Comments
1
Likes
6
Embeds 0
No embeds

No notes for slide

Drupal 8 entities & felds

  1. 1. Drupal 8 EntitiesContent vs ConfigurationAndy Postnikov, 2013
  2. 2. Entity? Node != Content?
  3. 3. Drupal 7 entities● Node● Comment● User● Term● Vocabulary●● Contrib … Commerce, Message, ECK, ...●● Entity API, Rules, DS
  4. 4. Drupal 8 entitiesCtools + Entity API + DS + RulesEntityInterfaceContentEntityInterfaceConfigEntityInterfaceEntity
  5. 5. Taxonomy vocabulary
  6. 6. D8 entity - taxonomy_vocabularycore/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. 7. Role — Drupal 8 changes!
  8. 8. Role = user_role config/core/profiles/standard/config/user.role.administrator.yml● id: administrator● label: Administrator● weight: 2● langcode: en
  9. 9. Node & NodeTypetype: articlename: Articlebase: node_contentmodule: nodedisabled: 0locked: 0custom: 1status: 1langcode: unddescription: Use<em>articles</em> fortime-sensitive content likenews, press releases orblog posts.help: has_title: 1title_label: Titlesettings:node:preview: 1options:status: statuspromote: promotesticky: 0revision: 0submitted: 1Node = nid, uuid, vid, type, langcode [tnid, translate]{node_field_data} + {node_field_revision} = title, uid...NodeType http://dgo.to/111715 - conversion
  10. 10. Content vs Config● Contact● Vocabulary● View● Custom block● Role● MenuBlock config vs Block content → Content
  11. 11. ContentEntityInterface
  12. 12. ConfigEntityInterfacegetOriginalID() + setStatus()
  13. 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
  14. 14. Entity translation in core
  15. 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 implementsUserInterface {…interface UserInterface extendsEntityInterface {}class Entity implementsIteratorAggregate, EntityInterface {}class EntityNG extends Entity {}
  16. 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. 17. Entity API● Controllers:– EntityStorageControllerInterface– EntityAccessControllerInterface– EntityRenderControllerInterface– EntityFormControllerInterface — many– EntityTranslationControllerInterface
  18. 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. 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. 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 dataobject (none-configurable field)
  21. 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"● * }
  22. 22. TypedData
  23. 23. Validation● #2002152 by fago, amateescu: Implemententity validation based on symfony validator.●● Make formatters and widgets work onnonconfigurable fieldshttps://drupal.org/node/1950632
  24. 24. Todo● [meta] Unified Entity Field API– https://drupal.org/node/1346214● Move entity-type specific storage logic intoentity classes– https://drupal.org/node/1893772● [META] Unify entity fields and field API– https://drupal.org/node/1949932
  25. 25. Questions● http://entity.worldempire.ch● http://realize.be/field-api/● http://buytaert.net/want-more-features-in-drupal-8-h

×