README.txt 7.2 KB

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