summaryrefslogtreecommitdiff
path: root/modules/system
diff options
context:
space:
mode:
authorJennifer Hodgdon <yahgrp@poplarware.com>2013-04-04 15:52:56 -0700
committerJennifer Hodgdon <yahgrp@poplarware.com>2013-04-04 15:52:56 -0700
commit558e9a7da1f731fbee30963ddb6ec077bf579736 (patch)
treeef08aa6395e227aedb7663947f07ca6163eea9be /modules/system
parentf854613f463affbcde6ae0a3729c32cb2e02df45 (diff)
downloadbrdo-558e9a7da1f731fbee30963ddb6ec077bf579736.tar.gz
brdo-558e9a7da1f731fbee30963ddb6ec077bf579736.tar.bz2
Issue #1943664 by joachim: Use new standards to document entity info callback functions
Diffstat (limited to 'modules/system')
-rw-r--r--modules/system/system.api.php111
1 files changed, 90 insertions, 21 deletions
diff --git a/modules/system/system.api.php b/modules/system/system.api.php
index ce4fb5fe8..e82ac8967 100644
--- a/modules/system/system.api.php
+++ b/modules/system/system.api.php
@@ -84,25 +84,23 @@ function hook_hook_info_alter(&$hooks) {
* Defaults to TRUE.
* - load hook: The name of the hook which should be invoked by
* DrupalDefaultEntityController:attachLoad(), for example 'node_load'.
- * - uri callback: 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().
- * - label callback: (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 title of a
- * node or the subject of a comment. If there is an entity object property
- * that defines the label, use the 'label' 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.
- * - language callback: (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
+ * - uri callback: The name of an implementation of
+ * callback_entity_info_uri().
+ * - label callback: (optional) The name of an implementation of
+ * callback_entity_info_label(), which returns the label of the entity. The
+ * entity label is the main string associated with an entity; for example,
+ * the title of a node or the subject of a comment. If there is an entity
+ * object property that defines the label, then using the 'label' element of
+ * the 'entity keys' return value component suffices to provide this
+ * information (see below). Alternatively, specifying this callback allows
+ * more complex logic to determine the label of an entity. See also the
+ * entity_label() function, which implements this logic.
+ * - language callback: (optional) The name of an implementation of
+ * callback_entity_info_language(). 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
* language property, instead of using the callback as main entity language
* source. In fact not having a language property defined is likely to
* prevent an entity from being queried by language. Moreover, given that
@@ -2302,7 +2300,7 @@ function hook_theme_registry_alter(&$theme_registry) {
* @return
* The machine-readable name of the theme that should be used for the current
* page request. The value returned from this function will only have an
- * effect if it corresponds to a currently-active theme on the site. Do not
+ * effect if it corresponds to a currently-active theme on the site. Do not
* return a value if you do not wish to set a custom theme.
*/
function hook_custom_theme() {
@@ -3639,7 +3637,7 @@ function hook_registry_files_alter(&$files, $modules) {
* inspect later. It is important to remove any temporary variables using
* variable_del() before your last task has completed and control is handed
* back to the installer.
- *
+ *
* @param array $install_state
* An array of information about the current installation state.
*
@@ -4690,6 +4688,77 @@ function hook_filetransfer_info_alter(&$filetransfer_info) {
*/
/**
+ * @addtogroup callbacks
+ * @{
+ */
+
+/**
+ * Return the URI for an entity.
+ *
+ * Callback for hook_entity_info().
+ *
+ * @param $entity
+ * The entity to return the URI for.
+ *
+ * @return
+ * An associative array with the following elements:
+ * - 'path': The URL path for the entity.
+ * - 'options': (optional) An array of options for the url() function.
+ * The actual entity URI can be constructed by passing these elements to
+ * url().
+ */
+function callback_entity_info_uri($entity) {
+ return array(
+ 'path' => 'node/' . $entity->nid,
+ );
+}
+
+/**
+ * Return the label of an entity.
+ *
+ * Callback for hook_entity_info().
+ *
+ * @param $entity
+ * The entity for which to generate the label.
+ * @param $entity_type
+ * The entity type; e.g., 'node' or 'user'.
+ *
+ * @return
+ * An unsanitized string with the label of the entity.
+ *
+ * @see entity_label()
+ */
+function callback_entity_info_label($entity, $entity_type) {
+ return empty($entity->title) ? 'Untitled entity' : $entity->title;
+}
+
+/**
+ * Return the language code of the entity.
+ *
+ * Callback for hook_entity_info().
+ *
+ * The language callback is meant to be used primarily for temporary alterations
+ * of the property value.
+ *
+ * @param $entity
+ * The entity for which to return the language.
+ * @param $entity_type
+ * The entity type; e.g., 'node' or 'user'.
+ *
+ * @return
+ * The language code for the language of the entity.
+ *
+ * @see entity_language()
+ */
+function callback_entity_info_language($entity, $entity_type) {
+ return $entity->language;
+}
+
+/**
+ * @} End of "addtogroup callbacks".
+ */
+
+/**
* @defgroup update_api Update versions of API functions
* @{
* Functions that are similar to normal API functions, but do not invoke hooks.