Issue #1618172 by jcisio, corvus_ch, estebanvalerio.h, Berdir: Remove entity_uri() in favor of EntityInterface::uri().
parent
3b308be763
commit
ff895df7ac
|
@ -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
|
* Defaults to empty string when clean URLs are in effect, and to
|
||||||
* 'index.php/' when they are not.
|
* 'index.php/' when they are not.
|
||||||
* - 'entity_type': The entity type of the object that called url(). Only
|
* - '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
|
* - '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
|
* @return
|
||||||
* A string containing a URL to the given path.
|
* A string containing a URL to the given path.
|
||||||
|
|
|
@ -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['user_picture'] = theme_get_setting('toggle_comment_user_picture') ? theme('user_picture', array('account' => $comment)) : '';
|
||||||
$variables['signature'] = $comment->signature;
|
$variables['signature'] = $comment->signature;
|
||||||
|
|
||||||
$uri = entity_uri('comment', $comment);
|
$uri = $comment->uri();
|
||||||
$uri['options'] += array('attributes' => array('class' => 'permalink', 'rel' => 'bookmark'));
|
$uri['options'] += array('attributes' => array('class' => 'permalink', 'rel' => 'bookmark'));
|
||||||
|
|
||||||
$variables['title'] = l($comment->subject, $uri['path'], $uri['options']);
|
$variables['title'] = l($comment->subject, $uri['path'], $uri['options']);
|
||||||
|
|
|
@ -6,7 +6,6 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use \InvalidArgumentException;
|
use \InvalidArgumentException;
|
||||||
|
|
||||||
use Drupal\entity\EntityFieldQuery;
|
use Drupal\entity\EntityFieldQuery;
|
||||||
use Drupal\entity\EntityMalformedException;
|
use Drupal\entity\EntityMalformedException;
|
||||||
use Drupal\entity\EntityStorageException;
|
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.
|
* Returns the label of an entity.
|
||||||
*
|
*
|
||||||
|
|
|
@ -117,8 +117,6 @@ class Entity implements EntityInterface {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implements EntityInterface::uri().
|
* Implements EntityInterface::uri().
|
||||||
*
|
|
||||||
* @see entity_uri()
|
|
||||||
*/
|
*/
|
||||||
public function uri() {
|
public function uri() {
|
||||||
$bundle = $this->bundle();
|
$bundle = $this->bundle();
|
||||||
|
|
|
@ -546,7 +546,7 @@ function image_field_formatter_view($entity_type, $entity, $field, $instance, $l
|
||||||
|
|
||||||
// Check if the formatter involves a link.
|
// Check if the formatter involves a link.
|
||||||
if ($display['settings']['image_link'] == 'content') {
|
if ($display['settings']['image_link'] == 'content') {
|
||||||
$uri = entity_uri($entity_type, $entity);
|
$uri = $entity->uri();
|
||||||
}
|
}
|
||||||
elseif ($display['settings']['image_link'] == 'file') {
|
elseif ($display['settings']['image_link'] == 'file') {
|
||||||
$link_file = TRUE;
|
$link_file = TRUE;
|
||||||
|
|
|
@ -1330,7 +1330,7 @@ function template_preprocess_node(&$variables) {
|
||||||
'link_attributes' => array('rel' => 'author'),
|
'link_attributes' => array('rel' => 'author'),
|
||||||
));
|
));
|
||||||
|
|
||||||
$uri = entity_uri('node', $node);
|
$uri = $node->uri();
|
||||||
$variables['node_url'] = url($uri['path'], $uri['options']);
|
$variables['node_url'] = url($uri['path'], $uri['options']);
|
||||||
$variables['title'] = check_plain($node->title);
|
$variables['title'] = check_plain($node->title);
|
||||||
$variables['page'] = $variables['view_mode'] == 'full' && node_is_page($node);
|
$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);
|
$extra = module_invoke_all('node_search_result', $node, $item->langcode);
|
||||||
|
|
||||||
$language = language_load($item->langcode);
|
$language = language_load($item->langcode);
|
||||||
$uri = entity_uri('node', $node);
|
$uri = $node->uri();
|
||||||
$results[] = array(
|
$results[] = array(
|
||||||
'link' => url($uri['path'], array_merge($uri['options'], array('absolute' => TRUE, 'language' => $language))),
|
'link' => url($uri['path'], array_merge($uri['options'], array('absolute' => TRUE, 'language' => $language))),
|
||||||
'type' => check_plain(node_type_get_name($node)),
|
'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.
|
// 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.
|
// Thus, we must explicitly set the page title to be the node title.
|
||||||
drupal_set_title($node->label());
|
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.
|
// 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);
|
drupal_add_html_head_link(array('rel' => 'canonical', 'href' => url($uri['path'], $uri['options'])), TRUE);
|
||||||
// Set the non-aliased path as a default shortlink.
|
// Set the non-aliased path as a default shortlink.
|
||||||
|
|
|
@ -598,7 +598,7 @@ function rdf_preprocess_field(&$variables) {
|
||||||
*/
|
*/
|
||||||
function rdf_preprocess_user_profile(&$variables) {
|
function rdf_preprocess_user_profile(&$variables) {
|
||||||
$account = $variables['elements']['#account'];
|
$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
|
// Adds RDFa markup to the user profile page. Fields displayed in this page
|
||||||
// will automatically describe the user.
|
// 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
|
// the URI of the resource described within the HTML element, while the
|
||||||
// typeof attribute indicates its RDF type (e.g., sioc:Post, foaf:Document,
|
// typeof attribute indicates its RDF type (e.g., sioc:Post, foaf:Document,
|
||||||
// and so on.)
|
// and so on.)
|
||||||
$uri = entity_uri('comment', $comment);
|
$uri = $comment->uri();
|
||||||
$variables['attributes']['about'] = url($uri['path'], $uri['options']);
|
$variables['attributes']['about'] = url($uri['path'], $uri['options']);
|
||||||
$variables['attributes']['typeof'] = $comment->rdf_mapping['rdftype'];
|
$variables['attributes']['typeof'] = $comment->rdf_mapping['rdftype'];
|
||||||
}
|
}
|
||||||
|
|
|
@ -236,7 +236,7 @@ function hook_search_execute($keys = NULL, $conditions = NULL) {
|
||||||
$extra = module_invoke_all('node_search_result', $node, $item->langcode);
|
$extra = module_invoke_all('node_search_result', $node, $item->langcode);
|
||||||
|
|
||||||
$language = language_load($item->langcode);
|
$language = language_load($item->langcode);
|
||||||
$uri = entity_uri('node', $node);
|
$uri = $node->uri();
|
||||||
$results[] = array(
|
$results[] = array(
|
||||||
'link' => url($uri['path'], array_merge($uri['options'], array('absolute' => TRUE, 'language' => $language))),
|
'link' => url($uri['path'], array_merge($uri['options'], array('absolute' => TRUE, 'language' => $language))),
|
||||||
'type' => check_plain(node_type_get_name($node)),
|
'type' => check_plain(node_type_get_name($node)),
|
||||||
|
|
|
@ -625,7 +625,7 @@ function template_preprocess_taxonomy_term(&$variables) {
|
||||||
$variables['term'] = $variables['elements']['#term'];
|
$variables['term'] = $variables['elements']['#term'];
|
||||||
$term = $variables['term'];
|
$term = $variables['term'];
|
||||||
|
|
||||||
$uri = entity_uri('taxonomy_term', $term);
|
$uri = $term->uri();
|
||||||
$variables['term_url'] = url($uri['path'], $uri['options']);
|
$variables['term_url'] = url($uri['path'], $uri['options']);
|
||||||
$variables['term_name'] = check_plain($term->name);
|
$variables['term_name'] = check_plain($term->name);
|
||||||
$variables['page'] = $variables['view_mode'] == 'full' && taxonomy_term_is_page($term);
|
$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 {
|
else {
|
||||||
$term = $item['taxonomy_term'];
|
$term = $item['taxonomy_term'];
|
||||||
$uri = entity_uri('taxonomy_term', $term);
|
$uri = $term->uri();
|
||||||
$element[$delta] = array(
|
$element[$delta] = array(
|
||||||
'#type' => 'link',
|
'#type' => 'link',
|
||||||
'#title' => $term->label(),
|
'#title' => $term->label(),
|
||||||
|
|
|
@ -110,7 +110,7 @@ function taxonomy_tokens($type, $tokens, array $data = array(), array $options =
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'url':
|
case 'url':
|
||||||
$uri = entity_uri('taxonomy_term', $term);
|
$uri = $term->uri();
|
||||||
$replacements[$original] = url($uri['path'], array_merge($uri['options'], array('absolute' => TRUE)));
|
$replacements[$original] = url($uri['path'], array_merge($uri['options'], array('absolute' => TRUE)));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
|
@ -116,7 +116,7 @@ class RegisterFormController extends AccountFormController {
|
||||||
$account->password = $pass;
|
$account->password = $pass;
|
||||||
|
|
||||||
// New administrative account without notification.
|
// New administrative account without notification.
|
||||||
$uri = entity_uri('user', $account);
|
$uri = $account->uri();
|
||||||
if ($admin && !$notify) {
|
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)));
|
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)));
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,7 +52,7 @@ class UserEntityCallbacksTest extends WebTestBase {
|
||||||
* Test URI callback.
|
* Test URI callback.
|
||||||
*/
|
*/
|
||||||
function testUriCallback() {
|
function testUriCallback() {
|
||||||
$uri = entity_uri('user', $this->account);
|
$uri = $this->account->uri();
|
||||||
$this->assertEqual('user/' . $this->account->uid, $uri['path'], t('Correct user URI.'));
|
$this->assertEqual('user/' . $this->account->uid, $uri['path'], t('Correct user URI.'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue