Commit 83c97345 authored by webchick's avatar webchick

#525622 by Frando, yched, et al: Add entity hook callbacks so that 'as link'...

#525622 by Frando, yched, et al: Add entity hook callbacks so that 'as link' formatters have a generic way to build the url of an 'entity'.
parent c78283e8
......@@ -6524,6 +6524,23 @@ function entity_prepare_view($entity_type, $entities) {
}
}
/**
* Returns the path to an entity.
*
* @param $entity_type
* The entity type; e.g. 'node' or 'user'.
* @param $entity
* The entity for which to generate a path.
* @return
* The path for the entity, or NULL if the entity has no page of its own.
*/
function entity_path($entity_type, $entity) {
$info = entity_get_info($entity_type);
if (isset($info['path callback']) && function_exists($info['path callback'])) {
return $info['path callback']($entity);
}
}
/**
* Performs one or more XML-RPC request(s).
*
......
......@@ -97,6 +97,7 @@ function comment_entity_info() {
'comment' => array(
'label' => t('Comment'),
'base table' => 'comment',
'path callback' => 'comment_path',
'fieldable' => TRUE,
'controller class' => 'CommentController',
'object keys' => array(
......@@ -125,6 +126,13 @@ function comment_entity_info() {
return $return;
}
/**
* Entity path callback.
*/
function comment_path($comment) {
return 'comment/' . $comment->cid;
}
/**
* Implements hook_theme().
*/
......
......@@ -463,8 +463,7 @@ function image_field_formatter_view($obj_type, $object, $field, $instance, $lang
// Check if the formatter involves a link.
if (strpos($display['type'], 'image_link_content') === 0) {
list($id) = entity_extract_ids($obj_type, $object);
$path = $obj_type . '/' . $id;
$path = entity_path($obj_type, $object);
}
elseif (strpos($display['type'], 'image_link_file') === 0) {
$link_file = TRUE;
......
......@@ -185,6 +185,7 @@ function node_entity_info() {
'controller class' => 'NodeController',
'base table' => 'node',
'revision table' => 'node_revision',
'path callback' => 'node_path',
'fieldable' => TRUE,
'object keys' => array(
'id' => 'nid',
......@@ -241,6 +242,13 @@ function node_entity_info() {
return $return;
}
/**
* Entity path callback.
*/
function node_path($node) {
return 'node/' . $node->nid;
}
/**
* Implements hook_admin_paths().
*/
......
......@@ -66,6 +66,8 @@ function hook_hook_info() {
* static caching of entities during a page request. Defaults to TRUE.
* - load hook: The name of the hook which should be invoked by
* DrupalDefaultEntityController:attachLoad(), for example 'node_load'.
* - path callback: A function taking an entity as argument and returning the
* path to the entity.
* - fieldable: Set to TRUE if you want your entity type to be fieldable.
* - object keys: An array describing how the Field API can extract the
* information it needs from the objects of the type. Elements:
......@@ -126,6 +128,7 @@ function hook_entity_info() {
'controller class' => 'NodeController',
'base table' => 'node',
'revision table' => 'node_revision',
'path callback' => 'node_path',
'fieldable' => TRUE,
'object keys' => array(
'id' => 'nid',
......
......@@ -87,6 +87,7 @@ function taxonomy_entity_info() {
'label' => t('Taxonomy term'),
'controller class' => 'TaxonomyTermController',
'base table' => 'taxonomy_term_data',
'path callback' => 'taxonomy_term_path',
'fieldable' => TRUE,
'object keys' => array(
'id' => 'tid',
......@@ -128,6 +129,13 @@ function taxonomy_entity_info() {
return $return;
}
/**
* Entity path callback.
*/
function taxonomy_term_path($term) {
return 'taxonomy/term/' . $term->tid;
}
/**
* Return nodes attached to a term across all field instances.
*
......
......@@ -148,6 +148,13 @@ function user_entity_info() {
return $return;
}
/**
* Entity path callback.
*/
function user_path($user) {
return 'user/' . $user->uid;
}
/**
* Implements hook_field_extra_fields().
*/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment