danielebarchiesi@4: array( danielebarchiesi@4: 'label' => t('Test Entity'), danielebarchiesi@4: 'entity class' => 'Entity', danielebarchiesi@4: 'controller class' => 'EntityAPIController', danielebarchiesi@4: 'base table' => 'entity_test', danielebarchiesi@4: 'module' => 'entity_test', danielebarchiesi@4: 'fieldable' => TRUE, danielebarchiesi@4: 'entity keys' => array( danielebarchiesi@4: 'id' => 'pid', danielebarchiesi@4: 'name' => 'name', danielebarchiesi@4: 'bundle' => 'type', danielebarchiesi@4: ), danielebarchiesi@4: 'bundles' => array(), danielebarchiesi@4: ), danielebarchiesi@4: ); danielebarchiesi@4: foreach (entity_test_get_types() as $name => $info) { danielebarchiesi@4: $return['entity_test']['bundles'][$name] = array( danielebarchiesi@4: 'label' => $info['label'], danielebarchiesi@4: ); danielebarchiesi@4: } danielebarchiesi@4: return $return; danielebarchiesi@4: } danielebarchiesi@4: danielebarchiesi@4: /** danielebarchiesi@4: * Provide additional metadata for entities. danielebarchiesi@4: * danielebarchiesi@4: * This is a placeholder for describing further keys for hook_entity_info(), danielebarchiesi@4: * which are introduced the entity API in order to support any entity type; e.g. danielebarchiesi@4: * to make entity_save(), entity_create(), entity_view() and others work. danielebarchiesi@4: * See entity_crud_hook_entity_info() for the documentation of additional keys danielebarchiesi@4: * for hook_entity_info() as introduced by the entity API for providing new danielebarchiesi@4: * entity types with the entity CRUD API. danielebarchiesi@4: * danielebarchiesi@4: * Additional keys are: danielebarchiesi@4: * - plural label: (optional) The human-readable, plural name of the entity danielebarchiesi@4: * type. As 'label' it should start capitalized. danielebarchiesi@4: * - description: (optional) A human-readable description of the entity type. danielebarchiesi@4: * - access callback: (optional) Specify a callback that returns access danielebarchiesi@4: * permissions for the operations 'create', 'update', 'delete' and 'view'. danielebarchiesi@4: * The callback gets optionally the entity and the user account to check for danielebarchiesi@4: * passed. See entity_access() for more details on the arguments and danielebarchiesi@4: * entity_metadata_no_hook_node_access() for an example. danielebarchiesi@4: * - creation callback: (optional) A callback that creates a new instance of danielebarchiesi@4: * this entity type. See entity_metadata_create_node() for an example. danielebarchiesi@4: * - save callback: (optional) A callback that permanently saves an entity of danielebarchiesi@4: * this type. danielebarchiesi@4: * - deletion callback: (optional) A callback that permanently deletes an danielebarchiesi@4: * entity of this type. danielebarchiesi@4: * - revision deletion callback: (optional) A callback that deletes a revision danielebarchiesi@4: * of the entity. danielebarchiesi@4: * - view callback: (optional) A callback to render a list of entities. danielebarchiesi@4: * See entity_metadata_view_node() as example. danielebarchiesi@4: * - form callback: (optional) A callback that returns a fully built edit form danielebarchiesi@4: * for the entity type. danielebarchiesi@4: * - token type: (optional) A type name to use for token replacements. Set it danielebarchiesi@4: * to FALSE if there aren't any token replacements for this entity type. danielebarchiesi@4: * - configuration: (optional) A boolean value that specifies whether the entity danielebarchiesi@4: * type should be considered as configuration. Modules working with entities danielebarchiesi@4: * may use this value to decide whether they should deal with a certain entity danielebarchiesi@4: * type. Defaults to TRUE to for entity types that are exportable, else to danielebarchiesi@4: * FALSE. danielebarchiesi@4: * danielebarchiesi@4: * @see hook_entity_info() danielebarchiesi@4: * @see entity_crud_hook_entity_info() danielebarchiesi@4: * @see entity_access() danielebarchiesi@4: * @see entity_create() danielebarchiesi@4: * @see entity_save() danielebarchiesi@4: * @see entity_delete() danielebarchiesi@4: * @see entity_view() danielebarchiesi@4: * @see entity_form() danielebarchiesi@4: */ danielebarchiesi@4: function entity_metadata_hook_entity_info() { danielebarchiesi@4: return array( danielebarchiesi@4: 'node' => array( danielebarchiesi@4: 'label' => t('Node'), danielebarchiesi@4: 'access callback' => 'entity_metadata_no_hook_node_access', danielebarchiesi@4: // ... danielebarchiesi@4: ), danielebarchiesi@4: ); danielebarchiesi@4: } danielebarchiesi@4: danielebarchiesi@4: /** danielebarchiesi@4: * Allow modules to define metadata about entity properties. danielebarchiesi@4: * danielebarchiesi@4: * Modules providing properties for any entities defined in hook_entity_info() danielebarchiesi@4: * can implement this hook to provide metadata about this properties. danielebarchiesi@4: * For making use of the metadata have a look at the provided wrappers returned danielebarchiesi@4: * by entity_metadata_wrapper(). danielebarchiesi@4: * For providing property information for fields see entity_hook_field_info(). danielebarchiesi@4: * danielebarchiesi@4: * @return danielebarchiesi@4: * An array whose keys are entity type names and whose values are arrays danielebarchiesi@4: * containing the keys: danielebarchiesi@4: * - properties: The array describing all properties for this entity. Entries danielebarchiesi@4: * are keyed by the property name and contain an array of metadata for each danielebarchiesi@4: * property. The name may only contain alphanumeric lowercase characters danielebarchiesi@4: * and underscores. Known keys are: danielebarchiesi@4: * - label: A human readable, translated label for the property. danielebarchiesi@4: * - description: (optional) A human readable, translated description for danielebarchiesi@4: * the property. danielebarchiesi@4: * - type: The data type of the property. To make the property actually danielebarchiesi@4: * useful it is important to map your properties to one of the known data danielebarchiesi@4: * types, which currently are: danielebarchiesi@4: * - text: Any text. danielebarchiesi@4: * - token: A string containing only lowercase letters, numbers, and danielebarchiesi@4: * underscores starting with a letter; e.g. this type is useful for danielebarchiesi@4: * machine readable names. danielebarchiesi@4: * - integer: A usual PHP integer value. danielebarchiesi@4: * - decimal: A PHP float or integer. danielebarchiesi@4: * - date: A full date and time, as timestamp. danielebarchiesi@4: * - duration: A duration as number of seconds. danielebarchiesi@4: * - boolean: A usual PHP boolean value. danielebarchiesi@4: * - uri: An absolute URI or URL. danielebarchiesi@4: * - entities - You may use the type of each entity known by danielebarchiesi@4: * hook_entity_info(), e.g. 'node' or 'user'. Internally entities are danielebarchiesi@4: * represented by their identifieres. In case of single-valued danielebarchiesi@4: * properties getter callbacks may return full entity objects as well, danielebarchiesi@4: * while a value of FALSE is interpreted like a NULL value as "property danielebarchiesi@4: * is not set". danielebarchiesi@4: * - entity: A special type to be used generically for entities where the danielebarchiesi@4: * entity type is not known beforehand. The entity has to be danielebarchiesi@4: * represented using an EntityMetadataWrapper. danielebarchiesi@4: * - struct: This as well as any else not known type may be used for danielebarchiesi@4: * supporting arbitrary data structures. For that additional metadata danielebarchiesi@4: * has to be specified with the 'property info' key. New type names danielebarchiesi@4: * have to be properly prefixed with the module name. danielebarchiesi@4: * - list: A list of values, represented as numerically indexed array. danielebarchiesi@4: * The list notation may be used to specify the type of the danielebarchiesi@4: * contained items, where TYPE may be any valid type expression. danielebarchiesi@4: * - bundle: (optional) If the property is an entity, you may specify the danielebarchiesi@4: * bundle of the referenced entity. danielebarchiesi@4: * - options list: (optional) A callback that returns a list of possible danielebarchiesi@4: * values for the property. The callback has to return an array as danielebarchiesi@4: * used by hook_options_list(). danielebarchiesi@4: * Note that it is possible to return a different set of options depending danielebarchiesi@4: * whether they are used in read or in write context. See danielebarchiesi@4: * EntityMetadataWrapper::optionsList() for more details on that. danielebarchiesi@4: * - getter callback: (optional) A callback used to retrieve the value of danielebarchiesi@4: * the property. Defaults to entity_property_verbatim_get(). danielebarchiesi@4: * It is important that your data is represented, as documented for your danielebarchiesi@4: * data type, e.g. a date has to be a timestamp. Thus if necessary, the danielebarchiesi@4: * getter callback has to do the necessary conversion. In case of an empty danielebarchiesi@4: * or not set value, the callback has to return NULL. danielebarchiesi@4: * - setter callback: (optional) A callback used to set the value of the danielebarchiesi@4: * property. In many cases entity_property_verbatim_set() can be used. danielebarchiesi@4: * - validation callback: (optional) A callback that returns whether the danielebarchiesi@4: * passed data value is valid for the property. May be used to implement danielebarchiesi@4: * additional validation checks, such as to ensure the value is a valid danielebarchiesi@4: * mail address. danielebarchiesi@4: * - access callback: (optional) An access callback to allow for checking danielebarchiesi@4: * 'view' and 'edit' access for the described property. If no callback danielebarchiesi@4: * is specified, a 'setter permission' may be specified instead. danielebarchiesi@4: * - setter permission: (optional) A permission that describes whether danielebarchiesi@4: * a user has permission to set ('edit') this property. This permission danielebarchiesi@4: * is only be taken into account, if no 'access callback' is given. danielebarchiesi@4: * - schema field: (optional) In case the property is directly based upon danielebarchiesi@4: * a field specified in the entity's hook_schema(), the name of the field. danielebarchiesi@4: * - queryable: (optional) Whether a property is queryable with danielebarchiesi@4: * EntityFieldQuery. Defaults to TRUE if a 'schema field' is specified, or danielebarchiesi@4: * if the deprecated 'query callback' is set to danielebarchiesi@4: * 'entity_metadata_field_query'. Otherwise it defaults to FALSE. danielebarchiesi@4: * - query callback: (deprecated) A callback for querying for entities danielebarchiesi@4: * having the given property value. See entity_property_query(). danielebarchiesi@4: * Generally, properties should be queryable via EntityFieldQuery. If danielebarchiesi@4: * that is the case, just set 'queryable' to TRUE. danielebarchiesi@4: * - required: (optional) Whether this property is required for the creation danielebarchiesi@4: * of a new instance of its entity. See danielebarchiesi@4: * entity_property_values_create_entity(). danielebarchiesi@4: * - field: (optional) A boolean indicating whether a property is stemming danielebarchiesi@4: * from a field. danielebarchiesi@4: * - computed: (optional) A boolean indicating whether a property is danielebarchiesi@4: * computed, i.e. the property value is not stored or loaded by the danielebarchiesi@4: * entity's controller but determined on the fly by the getter callback. danielebarchiesi@4: * Defaults to FALSE. danielebarchiesi@4: * - entity views field: (optional) If enabled, the property is danielebarchiesi@4: * automatically exposed as views field available to all views query danielebarchiesi@4: * backends listing this entity-type. As the property value will always be danielebarchiesi@4: * generated from a loaded entity object, this is particularly useful for danielebarchiesi@4: * 'computed' properties. Defaults to FALSE. danielebarchiesi@4: * - sanitized: (optional) For textual properties only, whether the text is danielebarchiesi@4: * already sanitized. In this case you might want to also specify a raw danielebarchiesi@4: * getter callback. Defaults to FALSE. danielebarchiesi@4: * - sanitize: (optional) For textual properties, that are not sanitized danielebarchiesi@4: * yet, specify a function for sanitizing the value. Defaults to danielebarchiesi@4: * check_plain(). danielebarchiesi@4: * - raw getter callback: (optional) For sanitized textual properties, a danielebarchiesi@4: * separate callback which can be used to retrieve the raw, unprocessed danielebarchiesi@4: * value. danielebarchiesi@4: * - clear: (optional) An array of property names, of which the cache should danielebarchiesi@4: * be cleared too once this property is updated. As a rule of thumb any danielebarchiesi@4: * duplicated properties should be avoided though. danielebarchiesi@4: * - property info: (optional) An array of info for an arbitrary data danielebarchiesi@4: * structure together with any else not defined type, see data type danielebarchiesi@4: * 'struct'. Specify metadata in the same way as defined for this hook. danielebarchiesi@4: * - property info alter: (optional) A callback for altering the property danielebarchiesi@4: * info before it is used by the metadata wrappers. danielebarchiesi@4: * - property defaults: (optional) An array of property info defaults for danielebarchiesi@4: * each property derived of the wrapped data item (e.g. an entity). danielebarchiesi@4: * Applied by the metadata wrappers. danielebarchiesi@4: * - auto creation: (optional) Properties of type 'struct' may specify danielebarchiesi@4: * this callback which is used to automatically create the data structure danielebarchiesi@4: * (e.g. an array) if necessary. This is necessary in order to support danielebarchiesi@4: * setting a property of a not yet initialized data structure. danielebarchiesi@4: * See entity_metadata_field_file_callback() for an example. danielebarchiesi@4: * - translatable: (optional) Whether the property is translatable, defaults danielebarchiesi@4: * to FALSE. danielebarchiesi@4: * - entity token: (optional) If Entity tokens module is enabled, the danielebarchiesi@4: * module provides a token for the property if one does not exist yet. danielebarchiesi@4: * Specify FALSE to disable this functionality for the property. danielebarchiesi@4: * - bundles: An array keyed by bundle name containing further metadata danielebarchiesi@4: * related to the bundles only. This array may contain the key 'properties' danielebarchiesi@4: * with an array of info about the bundle specific properties, structured in danielebarchiesi@4: * the same way as the entity properties array. danielebarchiesi@4: * danielebarchiesi@4: * @see hook_entity_property_info_alter() danielebarchiesi@4: * @see entity_get_property_info() danielebarchiesi@4: * @see entity_metadata_wrapper() danielebarchiesi@4: */ danielebarchiesi@4: function hook_entity_property_info() { danielebarchiesi@4: $info = array(); danielebarchiesi@4: $properties = &$info['node']['properties']; danielebarchiesi@4: danielebarchiesi@4: $properties['nid'] = array( danielebarchiesi@4: 'label' => t("Content ID"), danielebarchiesi@4: 'type' => 'integer', danielebarchiesi@4: 'description' => t("The unique content ID."), danielebarchiesi@4: ); danielebarchiesi@4: return $info; danielebarchiesi@4: } danielebarchiesi@4: danielebarchiesi@4: /** danielebarchiesi@4: * Allow modules to alter metadata about entity properties. danielebarchiesi@4: * danielebarchiesi@4: * @see hook_entity_property_info() danielebarchiesi@4: */ danielebarchiesi@4: function hook_entity_property_info_alter(&$info) { danielebarchiesi@4: $properties = &$info['node']['bundles']['poll']['properties']; danielebarchiesi@4: danielebarchiesi@4: $properties['poll-votes'] = array( danielebarchiesi@4: 'label' => t("Poll votes"), danielebarchiesi@4: 'description' => t("The number of votes that have been cast on a poll node."), danielebarchiesi@4: 'type' => 'integer', danielebarchiesi@4: 'getter callback' => 'entity_property_poll_node_get_properties', danielebarchiesi@4: ); danielebarchiesi@4: } danielebarchiesi@4: danielebarchiesi@4: /** danielebarchiesi@4: * Provide entity property information for fields. danielebarchiesi@4: * danielebarchiesi@4: * This is a placeholder for describing further keys for hook_field_info(), danielebarchiesi@4: * which are introduced by the entity API. danielebarchiesi@4: * danielebarchiesi@4: * For providing entity property info for fields each field type may specify a danielebarchiesi@4: * property type to map to using the key 'property_type'. With that info in danielebarchiesi@4: * place useful defaults are generated, which suffice for a lot of field danielebarchiesi@4: * types. danielebarchiesi@4: * However it is possible to specify further callbacks that may alter the danielebarchiesi@4: * generated property info. To do so use the key 'property_callbacks' and set danielebarchiesi@4: * it to an array of function names. Apart from that any property info provided danielebarchiesi@4: * for a field instance using the key 'property info' is added in too. danielebarchiesi@4: * danielebarchiesi@4: * @see entity_field_info_alter() danielebarchiesi@4: * @see entity_metadata_field_text_property_callback() danielebarchiesi@4: */ danielebarchiesi@4: function entity_hook_field_info() { danielebarchiesi@4: return array( danielebarchiesi@4: 'text' => array( danielebarchiesi@4: 'label' => t('Text'), danielebarchiesi@4: 'property_type' => 'text', danielebarchiesi@4: // ... danielebarchiesi@4: ), danielebarchiesi@4: ); danielebarchiesi@4: } danielebarchiesi@4: danielebarchiesi@4: /** danielebarchiesi@4: * Alter the handlers used by the data selection tables provided by this module. danielebarchiesi@4: * danielebarchiesi@4: * @param array $field_handlers danielebarchiesi@4: * An array of the field handler classes to use for specific types. The keys danielebarchiesi@4: * are the types, mapped to their respective classes. Contained types are: danielebarchiesi@4: * - All primitive types known by the entity API (see danielebarchiesi@4: * hook_entity_property_info()). danielebarchiesi@4: * - options: Special type for fields having an options list. danielebarchiesi@4: * - field: Special type for Field API fields. danielebarchiesi@4: * - entity: Special type for entity-valued fields. danielebarchiesi@4: * - relationship: Views relationship handler to use for relationships. danielebarchiesi@4: * Values for all specific entity types can be additionally added. danielebarchiesi@4: * danielebarchiesi@4: * @see entity_views_field_definition() danielebarchiesi@4: * @see entity_views_get_field_handlers() danielebarchiesi@4: */ danielebarchiesi@4: function hook_entity_views_field_handlers_alter(array &$field_handlers) { danielebarchiesi@4: $field_handlers['duration'] = 'example_duration_handler'; danielebarchiesi@4: $field_handlers['node'] = 'example_node_handler'; danielebarchiesi@4: } danielebarchiesi@4: danielebarchiesi@4: /** danielebarchiesi@4: * @} End of "addtogroup hooks". danielebarchiesi@4: */