O slideshow foi denunciado.
Seu SlideShare está sendo baixado. ×

Drupalize your data use entities

Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Próximos SlideShares
Tutorial   dekho queries
Tutorial dekho queries
Carregando em…3
×

Confira estes a seguir

1 de 46 Anúncio
Anúncio

Mais Conteúdo rRelacionado

Semelhante a Drupalize your data use entities (20)

Mais de 均民 戴 (16)

Anúncio

Mais recentes (20)

Drupalize your data use entities

  1. 1. Codinganddevelopment DrupalizeYour Data: UseEntities! PresentedbyWolfgangZiegler // fago
  2. 2. Wolfgang Ziegler // fago • from Vienna, Austria • studied at the TU Vienna • Drupal since 2005. wolfgangziegler.net twitter.com/the_real_fago gplus.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. Bundles Entity type ↔ Node Bundle ↔ Node type Entity type ↔ Taxonomy term Bundle ↔ Vocabulary Entity type ↔ User Bundle ↔ {}
  6. 6. Which entities are there? • Core • Modules: • Drupal commerce • Organic groups • Profile2 • Heartbeat and Message • File entity
  7. 7. Node modules Entity modules
  8. 8. Entity API - What for? Unified way to access data.
  9. 9. User Node Comment Profile Product Search Vote Groups Entity reference Rules Entity
  10. 10. Interacting with entities
  11. 11. Entity API module Assists you with • interacting with entities • and providing new entity types
  12. 12. Entity API Functions Drupal Core Entity API module entity_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 type TokensViews Rules Property Info Field API Schema CRUD controller Info XY
  21. 21. Exportable entities similar to CTools exportables, but... • unified CRUD interface • synced to the DB • regular CRUD hooks • Views, Tokens, Features, i18n, ...
  22. 22. Integrating your exportable entity Schema CRUD controller Info Tokens Property Info Views i18nFeatures Admin UI
  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 → no metadata tags
  25. 25. Example: Profile2 Profile2: • Entity type Profile2 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 API Your job
  27. 27. homework done, let's enjoy it.
  28. 28. • NoSQL, Doctrine, PHPCR • Remote entities • Data integration
  29. 29. Non-DB entities + Fields?
  30. 30. Non-DB entities Field storage Info Property Info Field API SchemaControllerInfo TokensRulesViews XY CRUD controller
  31. 31. Non-DB entities CRUD controller Info Property Info SchemaControllerInfo 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 entities http://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 8 class CommentStorageController extends  EntityDatabaseStorageController { … } class Comment extends Entity {  … } class Entity implements EntityInterface {  … }
  41. 41. Questions?
  42. 42. What didyouthink? Locatethissessiononthe DrupalConDenver website http://denver2012.drupal.org/program Clickthe“TaketheSurvey” link. ThankYou!

×