diff options
-rw-r--r-- | includes/common.inc | 17 | ||||
-rw-r--r-- | modules/comment/comment.module | 8 | ||||
-rw-r--r-- | modules/image/image.field.inc | 3 | ||||
-rw-r--r-- | modules/node/node.module | 8 | ||||
-rw-r--r-- | modules/system/system.api.php | 3 | ||||
-rw-r--r-- | modules/taxonomy/taxonomy.module | 8 | ||||
-rw-r--r-- | modules/user/user.module | 7 |
7 files changed, 52 insertions, 2 deletions
diff --git a/includes/common.inc b/includes/common.inc index 8d5f637d3..f8fb336c6 100644 --- a/includes/common.inc +++ b/includes/common.inc @@ -6525,6 +6525,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). * * @param $url diff --git a/modules/comment/comment.module b/modules/comment/comment.module index 678c92bf2..0b3fc2d8c 100644 --- a/modules/comment/comment.module +++ b/modules/comment/comment.module @@ -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( @@ -126,6 +127,13 @@ function comment_entity_info() { } /** + * Entity path callback. + */ +function comment_path($comment) { + return 'comment/' . $comment->cid; +} + +/** * Implements hook_theme(). */ function comment_theme() { diff --git a/modules/image/image.field.inc b/modules/image/image.field.inc index f7bb499de..1b4a96852 100644 --- a/modules/image/image.field.inc +++ b/modules/image/image.field.inc @@ -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; diff --git a/modules/node/node.module b/modules/node/node.module index 13fb334df..af855d7ca 100644 --- a/modules/node/node.module +++ b/modules/node/node.module @@ -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', @@ -242,6 +243,13 @@ function node_entity_info() { } /** + * Entity path callback. + */ +function node_path($node) { + return 'node/' . $node->nid; +} + +/** * Implements hook_admin_paths(). */ function node_admin_paths() { diff --git a/modules/system/system.api.php b/modules/system/system.api.php index f8f20b8cc..f92da9012 100644 --- a/modules/system/system.api.php +++ b/modules/system/system.api.php @@ -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', diff --git a/modules/taxonomy/taxonomy.module b/modules/taxonomy/taxonomy.module index 1c9378613..bcfc1c0e9 100644 --- a/modules/taxonomy/taxonomy.module +++ b/modules/taxonomy/taxonomy.module @@ -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', @@ -129,6 +130,13 @@ function taxonomy_entity_info() { } /** + * Entity path callback. + */ +function taxonomy_term_path($term) { + return 'taxonomy/term/' . $term->tid; +} + +/** * Return nodes attached to a term across all field instances. * * This function requires taxonomy module to be maintaining its own tables, diff --git a/modules/user/user.module b/modules/user/user.module index 313ff34a4..0b7c17a93 100644 --- a/modules/user/user.module +++ b/modules/user/user.module @@ -149,6 +149,13 @@ function user_entity_info() { } /** + * Entity path callback. + */ +function user_path($user) { + return 'user/' . $user->uid; +} + +/** * Implements hook_field_extra_fields(). */ function user_field_extra_fields() { |