diff --git a/core/modules/user/templates/user-admin-permissions.html.twig b/core/modules/user/templates/user-admin-permissions.html.twig new file mode 100644 index 0000000..0e19b14 --- /dev/null +++ b/core/modules/user/templates/user-admin-permissions.html.twig @@ -0,0 +1,21 @@ +{# +/** + * @file + * Default theme implementation for the administer permissions page. + * + * Available variables: + * - system_compact_link: A rendered link to show or hide inline help + * descriptions. + * - table: table of permissions + * - attributes: An array of html attributes to apply to the table tag. + * - form: Rendered form children elements. + * + * @see template_preprocess() + * @see template_preprocess_user_admin_permissions() + * + * @ingroup themeable + */ +#} +{{ system_compact_link }} +{{ table }} +{{ form }} diff --git a/core/modules/user/templates/user-admin-roles.html.twig b/core/modules/user/templates/user-admin-roles.html.twig new file mode 100644 index 0000000..90cf85a --- /dev/null +++ b/core/modules/user/templates/user-admin-roles.html.twig @@ -0,0 +1,18 @@ +{# +/** + * @file + * Default theme implementation for the role order and new role form. + * + * Available variables + * - table: table of roles + * - attributes: An array of html attributes to apply to the table tag. + * - form: Remaining form elements for user roles table. + * + * @see template_preprocess() + * @see template_preprocess_user_admin_roles() + * + * @ingroup themeable + */ +#} +{{ table }} +{{ form }} 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..9285fb6 --- /dev/null +++ b/core/modules/user/templates/user-permission-description.html.twig @@ -0,0 +1,26 @@ +{# +/** + * @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 %} + {% if description is defined %} + {{- description -}} + {% endif %} + {% if warning is defined %} + {{ warning }} + {% endif %} +{% endif %} diff --git a/core/modules/user/templates/user-picture.html.twig b/core/modules/user/templates/user-picture.html.twig new file mode 100644 index 0000000..1a70920 --- /dev/null +++ b/core/modules/user/templates/user-picture.html.twig @@ -0,0 +1,22 @@ +{# +/** + * @file + * Default theme implementation to display a picture for the user's account. + * + * Available variables: + * - user_picture: Image set by the user or the site's default. Will be linked + * depending on the viewer's permission to view the user's profile page. + * - account: Array of account information. Potentially unsafe. Be sure to + * check_plain() before use. + * + * @see template_preprocess() + * @see template_preprocess_user_picture() + * + * @ingroup themeable + */ +#} +{% if user_picture %} +
+ {{ user_picture }} +
+{% 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-profile.html.twig b/core/modules/user/templates/user-profile.html.twig new file mode 100644 index 0000000..a23d69d --- /dev/null +++ b/core/modules/user/templates/user-profile.html.twig @@ -0,0 +1,32 @@ +{# +/** + * @file + * Default theme implementation to present all user profile data. + * + * This template is used when viewing a registered member's profile page, + * e.g., example.com/user/123. 123 being the users ID. + * + * Use user_profile to print all profile items, or print a subset such as + * user_profile.user_picture. Always print user_profile at the end of the + * template in order to print all remaining items. + * + * If the item is a category, it will contain all its profile items. By + * default, user_profile.member_for is provided, which contains data on the + * user's history. user_profile.user_picture is available for showing the + * account picture. Other data can be included by modules. + * + * Available variables: + * - user_profile: Profile items. + * - Field variables: for each field attached to the user a corresponding + * variable is defined; e.g., account.field_example has a variable + * field_example defined. + * + * @see template_preprocess() + * @see template_preprocess_user_profile() + * + * @ingroup themeable + */ +#} + + {{ user_profile }} + diff --git a/core/modules/user/templates/user-signature.html.twig b/core/modules/user/templates/user-signature.html.twig new file mode 100644 index 0000000..024cd0a --- /dev/null +++ b/core/modules/user/templates/user-signature.html.twig @@ -0,0 +1,18 @@ +{# +/** + * @file + * Default theme implementation for a user signature. + * + * Available variables: + * - signature: The user's signature. + * - attributes: An array of HTML attributes for the wrapper of the signature. + * + * @TODO Use a general wrapper instead of this file. + * + * @see template_preprocess() + * @see template_preprocess_user_signature() + * + * @ingroup themeable + */ +#} +
{{ signature }}
diff --git a/core/modules/user/templates/user.html.twig b/core/modules/user/templates/user.html.twig new file mode 100644 index 0000000..c85b191 --- /dev/null +++ b/core/modules/user/templates/user.html.twig @@ -0,0 +1,32 @@ +{# +/** + * @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 users ID. + * + * Use render($content) to print all content, or print a subset + * such as render($content['field_example']). + * By default, $user_profile['summary'] is provided, which contains data on the + * user's history. Other data can be included by modules. + * + * Available variables: + * - $content: An array of content items. Use render() to print them. + * - 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 + */ +#} +
+ {{ content }} +
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..c76eaa7 --- /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 user object to format. + * - name: The user's name, sanitized. + * - extra: Additional text to append to the user's name, sanitized. + * - link: The fully generated link by l if a 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: 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 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 c3931d8..3804763 100644 --- a/core/modules/user/user.admin.inc +++ b/core/modules/user/user.admin.inc @@ -775,15 +775,15 @@ function user_admin_permissions_submit($form, &$form_state) { } /** - * Returns HTML for the administer permissions page. + * Preprocess variables for the administer permissions page. * - * @param $variables + * Default template: user-admin-permissions.html.twig. + * + * @param array $variables * An associative array containing: * - form: A render element representing the form. - * - * @ingroup themeable */ -function theme_user_admin_permissions($variables) { +function template_preprocess_user_admin_permissions(&$variables) { $form = $variables['form']; $roles = user_role_names(); @@ -811,16 +811,17 @@ function theme_user_admin_permissions($variables) { foreach (element_children($form['role_names']) as $rid) { $header[] = array('data' => drupal_render($form['role_names'][$rid]), 'class' => array('checkbox')); } - $output = theme('system_compact_link'); - $output .= theme('table', array('header' => $header, 'rows' => $rows, 'attributes' => array('id' => 'permissions'))); - $output .= drupal_render_children($form); - return $output; + $variables['system_compact_link'] = theme('system_compact_link'); + $variables['table'] = theme('table', array('header' => $header, 'rows' => $rows, 'attributes' => array('id' => 'permissions'))); + $variables['form'] = drupal_render_children($form); } /** - * Returns HTML for an individual permission description. + * Default theme implementation for an individual permission description. * - * @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: @@ -829,22 +830,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']; } } @@ -927,15 +920,15 @@ function user_admin_roles_order_submit($form, &$form_state) { } /** - * Returns HTML for the role order and new role form. + * Preprocess variables for user admin roles template. + * + * Default template: user-admin-roles.html.twig. * - * @param $variables + * @param array $variables * An associative array containing: * - form: A render element representing the form. - * - * @ingroup themeable */ -function theme_user_admin_roles($variables) { +function template_preprocess_user_admin_roles(&$variables) { $form = $variables['form']; $header = array(t('Name'), t('Weight'), t('Operations')); @@ -944,7 +937,10 @@ function theme_user_admin_roles($variables) { foreach (element_children($form['roles'][$rid]) as $column) { $row[] = drupal_render($form['roles'][$rid][$column]); } - $rows[] = array('data' => $row, 'class' => array('draggable')); + $rows[] = array( + 'data' => $row, + 'class' => array('draggable'), + ); } // Distribute the role add form into table columns. @@ -959,15 +955,16 @@ function theme_user_admin_roles($variables) { $row[] = drupal_render($form['role']); // Empty placeholder for the weight column. $row[] = ''; - $row[] = array('data' => drupal_render($actions), 'colspan' => 2); + $row[] = array( + 'data' => drupal_render($actions), + 'colspan' => 2, + ); $rows[] = array('data' => $row); drupal_add_tabledrag('user-roles', 'order', 'sibling', 'role-weight'); - $output = theme('table', array('header' => $header, 'rows' => $rows, 'attributes' => array('id' => 'user-roles'))); - $output .= drupal_render_children($form); - - return $output; + $variables['table'] = theme('table', array('header' => $header, 'rows' => $rows, 'attributes' => array('id' => 'user-roles'))); + $variables['form'] = drupal_render_children($form); } /** diff --git a/core/modules/user/user.module b/core/modules/user/user.module index bdf5862..15bf5ff 100644 --- a/core/modules/user/user.module +++ b/core/modules/user/user.module @@ -92,26 +92,31 @@ 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', 'file' => 'user.admin.inc', + 'template' => 'user-admin-permissions', ), 'user_admin_roles' => array( 'render element' => 'form', 'file' => 'user.admin.inc', + 'template' => 'user-admin-roles', ), 'user_permission_description' => array( 'variables' => array('permission_item' => NULL, 'hide' => NULL), 'file' => 'user.admin.inc', + 'template' => 'user-permission-description', ), 'user_signature' => array( 'variables' => array('signature' => NULL), + 'template' => 'user-signature', ), 'username' => array( 'variables' => array('account' => NULL), + 'template' => 'username', ), ); } @@ -728,13 +733,19 @@ function user_template_preprocess_default_variables_alter(&$variables) { } /** - * Preprocesses variables for theme_username(). + * Preprocesses variables for username. + * + * Default template: username.html.twig. + * + * @param array $variables + * An associative array containing: + * - account: @todo. + * - profile_access: @todo. + * - uid: @todo. * * Modules that make any changes to variables like 'name' or 'extra' must insure * that the final string is safe to include directly in the output by using * check_plain() or filter_xss(). - * - * @see template_process_username() */ function template_preprocess_username(&$variables) { $account = $variables['account']; @@ -779,7 +790,7 @@ function template_preprocess_username(&$variables) { // 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')); + $variables['attributes'] = new Attribute(array('class' => array('username'))); } /** @@ -802,45 +813,12 @@ function template_process_username(&$variables) { // 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']); + $attrs = (array) $variables['attributes']; + $variables['link_options']['attributes'] = new Attribute(array_merge_recursive($variables['link_attributes'], $attrs)); } } /** - * 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; -} - -/** * Determines if the current user is anonymous. * * @return bool @@ -1688,7 +1666,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 @@ -2294,26 +2272,16 @@ function user_build_filter_query(SelectInterface $query) { } /** - * Returns HTML for a user signature. + * Preprocess variables for user signature templates. * - * @param $variables + * Default template: user-signature.html.twig. + * + * @param array $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; +function template_preprocess_user_signature(&$variables) { + $variables['attributes'] = new Attribute(array('class' => array('clear'))); } /** diff --git a/core/modules/user/user.pages.inc b/core/modules/user/user.pages.inc index 140b767..2cf3f8c 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,13 @@ function user_logout() { } /** - * Process variables for user.tpl.php. + * Prepares variables for user template. * - * 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 */ function template_preprocess_user(&$variables) { $account = $variables['elements']['#user']; @@ -192,6 +194,10 @@ function template_preprocess_user(&$variables) { // Preprocess fields. field_attach_preprocess($account, $variables['elements'], $variables); + + // Set up attributes. + $variables['attributes'] = array('class' => array('profile')); + $variables['attributes'] = new Attribute($variables['attributes']); } /**