Projet

Général

Profil

Paste
Télécharger (7,2 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / entity / README.txt @ be58a50c

1

    
2
Entity API module
3
-----------------
4
by Wolfgang Ziegler, nuppla@zites.net
5

    
6
This module extends the entity API of Drupal core in order to provide a unified
7
way to deal with entities and their properties. Additionally, it provides an
8
entity CRUD controller, which helps simplifying the creation of new entity types.
9

    
10

    
11
This is an API module. You only need to enable it if a module depends on it or
12
you are interested in using it for development.
13

    
14
Advanced usage:
15
---------------
16
You can optimize cache clearing performance by setting the variable
17
'entity_rebuild_on_flush' to FALSE. This skips rebuilding of feature
18
components and exported entities during cache flushing. Instead, it is triggered
19
by the features module only; e.g., when features are reverted.
20

    
21

    
22
The README below is for interested developers. If you are not interested in
23
developing, you may stop reading now.
24

    
25
--------------------------------------------------------------------------------
26
                                Entity API
27
--------------------------------------------------------------------------------
28

    
29
  * The module provides API functions allowing modules to create, save, delete
30
    or to determine access for entities based on any entity type, for which the
31
    necessary metadata is available. The module comes with integration for all
32
    core entity types, as well as for entities provided via the Entity CRUD API
33
    (see below). However, for any other entity type implemented by a contrib
34
    module, the module integration has to be provided by the contrib module
35
    itself.
36

    
37
  * Thus the module provides API functions like entity_save(), entity_create(),
38
    entity_delete(), entity_revision_delete(), entity_view() and entity_access()
39
    among others.
40
    entity_load(), entity_label() and entity_uri() are already provided by
41
    Drupal core.
42

    
43
 *  For more information about how to provide this metadata, have a look at the
44
    API documentation, i.e. entity_metadata_hook_entity_info().
45

    
46
--------------------------------------------------------------------------------
47
               Entity CRUD API - Providing new entity types
48
--------------------------------------------------------------------------------
49

    
50
 * This API helps you when defining a new entity type. It provides an entity
51
   controller, which implements full CRUD functionality for your entities.
52

    
53
 * To make use of the CRUD functionality you may just use the API functions
54
   entity_create(), entity_delete() and entity_save().
55

    
56
   Alternatively you may specify a class to use for your entities, for which the
57
   "Entity" class is provided. In particular, it is useful to extend this class
58
   in order to easily customize the entity type, e.g. saving.
59

    
60
 * The controller supports fieldable entities and revisions. There is also a
61
   controller which supports implementing exportable entities.
62

    
63
 * The Entity CRUD API helps with providing additional module integration too,
64
   e.g. exportable entities are automatically integrated with the Features
65
   module. These module integrations are implemented in separate controller
66
   classes, which may be overridden and deactivated on their own.
67

    
68
 * There is also an optional ui controller class, which assists with providing
69
   an administrative UI for managing entities of a certain type.
70

    
71
 * For more details check out the documentation in the drupal.org handbook
72
   http://drupal.org/node/878804 as well as the API documentation, i.e.
73
   entity_crud_hook_entity_info().
74

    
75

    
76
 Basic steps to add a new entity type:
77
---------------------------------------
78

    
79
  * You might want to study the code of the "entity_test.module".
80

    
81
  * Describe your entities db table as usual in hook_schema().
82

    
83
  * Just use the "Entity" directly or extend it with your own class.
84
    To see how to provide a separate class have a look at the "EntityClass" from
85
    the "entity_test.module".
86

    
87
  * Implement hook_entity_info() for your entity. At least specifiy the
88
    controller class (EntityAPIController, EntityAPIControllerExportable or your
89
    own), your db table and your entity's keys.
90
    Again just look at "entity_test.module"'s hook_entity_info() for guidance.
91

    
92
  * If you want your entity to be fieldable just set 'fieldable' in
93
    hook_entity_info() to TRUE. The field API attachers are then called
94
    automatically in the entity CRUD functions.
95

    
96
  * The entity API is able to deal with bundle objects too (e.g. the node type
97
    object). For that just specify another entity type for the bundle objects
98
    and set the 'bundle of' property for it.
99
    Again just look at "entity_test.module"'s hook_entity_info() for guidance.
100

    
101
  * Schema fields marked as 'serialized' are automatically unserialized upon
102
    loading as well as serialized on saving. If the 'merge' attribute is also
103
    set to TRUE the unserialized data is automatically "merged" into the entity.
104

    
105
  * Further details can be found at http://drupal.org/node/878804.
106

    
107

    
108

    
109
--------------------------------------------------------------------------------
110
                Entity Properties & Entity metadata wrappers
111
--------------------------------------------------------------------------------
112

    
113
  * This module introduces a unique place for metadata about entity properties:
114
    hook_entity_property_info(), whereas hook_entity_property_info() may be
115
    placed in your module's {YOUR_MODULE}.info.inc include file. For details
116
    have a look at the API documentation, i.e. hook_entity_property_info() and
117
    at http://drupal.org/node/878876.
118

    
119
  * The information about entity properties contains the data type and callbacks
120
    for how to get and set the data of the property. That way the data of an
121
    entity can be easily re-used, e.g. to export it into other data formats like
122
    XML.
123

    
124
  * For making use of this information (metadata) the module provides some
125
    wrapper classes which ease getting and setting values. The wrapper supports
126
    chained usage for retrieving wrappers of entity properties, e.g. to get a
127
    node author's mail address one could use:
128

    
129
       $wrapper = entity_metadata_wrapper('node', $node);
130
       $wrapper->author->mail->value();
131

    
132
    To update the user's mail address one could use
133

    
134
       $wrapper->author->mail->set('sepp@example.com');
135

    
136
       or
137

    
138
       $wrapper->author->mail = 'sepp@example.com';
139

    
140
    The wrappers always return the data as described in the property
141
    information, which may be retrieved directly via entity_get_property_info()
142
    or from the wrapper:
143

    
144
       $mail_info = $wrapper->author->mail->info();
145

    
146
    In order to force getting a textual value sanitized for output one can use,
147
    e.g.
148

    
149
       $wrapper->title->value(array('sanitize' => TRUE));
150

    
151
    to get the sanitized node title. When a property is already returned
152
    sanitized by default, like the node body, one possibly wants to get the
153
    not-sanitized data as it would appear in a browser for other use-cases.
154
    To do so one can enable the 'decode' option, which ensures for any sanitized
155
    data the tags are stripped and HTML entities are decoded before the property
156
    is returned:
157

    
158
       $wrapper->body->value->value(array('decode' => TRUE));
159

    
160
    That way one always gets the data as shown to the user. However if you
161
    really want to get the raw, unprocessed value, even for sanitized textual
162
    data, you can do so via:
163

    
164
      $wrapper->body->value->raw();