annotate sites/all/modules/entity/entity.api.php @ 9:830c812b520f

added smtp module
author root <root@paio.local>
date Mon, 28 Oct 2013 15:34:27 +0000
parents ce11bbd8f642
children
rev   line source
danielebarchiesi@4 1 <?php
danielebarchiesi@4 2
danielebarchiesi@4 3 /**
danielebarchiesi@4 4 * @file
danielebarchiesi@4 5 * Hooks provided by the entity API.
danielebarchiesi@4 6 */
danielebarchiesi@4 7
danielebarchiesi@4 8 /**
danielebarchiesi@4 9 * @addtogroup hooks
danielebarchiesi@4 10 * @{
danielebarchiesi@4 11 */
danielebarchiesi@4 12
danielebarchiesi@4 13 /**
danielebarchiesi@4 14 * Provide an entity type via the entity CRUD API.
danielebarchiesi@4 15 *
danielebarchiesi@4 16 * This is a placeholder for describing further keys for hook_entity_info(),
danielebarchiesi@4 17 * which are introduced the entity API for providing a new entity type with the
danielebarchiesi@4 18 * entity CRUD API. For that the entity API provides two controllers:
danielebarchiesi@4 19 * - EntityAPIController: A regular CRUD controller.
danielebarchiesi@4 20 * - EntityAPIControllerExportable: Extends the regular controller to
danielebarchiesi@4 21 * additionally support exportable entities and/or entities making use of a
danielebarchiesi@4 22 * name key.
danielebarchiesi@4 23 * See entity_metadata_hook_entity_info() for the documentation of additional
danielebarchiesi@4 24 * keys for hook_entity_info() as introduced by the entity API and supported for
danielebarchiesi@4 25 * any entity type.
danielebarchiesi@4 26 *
danielebarchiesi@4 27 * The entity CRUD API supports the following keys:
danielebarchiesi@4 28 * - entity class: (optional) A class the controller will use for instantiating
danielebarchiesi@4 29 * entities. It is suggested to make use of the provided "Entity" class or to
danielebarchiesi@4 30 * extend it.
danielebarchiesi@4 31 * - bundle of: (optional) Entity types can be used as bundles for
danielebarchiesi@4 32 * other entity types. To enable this functionality, use the 'bundle of' key
danielebarchiesi@4 33 * to indicate which entity type this entity serves as a bundle for. But note
danielebarchiesi@4 34 * that the other entity type will still need to declare entities of this
danielebarchiesi@4 35 * type as bundles, as described by the documentation of hook_entity_info().
danielebarchiesi@4 36 * If the other entity type is fieldable, the entity API controller takes
danielebarchiesi@4 37 * care of invoking the field API bundle attachers. Note that
danielebarchiesi@4 38 * field_attach_delete_bundle() has to be invoked manually upon module
danielebarchiesi@4 39 * uninstallation. See entity_test_entity_info() and entity_test_uninstall()
danielebarchiesi@4 40 * for examples.
danielebarchiesi@4 41 * - module: (optional) The module providing the entity type. This is optional,
danielebarchiesi@4 42 * but strongly suggested.
danielebarchiesi@4 43 * - exportable: (optional) Whether the entity is exportable. Defaults to FALSE.
danielebarchiesi@4 44 * If enabled, a name key should be specified and db columns for the module
danielebarchiesi@4 45 * and status key as defined by entity_exportable_schema_fields() have to
danielebarchiesi@4 46 * exist in the entity's base table. Also see 'entity keys' below.
danielebarchiesi@4 47 * This option requires the EntityAPIControllerExportable to work.
danielebarchiesi@4 48 * - entity keys: An array of keys as defined by Drupal core. The following
danielebarchiesi@4 49 * additional keys are used by the entity CRUD API:
danielebarchiesi@4 50 * - name: (optional) The key of the entity property containing the unique,
danielebarchiesi@4 51 * machine readable name of the entity. If specified, this is used as
danielebarchiesi@4 52 * identifier of the entity, while the usual 'id' key is still required and
danielebarchiesi@4 53 * may be used when modules deal with entities generically, or to refer to
danielebarchiesi@4 54 * the entity internally, i.e. in the database.
danielebarchiesi@4 55 * If a name key is given, the name is used as entity identifier by the
danielebarchiesi@4 56 * entity API module, metadata wrappers and entity-type specific hooks.
danielebarchiesi@4 57 * However note that for consistency all generic entity hooks like
danielebarchiesi@4 58 * hook_entity_load() are invoked with the entities keyed by numeric id,
danielebarchiesi@4 59 * while entity-type specific hooks like hook_{entity_type}_load() are
danielebarchiesi@4 60 * invoked with the entities keyed by name.
danielebarchiesi@4 61 * Also, just as entity_load_single() entity_load() may be called
danielebarchiesi@4 62 * with names passed as the $ids parameter, while the results of
danielebarchiesi@4 63 * entity_load() are always keyed by numeric id. Thus, it is suggested to
danielebarchiesi@4 64 * make use of entity_load_multiple_by_name() to implement entity-type
danielebarchiesi@4 65 * specific loading functions like {entity_type}_load_multiple(), as this
danielebarchiesi@4 66 * function returns the entities keyed by name. See entity_test_get_types()
danielebarchiesi@4 67 * for an example.
danielebarchiesi@4 68 * For exportable entities, it is strongly recommended to make use of a
danielebarchiesi@4 69 * machine name as names are portable across systems.
danielebarchiesi@4 70 * This option requires the EntityAPIControllerExportable to work.
danielebarchiesi@4 71 * - module: (optional) A key for the module property used by the entity CRUD
danielebarchiesi@4 72 * API to save the source module name for exportable entities that have been
danielebarchiesi@4 73 * provided in code. Defaults to 'module'.
danielebarchiesi@4 74 * - status: (optional) The name of the entity property used by the entity
danielebarchiesi@4 75 * CRUD API to save the exportable entity status using defined bit flags.
danielebarchiesi@4 76 * Defaults to 'status'. See entity_has_status().
danielebarchiesi@4 77 * - default revision: (optional) The name of the entity property used by
danielebarchiesi@4 78 * the entity CRUD API to determine if a newly-created revision should be
danielebarchiesi@4 79 * set as the default revision. Defaults to 'default_revision'.
danielebarchiesi@4 80 * Note that on entity insert the created revision will be always default
danielebarchiesi@4 81 * regardless of the value of this entity property.
danielebarchiesi@4 82 * - export: (optional) An array of information used for exporting. For ctools
danielebarchiesi@4 83 * exportables compatibility any export-keys supported by ctools may be added
danielebarchiesi@4 84 * to this array too.
danielebarchiesi@4 85 * - default hook: What hook to invoke to find exportable entities that are
danielebarchiesi@4 86 * currently defined. This hook is automatically called by the CRUD
danielebarchiesi@4 87 * controller during entity_load(). Defaults to 'default_' . $entity_type.
danielebarchiesi@4 88 * - admin ui: (optional) An array of optional information used for providing an
danielebarchiesi@4 89 * administrative user interface. To enable the UI at least the path must be
danielebarchiesi@4 90 * given. Apart from that, the 'access callback' (see below) is required for
danielebarchiesi@4 91 * the entity, as well as the 'ENTITY_TYPE_form' for editing, adding and
danielebarchiesi@4 92 * cloning. The form gets the entity and the operation ('edit', 'add' or
danielebarchiesi@4 93 * 'clone') passed. See entity_ui_get_form() for more details.
danielebarchiesi@4 94 * Known keys are:
danielebarchiesi@4 95 * - path: A path where the UI should show up as expected by hook_menu().
danielebarchiesi@4 96 * - controller class: (optional) A controller class name for providing the
danielebarchiesi@4 97 * UI. Defaults to EntityDefaultUIController, which implements an admin UI
danielebarchiesi@4 98 * suiting for managing configuration entities. Other provided controllers
danielebarchiesi@4 99 * suiting for content entities are EntityContentUIController or
danielebarchiesi@4 100 * EntityBundleableUIController (which work fine despite the poorly named
danielebarchiesi@4 101 * 'admin ui' key).
danielebarchiesi@4 102 * For customizing the UI inherit from the default class and override
danielebarchiesi@4 103 * methods as suiting and specify your class as controller class.
danielebarchiesi@4 104 * - file: (optional) The name of the file in which the entity form resides
danielebarchiesi@4 105 * as it is required by hook_menu().
danielebarchiesi@4 106 * - file path: (optional) The path to the file as required by hook_menu. If
danielebarchiesi@4 107 * not set, it defaults to entity type's module's path, thus the entity
danielebarchiesi@4 108 * types 'module' key is required.
danielebarchiesi@4 109 * - menu wildcard: The wildcard to use in paths of the hook_menu() items.
danielebarchiesi@4 110 * Defaults to %entity_object which is the loader provided by Entity API.
danielebarchiesi@4 111 * - rules controller class: (optional) A controller class for providing Rules
danielebarchiesi@4 112 * integration, or FALSE to disable this feature. The given class has to
danielebarchiesi@4 113 * inherit from the class EntityDefaultRulesController, which serves as
danielebarchiesi@4 114 * default in case the entity type is not marked as configuration. For
danielebarchiesi@4 115 * configuration entities it defaults to FALSE.
danielebarchiesi@4 116 * - metadata controller class: (optional) A controller class for providing
danielebarchiesi@4 117 * entity property info. By default some info is generated out of the
danielebarchiesi@4 118 * information provided in your hook_schema() implementation, while only read
danielebarchiesi@4 119 * access is granted to that properties by default. Based upon that the
danielebarchiesi@4 120 * Entity tokens module also generates token replacements for your entity
danielebarchiesi@4 121 * type, once activated.
danielebarchiesi@4 122 * Override the controller class to adapt the defaults and to improve and
danielebarchiesi@4 123 * complete the generated metadata. Set it to FALSE to disable this feature.
danielebarchiesi@4 124 * Defaults to the EntityDefaultMetadataController class.
danielebarchiesi@4 125 * - extra fields controller class: (optional) A controller class for providing
danielebarchiesi@4 126 * field API extra fields. Defaults to none.
danielebarchiesi@4 127 * The class must implement the EntityExtraFieldsControllerInterface. Display
danielebarchiesi@4 128 * extra fields that are exposed that way are rendered by default by the
danielebarchiesi@4 129 * EntityAPIController. The EntityDefaultExtraFieldsController class may be
danielebarchiesi@4 130 * used to generate extra fields based upon property metadata, which in turn
danielebarchiesi@4 131 * get rendered by default by the EntityAPIController.
danielebarchiesi@4 132 * - features controller class: (optional) A controller class for providing
danielebarchiesi@4 133 * Features module integration for exportable entities. The given class has to
danielebarchiesi@4 134 * inherit from the default class being EntityDefaultFeaturesController. Set
danielebarchiesi@4 135 * it to FALSE to disable this feature.
danielebarchiesi@4 136 * - i18n controller class: (optional) A controller class for providing
danielebarchiesi@4 137 * i18n module integration for (exportable) entities. The given class has to
danielebarchiesi@4 138 * inherit from the class EntityDefaultI18nStringController. Defaults to
danielebarchiesi@4 139 * FALSE (disabled). See EntityDefaultI18nStringController for more
danielebarchiesi@4 140 * information.
danielebarchiesi@4 141 * - views controller class: (optional) A controller class for providing views
danielebarchiesi@4 142 * integration. The given class has to inherit from the class
danielebarchiesi@4 143 * EntityDefaultViewsController, which is set as default in case the providing
danielebarchiesi@4 144 * module has been specified (see 'module') and the module does not provide
danielebarchiesi@4 145 * any views integration. Else it defaults to FALSE, which disables this
danielebarchiesi@4 146 * feature. See EntityDefaultViewsController.
danielebarchiesi@4 147 * - access callback: (optional) Specify a callback that returns access
danielebarchiesi@4 148 * permissions for the operations 'create', 'update', 'delete' and 'view'.
danielebarchiesi@4 149 * The callback gets optionally the entity and the user account to check for
danielebarchiesi@4 150 * passed. See entity_access() for more details on the arguments and
danielebarchiesi@4 151 * entity_metadata_no_hook_node_access() for an example.
danielebarchiesi@4 152 * This is optional, but suggested for the Rules integration, and required for
danielebarchiesi@4 153 * the admin ui (see above).
danielebarchiesi@4 154 * - form callback: (optional) Specfiy a callback that returns a fully built
danielebarchiesi@4 155 * edit form for your entity type. See entity_form().
danielebarchiesi@4 156 * In case the 'admin ui' is used, no callback needs to be specified.
danielebarchiesi@4 157 * - entity cache: (optional) Whether entities should be cached using the cache
danielebarchiesi@4 158 * system. Requires the entitycache module to be installed and enabled. As
danielebarchiesi@4 159 * cached entities are only retrieved by id key, the cache would not apply to
danielebarchiesi@4 160 * exportable entities retrieved by name key. If enabled, 'field cache' is
danielebarchiesi@4 161 * obsolete and should be disabled. Defaults to FALSE.
danielebarchiesi@4 162 *
danielebarchiesi@4 163 * @see hook_entity_info()
danielebarchiesi@4 164 * @see entity_metadata_hook_entity_info()
danielebarchiesi@4 165 */
danielebarchiesi@4 166 function entity_crud_hook_entity_info() {
danielebarchiesi@4 167 $return = array(
danielebarchiesi@4 168 'entity_test' => array(
danielebarchiesi@4 169 'label' => t('Test Entity'),
danielebarchiesi@4 170 'entity class' => 'Entity',
danielebarchiesi@4 171 'controller class' => 'EntityAPIController',
danielebarchiesi@4 172 'base table' => 'entity_test',
danielebarchiesi@4 173 'module' => 'entity_test',
danielebarchiesi@4 174 'fieldable' => TRUE,
danielebarchiesi@4 175 'entity keys' => array(
danielebarchiesi@4 176 'id' => 'pid',
danielebarchiesi@4 177 'name' => 'name',
danielebarchiesi@4 178 'bundle' => 'type',
danielebarchiesi@4 179 ),
danielebarchiesi@4 180 'bundles' => array(),
danielebarchiesi@4 181 ),
danielebarchiesi@4 182 );
danielebarchiesi@4 183 foreach (entity_test_get_types() as $name => $info) {
danielebarchiesi@4 184 $return['entity_test']['bundles'][$name] = array(
danielebarchiesi@4 185 'label' => $info['label'],
danielebarchiesi@4 186 );
danielebarchiesi@4 187 }
danielebarchiesi@4 188 return $return;
danielebarchiesi@4 189 }
danielebarchiesi@4 190
danielebarchiesi@4 191 /**
danielebarchiesi@4 192 * Provide additional metadata for entities.
danielebarchiesi@4 193 *
danielebarchiesi@4 194 * This is a placeholder for describing further keys for hook_entity_info(),
danielebarchiesi@4 195 * which are introduced the entity API in order to support any entity type; e.g.
danielebarchiesi@4 196 * to make entity_save(), entity_create(), entity_view() and others work.
danielebarchiesi@4 197 * See entity_crud_hook_entity_info() for the documentation of additional keys
danielebarchiesi@4 198 * for hook_entity_info() as introduced by the entity API for providing new
danielebarchiesi@4 199 * entity types with the entity CRUD API.
danielebarchiesi@4 200 *
danielebarchiesi@4 201 * Additional keys are:
danielebarchiesi@4 202 * - plural label: (optional) The human-readable, plural name of the entity
danielebarchiesi@4 203 * type. As 'label' it should start capitalized.
danielebarchiesi@4 204 * - description: (optional) A human-readable description of the entity type.
danielebarchiesi@4 205 * - access callback: (optional) Specify a callback that returns access
danielebarchiesi@4 206 * permissions for the operations 'create', 'update', 'delete' and 'view'.
danielebarchiesi@4 207 * The callback gets optionally the entity and the user account to check for
danielebarchiesi@4 208 * passed. See entity_access() for more details on the arguments and
danielebarchiesi@4 209 * entity_metadata_no_hook_node_access() for an example.
danielebarchiesi@4 210 * - creation callback: (optional) A callback that creates a new instance of
danielebarchiesi@4 211 * this entity type. See entity_metadata_create_node() for an example.
danielebarchiesi@4 212 * - save callback: (optional) A callback that permanently saves an entity of
danielebarchiesi@4 213 * this type.
danielebarchiesi@4 214 * - deletion callback: (optional) A callback that permanently deletes an
danielebarchiesi@4 215 * entity of this type.
danielebarchiesi@4 216 * - revision deletion callback: (optional) A callback that deletes a revision
danielebarchiesi@4 217 * of the entity.
danielebarchiesi@4 218 * - view callback: (optional) A callback to render a list of entities.
danielebarchiesi@4 219 * See entity_metadata_view_node() as example.
danielebarchiesi@4 220 * - form callback: (optional) A callback that returns a fully built edit form
danielebarchiesi@4 221 * for the entity type.
danielebarchiesi@4 222 * - token type: (optional) A type name to use for token replacements. Set it
danielebarchiesi@4 223 * to FALSE if there aren't any token replacements for this entity type.
danielebarchiesi@4 224 * - configuration: (optional) A boolean value that specifies whether the entity
danielebarchiesi@4 225 * type should be considered as configuration. Modules working with entities
danielebarchiesi@4 226 * may use this value to decide whether they should deal with a certain entity
danielebarchiesi@4 227 * type. Defaults to TRUE to for entity types that are exportable, else to
danielebarchiesi@4 228 * FALSE.
danielebarchiesi@4 229 *
danielebarchiesi@4 230 * @see hook_entity_info()
danielebarchiesi@4 231 * @see entity_crud_hook_entity_info()
danielebarchiesi@4 232 * @see entity_access()
danielebarchiesi@4 233 * @see entity_create()
danielebarchiesi@4 234 * @see entity_save()
danielebarchiesi@4 235 * @see entity_delete()
danielebarchiesi@4 236 * @see entity_view()
danielebarchiesi@4 237 * @see entity_form()
danielebarchiesi@4 238 */
danielebarchiesi@4 239 function entity_metadata_hook_entity_info() {
danielebarchiesi@4 240 return array(
danielebarchiesi@4 241 'node' => array(
danielebarchiesi@4 242 'label' => t('Node'),
danielebarchiesi@4 243 'access callback' => 'entity_metadata_no_hook_node_access',
danielebarchiesi@4 244 // ...
danielebarchiesi@4 245 ),
danielebarchiesi@4 246 );
danielebarchiesi@4 247 }
danielebarchiesi@4 248
danielebarchiesi@4 249 /**
danielebarchiesi@4 250 * Allow modules to define metadata about entity properties.
danielebarchiesi@4 251 *
danielebarchiesi@4 252 * Modules providing properties for any entities defined in hook_entity_info()
danielebarchiesi@4 253 * can implement this hook to provide metadata about this properties.
danielebarchiesi@4 254 * For making use of the metadata have a look at the provided wrappers returned
danielebarchiesi@4 255 * by entity_metadata_wrapper().
danielebarchiesi@4 256 * For providing property information for fields see entity_hook_field_info().
danielebarchiesi@4 257 *
danielebarchiesi@4 258 * @return
danielebarchiesi@4 259 * An array whose keys are entity type names and whose values are arrays
danielebarchiesi@4 260 * containing the keys:
danielebarchiesi@4 261 * - properties: The array describing all properties for this entity. Entries
danielebarchiesi@4 262 * are keyed by the property name and contain an array of metadata for each
danielebarchiesi@4 263 * property. The name may only contain alphanumeric lowercase characters
danielebarchiesi@4 264 * and underscores. Known keys are:
danielebarchiesi@4 265 * - label: A human readable, translated label for the property.
danielebarchiesi@4 266 * - description: (optional) A human readable, translated description for
danielebarchiesi@4 267 * the property.
danielebarchiesi@4 268 * - type: The data type of the property. To make the property actually
danielebarchiesi@4 269 * useful it is important to map your properties to one of the known data
danielebarchiesi@4 270 * types, which currently are:
danielebarchiesi@4 271 * - text: Any text.
danielebarchiesi@4 272 * - token: A string containing only lowercase letters, numbers, and
danielebarchiesi@4 273 * underscores starting with a letter; e.g. this type is useful for
danielebarchiesi@4 274 * machine readable names.
danielebarchiesi@4 275 * - integer: A usual PHP integer value.
danielebarchiesi@4 276 * - decimal: A PHP float or integer.
danielebarchiesi@4 277 * - date: A full date and time, as timestamp.
danielebarchiesi@4 278 * - duration: A duration as number of seconds.
danielebarchiesi@4 279 * - boolean: A usual PHP boolean value.
danielebarchiesi@4 280 * - uri: An absolute URI or URL.
danielebarchiesi@4 281 * - entities - You may use the type of each entity known by
danielebarchiesi@4 282 * hook_entity_info(), e.g. 'node' or 'user'. Internally entities are
danielebarchiesi@4 283 * represented by their identifieres. In case of single-valued
danielebarchiesi@4 284 * properties getter callbacks may return full entity objects as well,
danielebarchiesi@4 285 * while a value of FALSE is interpreted like a NULL value as "property
danielebarchiesi@4 286 * is not set".
danielebarchiesi@4 287 * - entity: A special type to be used generically for entities where the
danielebarchiesi@4 288 * entity type is not known beforehand. The entity has to be
danielebarchiesi@4 289 * represented using an EntityMetadataWrapper.
danielebarchiesi@4 290 * - struct: This as well as any else not known type may be used for
danielebarchiesi@4 291 * supporting arbitrary data structures. For that additional metadata
danielebarchiesi@4 292 * has to be specified with the 'property info' key. New type names
danielebarchiesi@4 293 * have to be properly prefixed with the module name.
danielebarchiesi@4 294 * - list: A list of values, represented as numerically indexed array.
danielebarchiesi@4 295 * The list<TYPE> notation may be used to specify the type of the
danielebarchiesi@4 296 * contained items, where TYPE may be any valid type expression.
danielebarchiesi@4 297 * - bundle: (optional) If the property is an entity, you may specify the
danielebarchiesi@4 298 * bundle of the referenced entity.
danielebarchiesi@4 299 * - options list: (optional) A callback that returns a list of possible
danielebarchiesi@4 300 * values for the property. The callback has to return an array as
danielebarchiesi@4 301 * used by hook_options_list().
danielebarchiesi@4 302 * Note that it is possible to return a different set of options depending
danielebarchiesi@4 303 * whether they are used in read or in write context. See
danielebarchiesi@4 304 * EntityMetadataWrapper::optionsList() for more details on that.
danielebarchiesi@4 305 * - getter callback: (optional) A callback used to retrieve the value of
danielebarchiesi@4 306 * the property. Defaults to entity_property_verbatim_get().
danielebarchiesi@4 307 * It is important that your data is represented, as documented for your
danielebarchiesi@4 308 * data type, e.g. a date has to be a timestamp. Thus if necessary, the
danielebarchiesi@4 309 * getter callback has to do the necessary conversion. In case of an empty
danielebarchiesi@4 310 * or not set value, the callback has to return NULL.
danielebarchiesi@4 311 * - setter callback: (optional) A callback used to set the value of the
danielebarchiesi@4 312 * property. In many cases entity_property_verbatim_set() can be used.
danielebarchiesi@4 313 * - validation callback: (optional) A callback that returns whether the
danielebarchiesi@4 314 * passed data value is valid for the property. May be used to implement
danielebarchiesi@4 315 * additional validation checks, such as to ensure the value is a valid
danielebarchiesi@4 316 * mail address.
danielebarchiesi@4 317 * - access callback: (optional) An access callback to allow for checking
danielebarchiesi@4 318 * 'view' and 'edit' access for the described property. If no callback
danielebarchiesi@4 319 * is specified, a 'setter permission' may be specified instead.
danielebarchiesi@4 320 * - setter permission: (optional) A permission that describes whether
danielebarchiesi@4 321 * a user has permission to set ('edit') this property. This permission
danielebarchiesi@4 322 * is only be taken into account, if no 'access callback' is given.
danielebarchiesi@4 323 * - schema field: (optional) In case the property is directly based upon
danielebarchiesi@4 324 * a field specified in the entity's hook_schema(), the name of the field.
danielebarchiesi@4 325 * - queryable: (optional) Whether a property is queryable with
danielebarchiesi@4 326 * EntityFieldQuery. Defaults to TRUE if a 'schema field' is specified, or
danielebarchiesi@4 327 * if the deprecated 'query callback' is set to
danielebarchiesi@4 328 * 'entity_metadata_field_query'. Otherwise it defaults to FALSE.
danielebarchiesi@4 329 * - query callback: (deprecated) A callback for querying for entities
danielebarchiesi@4 330 * having the given property value. See entity_property_query().
danielebarchiesi@4 331 * Generally, properties should be queryable via EntityFieldQuery. If
danielebarchiesi@4 332 * that is the case, just set 'queryable' to TRUE.
danielebarchiesi@4 333 * - required: (optional) Whether this property is required for the creation
danielebarchiesi@4 334 * of a new instance of its entity. See
danielebarchiesi@4 335 * entity_property_values_create_entity().
danielebarchiesi@4 336 * - field: (optional) A boolean indicating whether a property is stemming
danielebarchiesi@4 337 * from a field.
danielebarchiesi@4 338 * - computed: (optional) A boolean indicating whether a property is
danielebarchiesi@4 339 * computed, i.e. the property value is not stored or loaded by the
danielebarchiesi@4 340 * entity's controller but determined on the fly by the getter callback.
danielebarchiesi@4 341 * Defaults to FALSE.
danielebarchiesi@4 342 * - entity views field: (optional) If enabled, the property is
danielebarchiesi@4 343 * automatically exposed as views field available to all views query
danielebarchiesi@4 344 * backends listing this entity-type. As the property value will always be
danielebarchiesi@4 345 * generated from a loaded entity object, this is particularly useful for
danielebarchiesi@4 346 * 'computed' properties. Defaults to FALSE.
danielebarchiesi@4 347 * - sanitized: (optional) For textual properties only, whether the text is
danielebarchiesi@4 348 * already sanitized. In this case you might want to also specify a raw
danielebarchiesi@4 349 * getter callback. Defaults to FALSE.
danielebarchiesi@4 350 * - sanitize: (optional) For textual properties, that are not sanitized
danielebarchiesi@4 351 * yet, specify a function for sanitizing the value. Defaults to
danielebarchiesi@4 352 * check_plain().
danielebarchiesi@4 353 * - raw getter callback: (optional) For sanitized textual properties, a
danielebarchiesi@4 354 * separate callback which can be used to retrieve the raw, unprocessed
danielebarchiesi@4 355 * value.
danielebarchiesi@4 356 * - clear: (optional) An array of property names, of which the cache should
danielebarchiesi@4 357 * be cleared too once this property is updated. As a rule of thumb any
danielebarchiesi@4 358 * duplicated properties should be avoided though.
danielebarchiesi@4 359 * - property info: (optional) An array of info for an arbitrary data
danielebarchiesi@4 360 * structure together with any else not defined type, see data type
danielebarchiesi@4 361 * 'struct'. Specify metadata in the same way as defined for this hook.
danielebarchiesi@4 362 * - property info alter: (optional) A callback for altering the property
danielebarchiesi@4 363 * info before it is used by the metadata wrappers.
danielebarchiesi@4 364 * - property defaults: (optional) An array of property info defaults for
danielebarchiesi@4 365 * each property derived of the wrapped data item (e.g. an entity).
danielebarchiesi@4 366 * Applied by the metadata wrappers.
danielebarchiesi@4 367 * - auto creation: (optional) Properties of type 'struct' may specify
danielebarchiesi@4 368 * this callback which is used to automatically create the data structure
danielebarchiesi@4 369 * (e.g. an array) if necessary. This is necessary in order to support
danielebarchiesi@4 370 * setting a property of a not yet initialized data structure.
danielebarchiesi@4 371 * See entity_metadata_field_file_callback() for an example.
danielebarchiesi@4 372 * - translatable: (optional) Whether the property is translatable, defaults
danielebarchiesi@4 373 * to FALSE.
danielebarchiesi@4 374 * - entity token: (optional) If Entity tokens module is enabled, the
danielebarchiesi@4 375 * module provides a token for the property if one does not exist yet.
danielebarchiesi@4 376 * Specify FALSE to disable this functionality for the property.
danielebarchiesi@4 377 * - bundles: An array keyed by bundle name containing further metadata
danielebarchiesi@4 378 * related to the bundles only. This array may contain the key 'properties'
danielebarchiesi@4 379 * with an array of info about the bundle specific properties, structured in
danielebarchiesi@4 380 * the same way as the entity properties array.
danielebarchiesi@4 381 *
danielebarchiesi@4 382 * @see hook_entity_property_info_alter()
danielebarchiesi@4 383 * @see entity_get_property_info()
danielebarchiesi@4 384 * @see entity_metadata_wrapper()
danielebarchiesi@4 385 */
danielebarchiesi@4 386 function hook_entity_property_info() {
danielebarchiesi@4 387 $info = array();
danielebarchiesi@4 388 $properties = &$info['node']['properties'];
danielebarchiesi@4 389
danielebarchiesi@4 390 $properties['nid'] = array(
danielebarchiesi@4 391 'label' => t("Content ID"),
danielebarchiesi@4 392 'type' => 'integer',
danielebarchiesi@4 393 'description' => t("The unique content ID."),
danielebarchiesi@4 394 );
danielebarchiesi@4 395 return $info;
danielebarchiesi@4 396 }
danielebarchiesi@4 397
danielebarchiesi@4 398 /**
danielebarchiesi@4 399 * Allow modules to alter metadata about entity properties.
danielebarchiesi@4 400 *
danielebarchiesi@4 401 * @see hook_entity_property_info()
danielebarchiesi@4 402 */
danielebarchiesi@4 403 function hook_entity_property_info_alter(&$info) {
danielebarchiesi@4 404 $properties = &$info['node']['bundles']['poll']['properties'];
danielebarchiesi@4 405
danielebarchiesi@4 406 $properties['poll-votes'] = array(
danielebarchiesi@4 407 'label' => t("Poll votes"),
danielebarchiesi@4 408 'description' => t("The number of votes that have been cast on a poll node."),
danielebarchiesi@4 409 'type' => 'integer',
danielebarchiesi@4 410 'getter callback' => 'entity_property_poll_node_get_properties',
danielebarchiesi@4 411 );
danielebarchiesi@4 412 }
danielebarchiesi@4 413
danielebarchiesi@4 414 /**
danielebarchiesi@4 415 * Provide entity property information for fields.
danielebarchiesi@4 416 *
danielebarchiesi@4 417 * This is a placeholder for describing further keys for hook_field_info(),
danielebarchiesi@4 418 * which are introduced by the entity API.
danielebarchiesi@4 419 *
danielebarchiesi@4 420 * For providing entity property info for fields each field type may specify a
danielebarchiesi@4 421 * property type to map to using the key 'property_type'. With that info in
danielebarchiesi@4 422 * place useful defaults are generated, which suffice for a lot of field
danielebarchiesi@4 423 * types.
danielebarchiesi@4 424 * However it is possible to specify further callbacks that may alter the
danielebarchiesi@4 425 * generated property info. To do so use the key 'property_callbacks' and set
danielebarchiesi@4 426 * it to an array of function names. Apart from that any property info provided
danielebarchiesi@4 427 * for a field instance using the key 'property info' is added in too.
danielebarchiesi@4 428 *
danielebarchiesi@4 429 * @see entity_field_info_alter()
danielebarchiesi@4 430 * @see entity_metadata_field_text_property_callback()
danielebarchiesi@4 431 */
danielebarchiesi@4 432 function entity_hook_field_info() {
danielebarchiesi@4 433 return array(
danielebarchiesi@4 434 'text' => array(
danielebarchiesi@4 435 'label' => t('Text'),
danielebarchiesi@4 436 'property_type' => 'text',
danielebarchiesi@4 437 // ...
danielebarchiesi@4 438 ),
danielebarchiesi@4 439 );
danielebarchiesi@4 440 }
danielebarchiesi@4 441
danielebarchiesi@4 442 /**
danielebarchiesi@4 443 * Alter the handlers used by the data selection tables provided by this module.
danielebarchiesi@4 444 *
danielebarchiesi@4 445 * @param array $field_handlers
danielebarchiesi@4 446 * An array of the field handler classes to use for specific types. The keys
danielebarchiesi@4 447 * are the types, mapped to their respective classes. Contained types are:
danielebarchiesi@4 448 * - All primitive types known by the entity API (see
danielebarchiesi@4 449 * hook_entity_property_info()).
danielebarchiesi@4 450 * - options: Special type for fields having an options list.
danielebarchiesi@4 451 * - field: Special type for Field API fields.
danielebarchiesi@4 452 * - entity: Special type for entity-valued fields.
danielebarchiesi@4 453 * - relationship: Views relationship handler to use for relationships.
danielebarchiesi@4 454 * Values for all specific entity types can be additionally added.
danielebarchiesi@4 455 *
danielebarchiesi@4 456 * @see entity_views_field_definition()
danielebarchiesi@4 457 * @see entity_views_get_field_handlers()
danielebarchiesi@4 458 */
danielebarchiesi@4 459 function hook_entity_views_field_handlers_alter(array &$field_handlers) {
danielebarchiesi@4 460 $field_handlers['duration'] = 'example_duration_handler';
danielebarchiesi@4 461 $field_handlers['node'] = 'example_node_handler';
danielebarchiesi@4 462 }
danielebarchiesi@4 463
danielebarchiesi@4 464 /**
danielebarchiesi@4 465 * @} End of "addtogroup hooks".
danielebarchiesi@4 466 */