README.txt 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. Entity API module
  2. -----------------
  3. by Wolfgang Ziegler, nuppla@zites.net
  4. This module extends the entity API of Drupal core in order to provide a unified
  5. way to deal with entities and their properties. Additionally, it provides an
  6. entity CRUD controller, which helps simplifying the creation of new entity types.
  7. This is an API module. You only need to enable it if a module depends on it or
  8. you are interested in using it for development.
  9. This README is for interested developers. If you are not interested in
  10. developing, you may stop reading now.
  11. --------------------------------------------------------------------------------
  12. Entity API
  13. --------------------------------------------------------------------------------
  14. * The module provides API functions allowing modules to create, save, delete
  15. or to determine access for entities based on any entity type, for which the
  16. necessary metadata is available. The module comes with integration for all
  17. core entity types, as well as for entities provided via the Entity CRUD API
  18. (see below). However, for any other entity type implemented by a contrib
  19. module, the module integration has to be provided by the contrib module
  20. itself.
  21. * Thus the module provides API functions like entity_save(), entity_create(),
  22. entity_delete(), entity_revision_delete(), entity_view() and entity_access()
  23. among others.
  24. entity_load(), entity_label() and entity_uri() are already provided by
  25. Drupal core.
  26. * For more information about how to provide this metadata, have a look at the
  27. API documentation, i.e. entity_metadata_hook_entity_info().
  28. --------------------------------------------------------------------------------
  29. Entity CRUD API - Providing new entity types
  30. --------------------------------------------------------------------------------
  31. * This API helps you when defining a new entity type. It provides an entity
  32. controller, which implements full CRUD functionality for your entities.
  33. * To make use of the CRUD functionality you may just use the API functions
  34. entity_create(), entity_delete() and entity_save().
  35. Alternatively you may specify a class to use for your entities, for which the
  36. "Entity" class is provided. In particular, it is useful to extend this class
  37. in order to easily customize the entity type, e.g. saving.
  38. * The controller supports fieldable entities and revisions. There is also a
  39. controller which supports implementing exportable entities.
  40. * The Entity CRUD API helps with providing additional module integration too,
  41. e.g. exportable entities are automatically integrated with the Features
  42. module. These module integrations are implemented in separate controller
  43. classes, which may be overridden and deactivated on their own.
  44. * There is also an optional ui controller class, which assists with providing
  45. an administrative UI for managing entities of a certain type.
  46. * For more details check out the documentation in the drupal.org handbook
  47. http://drupal.org/node/878804 as well as the API documentation, i.e.
  48. entity_crud_hook_entity_info().
  49. Basic steps to add a new entity type:
  50. ---------------------------------------
  51. * You might want to study the code of the "entity_test.module".
  52. * Describe your entities db table as usual in hook_schema().
  53. * Just use the "Entity" directly or extend it with your own class.
  54. To see how to provide a separate class have a look at the "EntityClass" from
  55. the "entity_test.module".
  56. * Implement hook_entity_info() for your entity. At least specifiy the
  57. controller class (EntityAPIController, EntityAPIControllerExportable or your
  58. own), your db table and your entity's keys.
  59. Again just look at "entity_test.module"'s hook_entity_info() for guidance.
  60. * If you want your entity to be fieldable just set 'fieldable' in
  61. hook_entity_info() to TRUE. The field API attachers are then called
  62. automatically in the entity CRUD functions.
  63. * The entity API is able to deal with bundle objects too (e.g. the node type
  64. object). For that just specify another entity type for the bundle objects
  65. and set the 'bundle of' property for it.
  66. Again just look at "entity_test.module"'s hook_entity_info() for guidance.
  67. * Schema fields marked as 'serialized' are automatically unserialized upon
  68. loading as well as serialized on saving. If the 'merge' attribute is also
  69. set to TRUE the unserialized data is automatically "merged" into the entity.
  70. * Further details can be found at http://drupal.org/node/878804.
  71. --------------------------------------------------------------------------------
  72. Entity Properties & Entity metadata wrappers
  73. --------------------------------------------------------------------------------
  74. * This module introduces a unique place for metadata about entity properties:
  75. hook_entity_property_info(), whereas hook_entity_property_info() may be
  76. placed in your module's {YOUR_MODULE}.info.inc include file. For details
  77. have a look at the API documentation, i.e. hook_entity_property_info() and
  78. at http://drupal.org/node/878876.
  79. * The information about entity properties contains the data type and callbacks
  80. for how to get and set the data of the property. That way the data of an
  81. entity can be easily re-used, e.g. to export it into other data formats like
  82. XML.
  83. * For making use of this information (metadata) the module provides some
  84. wrapper classes which ease getting and setting values. The wrapper supports
  85. chained usage for retrieving wrappers of entity properties, e.g. to get a
  86. node author's mail address one could use:
  87. $wrapper = entity_metadata_wrapper('node', $node);
  88. $wrapper->author->mail->value();
  89. To update the user's mail address one could use
  90. $wrapper->author->mail->set('sepp@example.com');
  91. or
  92. $wrapper->author->mail = 'sepp@example.com';
  93. The wrappers always return the data as described in the property
  94. information, which may be retrieved directly via entity_get_property_info()
  95. or from the wrapper:
  96. $mail_info = $wrapper->author->mail->info();
  97. In order to force getting a textual value sanitized for output one can use,
  98. e.g.
  99. $wrapper->title->value(array('sanitize' => TRUE));
  100. to get the sanitized node title. When a property is already returned
  101. sanitized by default, like the node body, one possibly wants to get the
  102. not-sanitized data as it would appear in a browser for other use-cases.
  103. To do so one can enable the 'decode' option, which ensures for any sanitized
  104. data the tags are stripped and HTML entities are decoded before the property
  105. is returned:
  106. $wrapper->body->value->value(array('decode' => TRUE));
  107. That way one always gets the data as shown to the user. However if you
  108. really want to get the raw, unprocessed value, even for sanitized textual
  109. data, you can do so via:
  110. $wrapper->body->value->raw();