D7 Entities

19
business of open technology Drupal 7 Entities DrupalCamp Helsinki 27.9.2011 Tomi Mikola

description

Drupal 7 Entities was delivered by Tomi Mikola of Mearra

Transcript of D7 Entities

Page 1: D7 Entities

business of open technology

Drupal 7 EntitiesDrupalCamp Helsinki

27.9.2011

Tomi Mikola

Page 2: D7 Entities

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

Page 3: D7 Entities

business of open technologyWhat are entities?

Page 4: D7 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

Page 5: D7 Entities

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, ...

Page 6: D7 Entities

business of open technologyFields and entities

Page 7: D7 Entities

business of open technology

Fields

• Data types which can be attached to any kind of entity

• Widgets & formatters

• Field instances

Page 8: D7 Entities

business of open technology

Bundles

• Entity + field (*n) = Bundle

• Node (entity), Article (bundle)

• User (entity), User (bundle)

Page 9: D7 Entities

business of open technology Entity API

Page 10: D7 Entities

business of open technology

Entity API

• Contrib module (drupal.org/project/entity)

• Completes what Drupal core entities should be

• Full CRUD operations

Page 11: D7 Entities

business of open technology Entity?

Page 12: D7 Entities

business of open technology

Entities or Nodes?

• “I created a draft using Word”

• Translations, versioning?

• End-user’s point of view: “Content!”

Page 13: D7 Entities

business of open technologyHow to begin?

Page 14: D7 Entities

business of open technology

How to begin with entities?• No UI

• Write code

• hook_schema()

• hook_entity_info()

• Label

• Base table

• Fieldable

Page 15: D7 Entities

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(), //...

Page 16: D7 Entities

business of open technology Prove it!

Page 17: D7 Entities

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

Page 18: D7 Entities

business of open technology

Thank you!

Page 19: D7 Entities

business of open technology

Photos © Tomi Mikola