Commit fa9c197e authored by alexpott's avatar alexpott

Issue #1843788 by scor, jenlampton, tyjamessmith: Remove template_process_username().

parent 573068f9
......@@ -1085,7 +1085,7 @@ function template_preprocess_node(&$variables) {
$username = array(
'#theme' => 'username',
'#account' => $node,
'#link_attributes' => array('rel' => 'author'),
'#link_options' => array('attributes' => array('rel' => 'author')),
);
$variables['name'] = drupal_render($username);
......
......@@ -647,13 +647,14 @@ function rdf_preprocess_user(&$variables) {
* Implements hook_preprocess_HOOK() for theme_username().
*/
function rdf_preprocess_username(&$variables) {
$attributes = array();
// Because lang is set on the HTML element that wraps the page, the
// username inherits this language attribute. However, since the username
// might not be transliterated to the same language that the content is in,
// we do not want it to inherit the language attribute, so we set the
// attribute to an empty string.
if (empty($variables['attributes']['lang'])) {
$variables['attributes']['lang'] = '';
$attributes['lang'] = '';
}
// $variables['account'] is a pseudo account object, and as such, does not
......@@ -672,10 +673,9 @@ function rdf_preprocess_username(&$variables) {
// a user profile URI for it (only a homepage which cannot be used as user
// profile in RDF.)
if ($variables['uid'] > 0) {
$variables['attributes']['about'] = url('user/' . $variables['uid']);
$attributes['about'] = url('user/' . $variables['uid']);
}
$attributes = array();
// The typeof attribute specifies the RDF type(s) of this resource. They
// are defined in the 'rdftype' property of the user RDF mapping.
if (!empty($rdf_mapping['rdftype'])) {
......@@ -696,8 +696,14 @@ function rdf_preprocess_username(&$variables) {
// separating the values in the RDFa attributes
// (see http://www.w3.org/TR/rdfa-syntax/#rdfa-attributes).
// Therefore, merge rather than override so as not to clobber values set by
// earlier preprocess functions.
$variables['attributes'] = NestedArray::mergeDeep($variables['attributes'], $attributes);
// earlier preprocess functions. These attributes will be placed in the a
// element if a link is rendered, or on a span element otherwise.
if (isset($variables['link_path'])) {
$variables['link_options']['attributes'] = array_merge_recursive($variables['link_options']['attributes'], $attributes);
}
else {
$variables['attributes'] = array_merge_recursive($variables['attributes'], $attributes);
}
}
/**
......
......@@ -739,6 +739,7 @@ function template_preprocess_username(&$variables) {
}
$variables['extra'] = '';
$variables['attributes'] = array();
if (empty($account->uid)) {
$variables['uid'] = 0;
if (theme_get_setting('features.comment_user_verification')) {
......@@ -764,45 +765,21 @@ function template_preprocess_username(&$variables) {
// Populate link path and attributes if appropriate.
if ($variables['uid'] && $variables['profile_access']) {
// We are linking to a local user.
$variables['link_attributes']['title'] = t('View user profile.');
$variables['link_options']['attributes']['title'] = t('View user profile.');
$variables['link_path'] = 'user/' . $variables['uid'];
}
elseif (!empty($account->homepage)) {
// Like the 'class' attribute, the 'rel' attribute can hold a
// space-separated set of values, so initialize it as an array to make it
// easier for other preprocess functions to append to it.
$variables['link_attributes']['rel'] = 'nofollow';
$variables['link_options']['attributes']['rel'] = 'nofollow';
$variables['link_path'] = $account->homepage;
$variables['homepage'] = $account->homepage;
}
// We do not want the l() function to check_plain() a second time.
$variables['link_options']['html'] = TRUE;
// Set a default class.
$variables['attributes'] = array('class' => array('username'));
}
/**
* Processes variables for theme_username().
*
* @see template_preprocess_username()
*/
function template_process_username(&$variables) {
// Finalize the link_options array for passing to the l() function.
// This is done in the process phase so that attributes may be added by
// modules or the theme during the preprocess phase.
if (isset($variables['link_path'])) {
// $variables['attributes'] contains attributes that should be applied
// regardless of whether a link is being rendered or not.
// $variables['link_attributes'] contains attributes that should only be
// applied if a link is being rendered. Preprocess functions are encouraged
// to use the former unless they want to add attributes on the link only.
// If a link is being rendered, these need to be merged. Some attributes are
// themselves arrays, so the merging needs to be recursive.
// This purposefully does not use
// \Drupal\Component\Utility\NestedArray::mergeDeep() for performance
// reasons, since it is potentially called very often.
$variables['link_options']['attributes'] = array_merge_recursive($variables['link_attributes'], $variables['attributes']);
}
$variables['link_options']['attributes']['class'] = array('username');
}
/**
......
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