diff --git a/core/modules/rdf/rdf.module b/core/modules/rdf/rdf.module
index 547075a..0f402d4 100644
--- a/core/modules/rdf/rdf.module
+++ b/core/modules/rdf/rdf.module
@@ -675,29 +675,22 @@ function rdf_preprocess_username(&$variables) {
$variables['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'])) {
- $attributes['typeof'] = $rdf_mapping['rdftype'];
+ $variables['attributes']['typeof'] = $rdf_mapping['rdftype'];
}
// Annotate the username in RDFa. A property attribute is used with an empty
// datatype attribute to ensure the username is parsed as a plain literal
// in RDFa 1.0 and 1.1.
if (!empty($rdf_mapping['name'])) {
- $attributes['property'] = $rdf_mapping['name']['predicates'];
- $attributes['datatype'] = '';
+ $variables['attributes']['property'] = $rdf_mapping['name']['predicates'];
+ $variables['attributes']['datatype'] = '';
}
// Add the homepage RDFa markup if present.
if (!empty($variables['homepage']) && !empty($rdf_mapping['homepage'])) {
- $attributes['rel'] = $rdf_mapping['homepage']['predicates'];
- }
- // The remaining attributes can have multiple values listed, with whitespace
- // 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);
+ $variables['attributes']['rel'] = $rdf_mapping['homepage']['predicates'];
+ }
}
/**
diff --git a/core/modules/user/templates/user-permission-description.html.twig b/core/modules/user/templates/user-permission-description.html.twig
new file mode 100644
index 0000000..0aa6340
--- /dev/null
+++ b/core/modules/user/templates/user-permission-description.html.twig
@@ -0,0 +1,28 @@
+{#
+/**
+ * @file
+ * Default theme implementation for an individual permission description.
+ *
+ * Available variables:
+ * - description: The text of the permission description.
+ * - warning: A security-related warning message about the permission (if
+ * there is one).
+ * - hide: Indicates whether or not the permission description was requested
+ * to be hidden rather than shown.
+ *
+ * @see template_preprocess()
+ * @see template_preprocess_user_permission_description()
+ *
+ * @ingroup themeable
+ */
+#}
+{% if not hide %}
+{% spaceless %}
+ {% if description %}
+ {{- description -}}
+ {% endif %}
+ {% if warning -%}
+ {{ warning }}
+ {%- endif %}
+{% endspaceless %}
+{% endif %}
diff --git a/core/modules/user/templates/user-picture.tpl.php b/core/modules/user/templates/user-picture.tpl.php
deleted file mode 100644
index ee82187..0000000
--- a/core/modules/user/templates/user-picture.tpl.php
+++ /dev/null
@@ -1,23 +0,0 @@
-
-
-
-
-
-
diff --git a/core/modules/user/templates/user.html.twig b/core/modules/user/templates/user.html.twig
new file mode 100644
index 0000000..c89ecb4
--- /dev/null
+++ b/core/modules/user/templates/user.html.twig
@@ -0,0 +1,30 @@
+{#
+/**
+ * @file
+ * Default theme implementation to present all user data.
+ *
+ * This template is used when viewing a registered user's page,
+ * e.g., example.com/user/123. 123 being the user's ID.
+ *
+ * Available variables:
+ * - content: A list of content items. Use 'content' to print all content, or
+ * print a subset such as 'content.field_example'.
+ * - Field variables: For each field instance attached to the user a
+ * corresponding variable is defined; e.g., account.field_example has a
+ * variable 'field_example' defined. When needing to access a field's raw
+ * values, developers/themers are strongly encouraged to use these
+ * variables. Otherwise they will have to explicitly specify the desired
+ * field language, e.g. account.field_example.en, thus overriding any
+ * language negotiation rule that was previously applied.
+ *
+ * @see template_preprocess()
+ * @see template_preprocess_user()
+ *
+ * @ingroup themeable
+ */
+#}
+
+ {% if content is not empty %}
+ {{- content -}}
+ {% endif %}
+
diff --git a/core/modules/user/templates/user.tpl.php b/core/modules/user/templates/user.tpl.php
deleted file mode 100644
index 617d310..0000000
--- a/core/modules/user/templates/user.tpl.php
+++ /dev/null
@@ -1,32 +0,0 @@
-field_example has a
- * variable $field_example defined. When needing to access a field's raw
- * values, developers/themers are strongly encouraged to use these
- * variables. Otherwise they will have to explicitly specify the desired
- * field language, e.g. $account->field_example['en'], thus overriding any
- * language negotiation rule that was previously applied.
- *
- * @see template_preprocess_user()
- *
- * @ingroup themeable
- */
-?>
->
-
-
diff --git a/core/modules/user/templates/username.html.twig b/core/modules/user/templates/username.html.twig
new file mode 100644
index 0000000..35c64d3
--- /dev/null
+++ b/core/modules/user/templates/username.html.twig
@@ -0,0 +1,32 @@
+{#
+/**
+ * @file
+ * Default theme implementation for displaying a username.
+ *
+ * Available variables:
+ * - account: The full account information for the user.
+ * - name: The user's name, sanitized.
+ * - extra: Additional text to append to the user's name, sanitized.
+ * - link: The link fully generated by l() if link_path is set.
+ * - link_path: The path or URL of the user's profile page, home page,
+ * or other desired page to link to for more information about the user.
+ * - link_options: Options to pass to the l() function's $options parameter if
+ * linking the user's name to the user's page.
+ * - attributes: HTML attributes to be used if not linking to the user's page.
+ *
+ * @see template_preprocess()
+ * @see template_preprocess_username()
+ *
+ * @ingroup themeable
+ */
+#}
+{% if link %}
+ {{- link -}}
+{% else %}
+ {#
+ Modules may have added important attributes so they must be included
+ in the output. Additional classes may be added as array elements like
+ {% set attributes.class = attributes.class|merge(["myclass"]) %}
+ #}
+ {{ name }}{{ extra }}
+{% endif %}
diff --git a/core/modules/user/user.admin.inc b/core/modules/user/user.admin.inc
index 768bb96..46f8ad8 100644
--- a/core/modules/user/user.admin.inc
+++ b/core/modules/user/user.admin.inc
@@ -428,9 +428,11 @@ function theme_user_admin_permissions($variables) {
}
/**
- * Returns HTML for an individual permission description.
+ * Prepares variables for individual permission description templates.
*
- * @param $variables
+ * Default template: user-permission-description.html.twig.
+ *
+ * @param array $variables
* An associative array containing:
* - permission_item: An associative array representing the permission whose
* description is being themed. Useful keys include:
@@ -439,22 +441,14 @@ function theme_user_admin_permissions($variables) {
* there is one).
* - hide: A boolean indicating whether or not the permission description was
* requested to be hidden rather than shown.
- *
- * @ingroup themeable
*/
-function theme_user_permission_description($variables) {
- if (!$variables['hide']) {
- $description = array();
- $permission_item = $variables['permission_item'];
- if (!empty($permission_item['description'])) {
- $description[] = $permission_item['description'];
- }
- if (!empty($permission_item['warning'])) {
- $description[] = '' . $permission_item['warning'] . '';
- }
- if (!empty($description)) {
- return implode(' ', $description);
- }
+function template_preprocess_user_permission_description(&$variables) {
+ $permission_item = $variables['permission_item'];
+ if (!empty($permission_item['description'])) {
+ $variables['description'] = $permission_item['description'];
+ }
+ if (!empty($permission_item['warning'])) {
+ $variables['warning'] = $permission_item['warning'];
}
}
diff --git a/core/modules/user/user.module b/core/modules/user/user.module
index ead593b..7161f70 100644
--- a/core/modules/user/user.module
+++ b/core/modules/user/user.module
@@ -92,8 +92,8 @@ function user_theme() {
return array(
'user' => array(
'render element' => 'elements',
- 'template' => 'user',
'file' => 'user.pages.inc',
+ 'template' => 'user',
),
'user_admin_permissions' => array(
'render element' => 'form',
@@ -106,12 +106,11 @@ function user_theme() {
'user_permission_description' => array(
'variables' => array('permission_item' => NULL, 'hide' => NULL),
'file' => 'user.admin.inc',
- ),
- 'user_signature' => array(
- 'variables' => array('signature' => NULL),
+ 'template' => 'user-permission-description',
),
'username' => array(
'variables' => array('account' => NULL),
+ 'template' => 'username',
),
);
}
@@ -734,9 +733,17 @@ function user_template_preprocess_default_variables_alter(&$variables) {
}
/**
- * Preprocesses variables for theme_username().
+ * Prepares variables for username templates.
+ *
+ * Default template: username.html.twig.
*
- * Modules that make any changes to variables like 'name' or 'extra' must insure
+ * @param array $variables
+ * An associative array containing:
+ * - account: The user account to check access for
+ * (Drupal\user\Plugin\Core\Entity\User).
+ * - uid: The user uid number.
+ *
+ * Modules that make any changes to variables like 'name' or 'extra' must ensure
* that the final string is safe to include directly in the output by using
* check_plain() or filter_xss().
*
@@ -771,8 +778,8 @@ 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_path'] = 'user/' . $variables['uid'];
+ $variables['link_attributes'] = array('title' => t('View user profile.'));
}
elseif (!empty($account->homepage)) {
// Like the 'class' attribute, the 'rel' attribute can hold a
@@ -809,41 +816,10 @@ function template_process_username(&$variables) {
// \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'] = l($variables['name'] . $variables['extra'], $variables['link_path'], $variables['link_options']);
}
-}
-/**
- * Returns HTML for a username, potentially linked to the user's page.
- *
- * @param $variables
- * An associative array containing:
- * - account: The user object to format.
- * - name: The user's name, sanitized.
- * - extra: Additional text to append to the user's name, sanitized.
- * - link_path: The path or URL of the user's profile page, home page, or
- * other desired page to link to for more information about the user.
- * - link_options: An array of options to pass to the l() function's $options
- * parameter if linking the user's name to the user's page.
- * - attributes: An array of attributes to instantiate the
- * Drupal\Core\Template\Attribute class if not linking to the user's page.
- *
- * @see template_preprocess_username()
- * @see template_process_username()
- */
-function theme_username($variables) {
- if (isset($variables['link_path'])) {
- // We have a link path, so we should generate a link using l().
- // Additional classes may be added as array elements like
- // $variables['link_options']['attributes']['class'][] = 'myclass';
- $output = l($variables['name'] . $variables['extra'], $variables['link_path'], $variables['link_options']);
- }
- else {
- // Modules may have added important attributes so they must be included
- // in the output. Additional classes may be added as array elements like
- // $variables['attributes']['class'][] = 'myclass';
- $output = '' . $variables['name'] . $variables['extra'] . '';
- }
- return $output;
+ $variables['attributes'] = new Attribute($variables['attributes']);
}
/**
@@ -1691,7 +1667,7 @@ function user_view_page($account) {
* - $page['content']['#user']:
* The user account of the profile being viewed.
*
- * To theme user profiles, copy modules/user/user.tpl.php
+ * To theme user profiles, copy modules/user/templates/user.html.twig
* to your theme directory, and edit it as instructed in that file's comments.
*
* @param $account
@@ -2297,29 +2273,6 @@ function user_build_filter_query(SelectInterface $query) {
}
/**
- * Returns HTML for a user signature.
- *
- * @param $variables
- * An associative array containing:
- * - signature: The user's signature.
- *
- * @ingroup themeable
- */
-function theme_user_signature($variables) {
- $signature = $variables['signature'];
- $output = '';
-
- if ($signature) {
- $output .= '';
- $output .= '
—
';
- $output .= $signature;
- $output .= '
';
- }
-
- return $output;
-}
-
-/**
* Get the language object preferred by the user. This user preference can
* be set on the user account editing page, and is only available if there
* are more than one languages enabled on the site. If the user did not
diff --git a/core/modules/user/user.pages.inc b/core/modules/user/user.pages.inc
index 140b767..1d6856d 100644
--- a/core/modules/user/user.pages.inc
+++ b/core/modules/user/user.pages.inc
@@ -5,6 +5,7 @@
* User page callback file for the user module.
*/
+use Drupal\Core\Template\Attribute;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RedirectResponse;
@@ -175,12 +176,14 @@ function user_logout() {
}
/**
- * Process variables for user.tpl.php.
+ * Prepares variables for user templates.
*
- * The $variables array contains the following arguments:
- * - $account
+ * Default template: user.html.twig.
*
- * @see user.tpl.php
+ * @param array $variables
+ * An associative array containing:
+ * - account: The user account to check access for
+ * (Drupal\user\Plugin\Core\Entity\User).
*/
function template_preprocess_user(&$variables) {
$account = $variables['elements']['#user'];
@@ -192,6 +195,9 @@ function template_preprocess_user(&$variables) {
// Preprocess fields.
field_attach_preprocess($account, $variables['elements'], $variables);
+
+ // Set up attributes.
+ $variables['attributes'] = new Attribute(array('class' => array('profile')));
}
/**