Issue #1618172 by jcisio, corvus_ch, estebanvalerio.h, Berdir: Remove entity_uri() in favor of EntityInterface::uri().

8.0.x
catch 2012-08-22 15:04:43 +02:00
parent 3b308be763
commit ff895df7ac
12 changed files with 15 additions and 60 deletions

View File

@ -2090,9 +2090,9 @@ function _format_date_callback(array $matches = NULL, $new_langcode = NULL) {
* Defaults to empty string when clean URLs are in effect, and to
* 'index.php/' when they are not.
* - 'entity_type': The entity type of the object that called url(). Only
* set if url() is invoked by entity_uri().
* set if url() is invoked by Drupal\entity\Entity::uri().
* - 'entity': The entity object (such as a node) for which the URL is being
* generated. Only set if url() is invoked by entity_uri().
* generated. Only set if url() is invoked by Drupal\entity\Entity::uri().
*
* @return
* A string containing a URL to the given path.

View File

@ -1756,7 +1756,7 @@ function template_preprocess_comment(&$variables) {
$variables['user_picture'] = theme_get_setting('toggle_comment_user_picture') ? theme('user_picture', array('account' => $comment)) : '';
$variables['signature'] = $comment->signature;
$uri = entity_uri('comment', $comment);
$uri = $comment->uri();
$uri['options'] += array('attributes' => array('class' => 'permalink', 'rel' => 'bookmark'));
$variables['title'] = l($comment->subject, $uri['path'], $uri['options']);

View File

@ -6,7 +6,6 @@
*/
use \InvalidArgumentException;
use Drupal\entity\EntityFieldQuery;
use Drupal\entity\EntityMalformedException;
use Drupal\entity\EntityStorageException;
@ -371,48 +370,6 @@ function entity_prepare_view($entity_type, $entities) {
}
}
/**
* 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
* 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.
*
* @todo
* Remove once all entity types are implementing the EntityInterface.
*/
function entity_uri($entity_type, $entity) {
$info = entity_get_info($entity_type);
// A bundle-specific callback takes precedence over the generic one for the
// entity type.
if (isset($info['bundles'][$entity->bundle()]['uri callback'])) {
$uri_callback = $info['bundles'][$entity->bundle()]['uri callback'];
}
elseif (isset($info['uri callback'])) {
$uri_callback = $info['uri callback'];
}
else {
return NULL;
}
// Invoke the callback to get the URI. If there is no callback, return NULL.
if (isset($uri_callback)) {
$uri = $uri_callback($entity);
// Pass the entity data to url() so that alter functions do not need to
// lookup this entity again.
$uri['options']['entity_type'] = $entity_type;
$uri['options']['entity'] = $entity;
return $uri;
}
}
/**
* Returns the label of an entity.
*

View File

@ -117,8 +117,6 @@ class Entity implements EntityInterface {
/**
* Implements EntityInterface::uri().
*
* @see entity_uri()
*/
public function uri() {
$bundle = $this->bundle();

View File

@ -546,7 +546,7 @@ function image_field_formatter_view($entity_type, $entity, $field, $instance, $l
// Check if the formatter involves a link.
if ($display['settings']['image_link'] == 'content') {
$uri = entity_uri($entity_type, $entity);
$uri = $entity->uri();
}
elseif ($display['settings']['image_link'] == 'file') {
$link_file = TRUE;

View File

@ -1330,7 +1330,7 @@ function template_preprocess_node(&$variables) {
'link_attributes' => array('rel' => 'author'),
));
$uri = entity_uri('node', $node);
$uri = $node->uri();
$variables['node_url'] = url($uri['path'], $uri['options']);
$variables['title'] = check_plain($node->title);
$variables['page'] = $variables['view_mode'] == 'full' && node_is_page($node);
@ -1568,7 +1568,7 @@ function node_search_execute($keys = NULL, $conditions = NULL) {
$extra = module_invoke_all('node_search_result', $node, $item->langcode);
$language = language_load($item->langcode);
$uri = entity_uri('node', $node);
$uri = $node->uri();
$results[] = array(
'link' => url($uri['path'], array_merge($uri['options'], array('absolute' => TRUE, 'language' => $language))),
'type' => check_plain(node_type_get_name($node)),
@ -2561,7 +2561,7 @@ function node_page_view(Node $node) {
// of the active trail, and the link name becomes the page title.
// Thus, we must explicitly set the page title to be the node title.
drupal_set_title($node->label());
$uri = entity_uri('node', $node);
$uri = $node->uri();
// Set the node path as the canonical URL to prevent duplicate content.
drupal_add_html_head_link(array('rel' => 'canonical', 'href' => url($uri['path'], $uri['options'])), TRUE);
// Set the non-aliased path as a default shortlink.

View File

@ -598,7 +598,7 @@ function rdf_preprocess_field(&$variables) {
*/
function rdf_preprocess_user_profile(&$variables) {
$account = $variables['elements']['#account'];
$uri = entity_uri('user', $account);
$uri = $account->uri();
// Adds RDFa markup to the user profile page. Fields displayed in this page
// will automatically describe the user.
@ -695,7 +695,7 @@ function rdf_preprocess_comment(&$variables) {
// the URI of the resource described within the HTML element, while the
// typeof attribute indicates its RDF type (e.g., sioc:Post, foaf:Document,
// and so on.)
$uri = entity_uri('comment', $comment);
$uri = $comment->uri();
$variables['attributes']['about'] = url($uri['path'], $uri['options']);
$variables['attributes']['typeof'] = $comment->rdf_mapping['rdftype'];
}

View File

@ -236,7 +236,7 @@ function hook_search_execute($keys = NULL, $conditions = NULL) {
$extra = module_invoke_all('node_search_result', $node, $item->langcode);
$language = language_load($item->langcode);
$uri = entity_uri('node', $node);
$uri = $node->uri();
$results[] = array(
'link' => url($uri['path'], array_merge($uri['options'], array('absolute' => TRUE, 'language' => $language))),
'type' => check_plain(node_type_get_name($node)),

View File

@ -625,7 +625,7 @@ function template_preprocess_taxonomy_term(&$variables) {
$variables['term'] = $variables['elements']['#term'];
$term = $variables['term'];
$uri = entity_uri('taxonomy_term', $term);
$uri = $term->uri();
$variables['term_url'] = url($uri['path'], $uri['options']);
$variables['term_name'] = check_plain($term->name);
$variables['page'] = $variables['view_mode'] == 'full' && taxonomy_term_is_page($term);
@ -1230,7 +1230,7 @@ function taxonomy_field_formatter_view($entity_type, $entity, $field, $instance,
}
else {
$term = $item['taxonomy_term'];
$uri = entity_uri('taxonomy_term', $term);
$uri = $term->uri();
$element[$delta] = array(
'#type' => 'link',
'#title' => $term->label(),

View File

@ -110,7 +110,7 @@ function taxonomy_tokens($type, $tokens, array $data = array(), array $options =
break;
case 'url':
$uri = entity_uri('taxonomy_term', $term);
$uri = $term->uri();
$replacements[$original] = url($uri['path'], array_merge($uri['options'], array('absolute' => TRUE)));
break;

View File

@ -116,7 +116,7 @@ class RegisterFormController extends AccountFormController {
$account->password = $pass;
// New administrative account without notification.
$uri = entity_uri('user', $account);
$uri = $account->uri();
if ($admin && !$notify) {
drupal_set_message(t('Created a new user account for <a href="@url">%name</a>. No e-mail has been sent.', array('@url' => url($uri['path'], $uri['options']), '%name' => $account->name)));
}

View File

@ -52,7 +52,7 @@ class UserEntityCallbacksTest extends WebTestBase {
* Test URI callback.
*/
function testUriCallback() {
$uri = entity_uri('user', $this->account);
$uri = $this->account->uri();
$this->assertEqual('user/' . $this->account->uid, $uri['path'], t('Correct user URI.'));
}
}