Successfully reported this slideshow.

Drupalize your data use entities

565 views

Published on

Drupalize your data use entities
Druapl 7

Published in: Technology, Education
  • Be the first to comment

Drupalize your data use entities

  1. 1. CodinganddevelopmentDrupalizeYour Data:UseEntities!PresentedbyWolfgangZiegler // fago
  2. 2. Wolfgang Ziegler // fago• from Vienna, Austria• studied at the TU Vienna• Drupal since 2005.wolfgangziegler.nettwitter.com/the_real_fagogplus.to/fago
  3. 3. Outline• Introduction• Interact with entities• Providing a new entity type• Expose non-DB entities• Outlook
  4. 4. Drupal 7:Fields everywhere!
  5. 5. BundlesEntity type ↔ NodeBundle ↔ Node typeEntity type ↔ Taxonomy termBundle ↔ VocabularyEntity type ↔ UserBundle ↔ {}
  6. 6. Which entities are there?• Core• Modules:• Drupal commerce• Organic groups• Profile2• Heartbeat and Message• File entity
  7. 7. Node modulesEntity modules
  8. 8. Entity API - What for?Unified way to access data.
  9. 9. UserNodeCommentProfileProductSearchVoteGroupsEntityreferenceRulesEntity
  10. 10. Interacting with entities
  11. 11. Entity API moduleAssists you with• interacting with entities• and providing new entity types
  12. 12. Entity API FunctionsDrupal CoreEntity API moduleentity_save()entity_load()entity_get_info()entity_metadata_wrapper()entity_view()entity_access()entity_create()entity_id()entity_get_property_info()entity_delete()
  13. 13. Metadata Wrapper$wrapper = entity_metadata_wrapper(node, $nid);$mail = $wrapper­>author­>mail­>value();$wrapper­>author­>mail­>set(fago@example.com);$text = $wrapper­>field_text­>value();$wrapper­>language(de)­>field_text­>value();$terms = $wrapper­>field_tags­>value();$wrapper­>field_tags[] = $term;$options = $wrapper­>field_tags­>optionsList();$label = $wrapper­>field_tags[0]­>label();$access = $wrapper­>field_tags­>access(edit);
  14. 14. Metadata Wrapper$wrapper = entity_metadata_wrapper(node, $nid);$mail = $wrapper­>author­>mail­>value();$wrapper­>author­>mail­>set(fago@example.com);$text = $wrapper­>field_text­>value();$wrapper­>language(de)­>field_text­>value();$terms = $wrapper­>field_tags­>value();$wrapper­>field_tags[] = $term;$options = $wrapper­>field_tags­>optionsList();$label = $wrapper­>field_tags[0]­>label();$access = $wrapper­>field_tags­>access(edit);
  15. 15. Entity property info$properties[mail] = array(  label => t("Email"),  type => text,  description => t("The email address of ..."),  setter callback => entity_property_verbatim_set,  validation callback => valid_email_address,  required => TRUE,  access callback => user_properties_access,  schema field => mail,);
  16. 16. Property info?• Unified access to entity data• Validation• Access information
  17. 17. How modules use it• Drupal Commerce, VBO, OG• Rules, Search API• Microdata• RestWS, WSClient• Entity tokens• Entity Views
  18. 18. Providing an entity type• Implement hook_entity_info()• Specify your controller class• Implement hook_schema()
  19. 19. Entity API module$profile = entity_create(profile2, array(  type => main,  user=> $account,));$profile­>save();$profile­>delete();entity_delete_multiple(profile2, array(1, 2, 3));
  20. 20. Integrating your entity typeTokensViews RulesPropertyInfoField APISchemaCRUDcontrollerInfoXY
  21. 21. Exportable entitiessimilar to CTools exportables, but...• unified CRUD interface• synced to the DB• regular CRUD hooks• Views, Tokens, Features, i18n, ...
  22. 22. Integrating your exportable entitySchemaCRUDcontrollerInfoTokensPropertyInfoViews i18nFeaturesAdminUI
  23. 23. Apocalypse now?• Provide an entity• get a bullshit of not fitting stuff•• Find a good metafa, or cite for it.• is it an elephant or moskito?
  24. 24. Module developers: Think• what makes it applicable?• label, URI?• field?• custom on,off• example: no display,no page → nometadata tags
  25. 25. Example: Profile2Profile2:• Entity typeProfile2 types:• Entity type• Bundle of Profile2• Exportable
  26. 26. Profile2 torn apart• CRUD, Field API• Permissions, Access• Profile form, display• Admin UI, I18n• Views, CTools, Rules, Tokens,Features, Search APIYour job
  27. 27. homework done,lets enjoy it.
  28. 28. • NoSQL, Doctrine, PHPCR• Remote entities• Data integration
  29. 29. Non-DB entities+Fields?
  30. 30. Non-DB entitiesFieldstorageInfoPropertyInfoField APISchemaControllerInfo TokensRulesViews XYCRUDcontroller
  31. 31. Non-DB entitiesCRUDcontrollerInfoPropertyInfoSchemaControllerInfo TokensRulesViews XY
  32. 32. What does it buy us?• Classed CRUD API• CRUD Hooks• Tokens• Entity reference• Rules, Rules Links• Search API, Views integration, RestWS• …
  33. 33. Drupalize your data!
  34. 34. howto slide?
  35. 35. Example...
  36. 36. Google Picasa entitieshttp://drupal.org/sandbox/fago/1493180
  37. 37. Room for improvements• EFQ Views• Ready-only mode• Generated display• Generated form
  38. 38. Drupal 8
  39. 39. Comments in Drupal 8$comment = entity_create(comment, array(  nid => $node­>nid,));$comment­>save();echo $comment­>id();$comment­>delete();entity_delete_multiple(comment, array(1, 2, 3));
  40. 40. Comments in Drupal 8class CommentStorageController extends EntityDatabaseStorageController {…}class Comment extends Entity { …}class Entity implements EntityInterface { …}
  41. 41. Questions?
  42. 42. What didyouthink?LocatethissessionontheDrupalConDenver websitehttp://denver2012.drupal.org/programClickthe“TaketheSurvey” link.ThankYou!

×