d7 entities
DESCRIPTION
Drupal 7 Entities was delivered by Tomi Mikola of MearraTRANSCRIPT
business of open technology
Drupal 7 EntitiesDrupalCamp Helsinki
27.9.2011
Tomi Mikola
business of open technology
About me
• Working at Mearra
• Architect, senior developer, project mgr, salesman, co-founder, Drupal evangelist
• Drupal as the primary platform since 2006
business of open technologyWhat are entities?
business of open technology
Concept of Entity
• Generalization of something that can be stored in Drupal
• Standardized set of how data structures are represented
• In D6 nodes were considered as the main abstraction point
business of open technology
Concept of Entity• Type of objects which Drupal is
aware of
• Something unique, relevant to the application
• "The new Node"
• D7: Nodes, Users, Files, Comments, Terms, ...
business of open technologyFields and entities
business of open technology
Fields
• Data types which can be attached to any kind of entity
• Widgets & formatters
• Field instances
business of open technology
Bundles
• Entity + field (*n) = Bundle
• Node (entity), Article (bundle)
• User (entity), User (bundle)
business of open technology Entity API
business of open technology
Entity API
• Contrib module (drupal.org/project/entity)
• Completes what Drupal core entities should be
• Full CRUD operations
business of open technology Entity?
business of open technology
Entities or Nodes?
• “I created a draft using Word”
• Translations, versioning?
• End-user’s point of view: “Content!”
business of open technologyHow to begin?
business of open technology
How to begin with entities?• No UI
• Write code
• hook_schema()
• hook_entity_info()
• Label
• Base table
• Fieldable
business of open technology
How to begin with entities?function node_entity_info() { $return = array( 'node' => array( 'label' => t('Node'), 'controller class' => 'NodeController', 'base table' => 'node', 'revision table' => 'node_revision', 'uri callback' => 'node_uri', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'nid', 'revision' => 'vid', 'bundle' => 'type', 'label' => 'title', ), 'bundles' => array(), //...
business of open technology Prove it!
business of open technology
Poll Improved (demo)
• Drupal core Poll doesn’t take advantage of entities
• Started new project to test Entity API
• Model (contrib module) as basis
• Flexibility by using Field API
business of open technology
Thank you!
business of open technology
Photos © Tomi Mikola