Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
project
drupal
Commits
52195a6b
Commit
52195a6b
authored
Feb 11, 2010
by
webchick
Browse files
#525622
by scor, catch, and yched: Allow Entity path callback to deal with options.
parent
30ae1fb5
Changes
7
Hide whitespace changes
Inline
Side-by-side
includes/common.inc
View file @
52195a6b
...
...
@@ -6567,19 +6567,21 @@ function entity_prepare_view($entity_type, $entities) {
}
/**
* Returns the
path to
an entity.
* Returns the
uri elements of
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.
* An array containing the 'path' and 'options' keys used to build the uri of
* the entity, and matching the signature of url(). NULL if the entity has no
* uri of its own.
*/
function
entity_
path
(
$entity_type
,
$entity
)
{
function
entity_
uri
(
$entity_type
,
$entity
)
{
$info
=
entity_get_info
(
$entity_type
);
if
(
isset
(
$info
[
'
path
callback'
])
&&
function_exists
(
$info
[
'
path
callback'
]))
{
return
$info
[
'
path
callback'
](
$entity
);
if
(
isset
(
$info
[
'
uri
callback'
])
&&
function_exists
(
$info
[
'
uri
callback'
]))
{
return
$info
[
'
uri
callback'
](
$entity
)
+
array
(
'options'
=>
array
())
;
}
}
/**
...
...
modules/comment/comment.module
View file @
52195a6b
...
...
@@ -97,7 +97,7 @@ function comment_entity_info() {
'comment'
=>
array
(
'label'
=>
t
(
'Comment'
),
'base table'
=>
'comment'
,
'
path
callback'
=>
'comment_
path
'
,
'
uri
callback'
=>
'comment_
uri
'
,
'fieldable'
=>
TRUE
,
'controller class'
=>
'CommentController'
,
'object keys'
=>
array
(
...
...
@@ -148,10 +148,13 @@ function comment_node_type_load($name) {
}
/**
* Entity
path
callback.
* Entity
uri
callback.
*/
function
comment_path
(
$comment
)
{
return
'comment/'
.
$comment
->
cid
;
function
comment_uri
(
$comment
)
{
return
array
(
'path'
=>
'comment/'
.
$comment
->
cid
,
'options'
=>
array
(
'fragment'
=>
'comment-'
.
$comment
->
cid
),
);
}
/**
...
...
modules/image/image.field.inc
View file @
52195a6b
...
...
@@ -461,7 +461,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
)
{
$
path
=
entity_
path
(
$obj_type
,
$object
);
$
uri
=
entity_
uri
(
$obj_type
,
$object
);
}
elseif
(
strpos
(
$display
[
'type'
],
'image_link_file'
)
===
0
)
{
$link_file
=
TRUE
;
...
...
@@ -469,17 +469,20 @@ function image_field_formatter_view($obj_type, $object, $field, $instance, $lang
foreach
(
$items
as
$delta
=>
$item
)
{
if
(
isset
(
$link_file
))
{
$path
=
file_create_url
(
$item
[
'uri'
]);
$uri
=
array
(
'path'
=>
file_create_url
(
$item
[
'uri'
]),
'options'
=>
array
(),
);
}
$element
[
$delta
]
=
array
(
'#theme'
=>
'image_formatter'
,
'#item'
=>
$item
,
'#image_style'
=>
isset
(
$image_style
)
?
$image_style
:
''
,
'#path'
=>
isset
(
$
path
)
?
$
path
:
''
,
'#path'
=>
isset
(
$
uri
)
?
$
uri
:
''
,
);
}
return
$element
;
return
$element
;
}
/**
...
...
@@ -502,7 +505,11 @@ function theme_image_formatter($variables) {
}
if
(
$variables
[
'path'
])
{
$output
=
l
(
$output
,
$variables
[
'path'
],
array
(
'html'
=>
TRUE
));
$path
=
$variables
[
'path'
][
'path'
];
$options
=
$variables
[
'path'
][
'options'
];
// When displaying an image inside a link, the html option must be TRUE.
$options
[
'html'
]
=
TRUE
;
$output
=
l
(
$output
,
$path
,
$options
);
}
return
$output
;
...
...
modules/node/node.module
View file @
52195a6b
...
...
@@ -185,7 +185,7 @@ function node_entity_info() {
'controller class'
=>
'NodeController'
,
'base table'
=>
'node'
,
'revision table'
=>
'node_revision'
,
'
path
callback'
=>
'node_
path
'
,
'
uri
callback'
=>
'node_
uri
'
,
'fieldable'
=>
TRUE
,
'object keys'
=>
array
(
'id'
=>
'nid'
,
...
...
@@ -243,10 +243,12 @@ function node_entity_info() {
}
/**
* Entity
path
callback.
* Entity
uri
callback.
*/
function
node_path
(
$node
)
{
return
'node/'
.
$node
->
nid
;
function
node_uri
(
$node
)
{
return
array
(
'path'
=>
'node/'
.
$node
->
nid
,
);
}
/**
...
...
modules/system/system.api.php
View file @
52195a6b
...
...
@@ -66,8 +66,9 @@ 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.
* - 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().
* - 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:
...
...
modules/taxonomy/taxonomy.module
View file @
52195a6b
...
...
@@ -87,7 +87,7 @@ function taxonomy_entity_info() {
'label'
=>
t
(
'Taxonomy term'
),
'controller class'
=>
'TaxonomyTermController'
,
'base table'
=>
'taxonomy_term_data'
,
'
path
callback'
=>
'taxonomy_term_
path
'
,
'
uri
callback'
=>
'taxonomy_term_
uri
'
,
'fieldable'
=>
TRUE
,
'object keys'
=>
array
(
'id'
=>
'tid'
,
...
...
@@ -130,10 +130,12 @@ function taxonomy_entity_info() {
}
/**
* Entity
path
callback.
* Entity
uri
callback.
*/
function
taxonomy_term_path
(
$term
)
{
return
'taxonomy/term/'
.
$term
->
tid
;
function
taxonomy_term_uri
(
$term
)
{
return
array
(
'path'
=>
'taxonomy/term/'
.
$term
->
tid
,
);
}
/**
...
...
modules/user/user.module
View file @
52195a6b
...
...
@@ -125,7 +125,7 @@ function user_entity_info() {
'label'
=>
t
(
'User'
),
'controller class'
=>
'UserController'
,
'base table'
=>
'users'
,
'
path
callback'
=>
'user_
path
'
,
'
uri
callback'
=>
'user_
uri
'
,
'fieldable'
=>
TRUE
,
'object keys'
=>
array
(
'id'
=>
'uid'
,
...
...
@@ -150,10 +150,12 @@ function user_entity_info() {
}
/**
* Entity
path
callback.
* Entity
uri
callback.
*/
function
user_path
(
$user
)
{
return
'user/'
.
$user
->
uid
;
function
user_uri
(
$user
)
{
return
array
(
'path'
=>
'user/'
.
$user
->
uid
,
);
}
/**
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment