Drupal 7: What's new Karoly Negyesi Clarity Digital (examiner.com)
What's new in Drupal 7 <ul><li>See  http://blip.tv/file/2772239
Tons of new APIs
Most of them are well documented and easy
Field API: many new concepts and gotchas </li></ul>
Field API <ul><li>Extremely powerful
API and not browser driven
Our work now is “precision surgery” </li></ul>
Key concepts <ul><li>Bundles
Field storage
Field types
Widgets
Formatters
Fields
Attach
Instances </li></ul>
Anatomy of a node <ul><li>Organization: node type
Primary identifier: nid
Version identifier: vid </li></ul>
Anatomy of a term <ul><li>Organization: vocabulary
Upcoming SlideShare
Loading in …5
×

Drupal 7 field API

1,880 views

Published on

Drupal 7 field API talk given at FOSDEM 2010.

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

Drupal 7 field API

  1. 1. Drupal 7: What's new Karoly Negyesi Clarity Digital (examiner.com)
  2. 2. What's new in Drupal 7 <ul><li>See http://blip.tv/file/2772239
  3. 3. Tons of new APIs
  4. 4. Most of them are well documented and easy
  5. 5. Field API: many new concepts and gotchas </li></ul>
  6. 6. Field API <ul><li>Extremely powerful
  7. 7. API and not browser driven
  8. 8. Our work now is “precision surgery” </li></ul>
  9. 9. Key concepts <ul><li>Bundles
  10. 10. Field storage
  11. 11. Field types
  12. 12. Widgets
  13. 13. Formatters
  14. 14. Fields
  15. 15. Attach
  16. 16. Instances </li></ul>
  17. 17. Anatomy of a node <ul><li>Organization: node type
  18. 18. Primary identifier: nid
  19. 19. Version identifier: vid </li></ul>
  20. 20. Anatomy of a term <ul><li>Organization: vocabulary
  21. 21. Primary identifier: tid
  22. 22. Version identifier: tid (same) </li></ul>
  23. 23. Anatomy of an entity <ul><li>Entity type: node
  24. 24. Bundle: node type
  25. 25. Primary id: nid
  26. 26. Version id: vid </li></ul><ul><li>Type: taxonomy term
  27. 27. Bundle: vocabulary
  28. 28. Primary id: tid
  29. 29. Version id: tid </li></ul><ul><li>list($id, $vid, $bundle) = entity_extract_ids($obj_type, $object); </li></ul>
  30. 30. Field storage <ul><li>Storage primitives
  31. 31. Cornerstone of scalability
  32. 32. MongoDB </li></ul>
  33. 33. Field type <ul><li>Business logic of a field
  34. 34. Text, file, image...
  35. 35. Gotcha: extremely badly named hooks. for eg. hook_field_load node-like “one only” hook should be field_type not field . </li></ul>
  36. 36. Field <ul><li>A bunch of settings
  37. 37. Field type
  38. 38. Cardinality
  39. 39. Storage engine
  40. 40. All the things that are hard to upgrade
  41. 41. Core does not upgrade </li></ul>
  42. 42. Attaching <ul><li>Attaching
  43. 43. (a) Field
  44. 44. (to a) Bundle
  45. 45. (is an) Instance </li></ul>
  46. 46. Instance <ul><li>Again a bunch of settings
  47. 47. Widget settings
  48. 48. Formatter settings
  49. 49. Trivial to update
  50. 50. Gotcha: formatter settings are stored in 'display' </li></ul>
  51. 51. Difference <ul><li>Fields describe data structure and behaviour
  52. 52. Hard to update
  53. 53. Instances are trivial to update
  54. 54. Instances are mostly just widget / formatter </li></ul>
  55. 55. Widgets <ul><li>Data entry mechanism
  56. 56. Generic: textfield, textarea, options_select...
  57. 57. Specific: Image (but there is always an alter) </li></ul>
  58. 58. Formatter <ul><li>Displays a field
  59. 59. Generic
  60. 60. Specific (yes, we have an alter here too) </li></ul>
  61. 61. Field attach API <ul><li>field_attach_* called explicitly by entity modules:
  62. 62. field_attach_presave('node', $node);
  63. 63. These call same named hooks
  64. 64. module_invoke_all('field_attach_presave', $obj_type, $object);
  65. 65. hook arguments are entity type and the entity
  66. 66. Gotcha: does not deal with attaching a field
  67. 67. But at least it's a real hook. </li></ul>
  68. 68. Field attach API continued <ul><li>Entity information can be extracted: list($id, $vid, $bundle, $cacheable) = entity_extract_ids($obj_type, $object);
  69. 69. Instances can be found: field_info_instances($obj_type, $bundle) </li></ul>
  70. 70. So all the gotchas <ul><li>hook_field_X is really “field_type X callback”
  71. 71. Entity type variables are typically $obj_type
  72. 72. Similarly, entities are $object
  73. 73. Formatter settings are in $instance['display']
  74. 74. The field attach API deals with fields already attached aka. Instances and not the attach itself </li></ul>
  75. 75. Taxonomy specific gotchas <ul><li>Vocabularies themselves are entities too
  76. 76. Taxonomy_term_reference
  77. 77. Hiearchy is not a field </li></ul>
  78. 78. Hook cornucopia <ul><li>field_attach_update('user', $object);
  79. 79. user_module_invoke('update', $edit, $user, $category);
  80. 80. entity_invoke('update', 'user', $user); </li></ul>

×