/* drucafe */

Wednesday, January 30, 2013

hook_entity_info() structure - fill-in

The hook_entity_info hook informs the base system and the Field API about one or more entity types. 

Return value is an array whose keys are entity type names and whose values identify properties of those types that the system needs to know about.

The following properties are possible:

  •   : The human-readable name of the type.
  •   class: The name of the class that is used to load the objects. The class has to implement the DrupalEntityControllerInterface interface. Leave blank to use the   implementation.
  •   : (used by DrupalDefaultEntityController) The name of the entity type's base table.
  •   : The name of the entity type's revision table (if any).
  •   : (used by DrupalDefaultEntityController) FALSE to disable static caching of entities during a page request. Defaults to TRUE.
  •   : (used by Field API loading and saving of field data) FALSE to disable Field API's persistent cache of field data. Only recommended if a higher level persistent cache is available for the entity type. Defaults to TRUE.
  •   : The name of the hook which should be invoked by DrupalDefaultEntityController:attachLoad(), for example 'node_load'.
  •   : A function taking an entity as argument and returning the URI elements of the entity, e.g. 'path' and 'options'. The actual entity URI can be constructed by passing these elements to url().
  •   : (optional) A function taking an entity and an entity type as arguments and returning the label of the entity. The entity label is the main string associated with an entity; for example, the   of a node or the   of a comment. If there is an entity object property that defines the label, use the '   ' element of the 'entity keys' return value component to provide this information (see below). If more complex logic is needed to determine the label of an entity, you can instead specify a callback function here, which will be called to determine the entity label. See also the entity_label() function, which implements this logic.
  •   : (optional) A function taking an entity and an entity type as arguments and returning a language code. In most situations, when needing to determine this value, inspecting a property named after the 'language' element of the 'entity keys' should be enough. The language callback is meant to be used primarily for temporary alterations of the property value: entity-defining modules are encouraged to always define a   property, instead of using the callback as main entity language source. In fact not having a   property defined is likely to prevent an entity from being queried by language. Moreover, given that entity_language() is not necessarily used everywhere it would be appropriate, modules implementing the language callback should be aware that this might not be always called.
  •   : Set to TRUE if you want your entity type to accept fields being attached to it.
  •   : An associative array of modules registered as field translation handlers. Array keys are the module names, array values can be any data structure the module uses to provide field translation. Any empty value disallows the module to appear as a translation handler.
  •   : An array describing how the Field API can extract the information it needs from the objects of the type. Elements:
    •   : The name of the property that contains the primary id of the entity. Every entity object passed to the Field API must have this property and its value must be numeric.
    •   : The name of the property that contains the revision id of the entity. The Field API assumes that all revision ids are unique across all entities of a type. This entry can be omitted if the entities of this type are not versionable.
    •   : The name of the property that contains the bundle name for the entity. The bundle name defines which set of fields are attached to the entity (e.g. what nodes call "content type"). This entry can be omitted if this entity type exposes a single bundle (all entities have the same collection of fields). The name of this single bundle will be the same as the entity type.
    •   : The name of the property that contains the entity label. For example, if the entity's label is located in $entity->subject, then '   ' should be specified here. If complex logic is required to build the label, a 'label callback' should be defined instead (see the 'label callback' section above for details).
    •   : The name of the property, typically 'language', that contains the language code representing the language the entity has been created in. This value may be changed when editing the entity and represents the language its textual components are supposed to have. If no language property is available, the 'language callback' may be used instead. This entry can be omitted if the entities of this type .
  •   : An array describing how the Field API can extract the information it needs from the bundle objects for this type. This entry is required if the 'path' provided in the 'bundles'/'admin' section identifies the bundle using a named menu placeholder whose loader callback returns an object (e.g., $vocabulary for taxonomy terms, or $node_type for nodes). If the path does not include the bundle, or the bundle is just a string rather than an automatically loaded object, then this can be omitted. Elements:
    • bundle: The name of the    of the bundle object that contains the name of the bundle object.
  •   : An array describing all bundles for this object type. Keys are bundles machine names, as found in the objects' 'bundle' property (defined in the 'entity keys' entry above). Elements:
    •   : The human-readable name of the bundle.
    • uri callback: Same as the 'uri callback' key documented above for the entity type, but for the bundle only. When determining the URI of an entity, if a 'uri callback' is defined for both the entity type and the bundle, the one for the   is used.
    •   : An array of information that allows Field UI pages to attach themselves to the existing administration pages for the bundle. Elements:
      •   : the path of the bundle's main administration page, as defined in hook_menu(). If the path includes a placeholder for the bundle, the 'bundle argument' and 'real path' keys below are required.
      •   : The position of the bundle placeholder in 'path', if any.
      •   : The actual path (no placeholder) of the bundle's main administration page. This will be used to generate links.
      •   : As in hook_menu(). 'user_access' will be assumed if no value is provided.
      •   : As in hook_menu().
  •   : An array describing the view modes for the entity type. View modes let entities be displayed differently depending on the context. For instance, a node can be displayed differently on its own page ('   ' mode), on the home page or taxonomy listings ('   ' mode), or in an RSS feed ('   ' mode). Modules taking part in the display of the entity (notably the Field API) can adjust their behavior depending on the requested view mode. An additional '   ' view mode is available for all entity types. This view mode is not intended for actual entity display, but holds default display settings. For each available view mode, administrators can configure whether it should use its own set of field display settings, or just replicate the settings of the 'default' view mode, thus reducing the amount of display configurations to keep track of. Keys of the array are view mode names. Each view mode is described by an array with the following key/value pairs:
    •   : The human-readable name of the view mode
    •   : A boolean specifying whether the view mode should by default use its own custom field display settings. If FALSE, entities displayed in this view mode will reuse the 'default' display settings by default (e.g. right after the module exposing the view mode is enabled), but administrators can later use the Field UI to apply custom display settings specific to the view mode.
Based on: http://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_entity_info/7

1 comment: