diff --git a/core/modules/rdf/rdf.module b/core/modules/rdf/rdf.module index 08cd24c..ded7bbf 100644 --- a/core/modules/rdf/rdf.module +++ b/core/modules/rdf/rdf.module @@ -388,14 +388,13 @@ 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'])) { - $attributes['lang'] = ''; + $variables['attributes']['lang'] = ''; } // The profile URI is used to identify the user account. The about attribute @@ -406,39 +405,27 @@ 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) { - $attributes['about'] = url('user/' . $variables['uid']); + $variables['attributes']['about'] = url('user/' . $variables['uid']); } // Add RDF type of user. $mapping = rdf_get_mapping('user', 'user'); $bundle_mapping = $mapping->getPreparedBundleMapping(); if (!empty($bundle_mapping['types'])) { - $attributes['typeof'] = $bundle_mapping['types']; + $variables['attributes']['typeof'] = $bundle_mapping['types']; } // 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. $name_mapping = $mapping->getPreparedFieldMapping('name'); if (!empty($name_mapping)) { - $attributes['property'] = $name_mapping['properties']; - $attributes['datatype'] = ''; + $variables['attributes']['property'] = $name_mapping['properties']; + $variables['attributes']['datatype'] = ''; } // Add the homepage RDFa markup if present. $homepage_mapping = $mapping->getPreparedFieldMapping('homepage'); if (!empty($variables['homepage']) && !empty($homepage_mapping)) { - $attributes['rel'] = $homepage_mapping['properties']; - } - // 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. 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); + $variables['attributes']['rel'] = $homepage_mapping['properties']; } } diff --git a/core/modules/system/system.api.php b/core/modules/system/system.api.php index 0d9b5be..7197a22 100644 --- a/core/modules/system/system.api.php +++ b/core/modules/system/system.api.php @@ -1176,19 +1176,9 @@ function hook_system_info_alter(&$info, $file, $type) { * have inherent security risks across a variety of potential use cases * (for example, the "administer filters" and "bypass node access" * permissions provided by Drupal core). When set to TRUE, a standard - * warning message defined in user_admin_permissions() and output via - * theme_user_permission_description() will be associated with the - * permission and displayed with it on the permission administration page. - * Defaults to FALSE. - * - warning: (optional) A translated warning message to display for this - * permission on the permission administration page. This warning overrides - * the automatic warning generated by 'restrict access' being set to TRUE. - * This should rarely be used, since it is important for all permissions to - * have a clear, consistent security warning that is the same across the - * site. Use the 'description' key instead to provide any information that - * is specific to the permission you are defining. - * - * @see theme_user_permission_description() + * warning message defined in user_admin_permissions() will be displayed + * with the permission on the permission administration page. Defaults + * to FALSE. */ function hook_permission() { return array( diff --git a/core/modules/user/lib/Drupal/user/Form/UserPermissionsForm.php b/core/modules/user/lib/Drupal/user/Form/UserPermissionsForm.php index a0b29ee..1bbeec6 100644 --- a/core/modules/user/lib/Drupal/user/Form/UserPermissionsForm.php +++ b/core/modules/user/lib/Drupal/user/Form/UserPermissionsForm.php @@ -140,18 +140,21 @@ public function buildForm(array $form, array &$form_state) { 'warning' => !empty($perm_item['restrict access']) ? $this->t('Warning: Give to trusted roles only; this permission has security implications.') : '', ); $options[$perm] = $perm_item['title']; - $user_permission_description = array( - '#theme' => 'user_permission_description', - '#permission_item' => $perm_item, - '#hide' => $hide_descriptions, - ); + // Show the permission description. + if (!$hide_descriptions) { + $user_permission_description = $perm_item['description']; + // Append warning message. + if (!empty($perm_item['warning'])) { + $user_permission_description .= ' ' . $perm_item['warning'] . ''; + } + } $form['permissions'][$perm]['description'] = array( '#wrapper_attributes' => array( 'class' => array('permission'), ), '#type' => 'item', '#markup' => $perm_item['title'], - '#description' => drupal_render($user_permission_description), + '#description' => $user_permission_description, ); $options[$perm] = ''; foreach ($role_names as $rid => $name) { diff --git a/core/modules/user/templates/username.html.twig b/core/modules/user/templates/username.html.twig new file mode 100644 index 0000000..a41def7 --- /dev/null +++ b/core/modules/user/templates/username.html.twig @@ -0,0 +1,31 @@ +{# +/** + * @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_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 9a6ca2a..56a2b94 100644 --- a/core/modules/user/user.admin.inc +++ b/core/modules/user/user.admin.inc @@ -6,32 +6,86 @@ */ /** - * Returns HTML for an individual permission description. - * - * @param $variables - * An associative array containing: - * - permission_item: An associative array representing the permission whose - * description is being themed. Useful keys include: - * - description: The text of the permission description. - * - warning: A security-related warning message about the permission (if - * there is one). - * - hide: A boolean indicating whether or not the permission description was - * requested to be hidden rather than shown. - * - * @ingroup themeable + * Page callback: User administration page. */ -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 user_admin_account() { + $header = array( + 'username' => array('data' => t('Username'), 'field' => 'u.name'), + 'status' => array('data' => t('Status'), 'field' => 'u.status', 'class' => array(RESPONSIVE_PRIORITY_LOW)), + 'roles' => array('data' => t('Roles'), 'class' => array(RESPONSIVE_PRIORITY_LOW)), + 'member_for' => array('data' => t('Member for'), 'field' => 'u.created', 'sort' => 'desc', 'class' => array(RESPONSIVE_PRIORITY_LOW)), + 'access' => array('data' => t('Last access'), 'field' => 'u.access', 'class' => array(RESPONSIVE_PRIORITY_LOW)), + 'operations' => t('Operations'), + ); + + $query = db_select('users', 'u'); + $query->condition('u.uid', 0, '<>'); + + $count_query = clone $query; + $count_query->addExpression('COUNT(u.uid)'); + + $query = $query + ->extend('Drupal\Core\Database\Query\PagerSelectExtender') + ->extend('Drupal\Core\Database\Query\TableSortExtender'); + $query + ->fields('u', array('uid')) + ->limit(50) + ->orderByHeader($header) + ->setCountQuery($count_query); + $uids = $query->execute() + ->fetchCol('uid'); + + $destination = drupal_get_destination(); + $accounts = user_load_multiple($uids); + + foreach ($accounts as $account) { + $users_roles = $account->getRoles(); + unset($users_roles[0]); + asort($users_roles); + $username = array( + '#theme' => 'username', + '#account' => $account, + ); + $item_list = array( + '#theme' => 'item_list', + '#items' => $users_roles, + ); + $options[$account->id()] = array( + 'username' => drupal_render($username), + 'status' => $account->isActive() ? t('active') : t('blocked'), + 'roles' => drupal_render($item_list), + 'member_for' => format_interval(REQUEST_TIME - $account->getCreatedTime()), + 'access' => $account->getLastAccessedTime() ? t('@time ago', array('@time' => format_interval(REQUEST_TIME - $account->getLastAccessedTime()))) : t('never'), + ); + $links = array(); + $links['edit'] = array( + 'title' => t('Edit'), + 'href' => 'user/' . $account->id() . '/edit', + 'query' => $destination, + ); + if (module_invoke('content_translation', 'translate_access', $account)) { + $links['translate'] = array( + 'title' => t('Translate'), + 'href' => 'user/' . $account->id() . '/translations', + 'query' => $destination, + ); } + $options[$account->id()]['operations']['data'] = array( + '#type' => 'operations', + '#links' => $links, + ); + } + + $form['accounts'] = array( + '#theme' => 'table', + '#header' => $header, + '#rows' => $options, + '#empty' => t('No people available.'), + ); + $form['pager'] = array( + '#theme' =>'pager', + ); + + return $form; } diff --git a/core/modules/user/user.module b/core/modules/user/user.module index 41dbae9..7932b85 100644 --- a/core/modules/user/user.module +++ b/core/modules/user/user.module @@ -97,15 +97,9 @@ function user_theme() { 'file' => 'user.pages.inc', 'template' => 'user', ), - 'user_permission_description' => array( - 'variables' => array('permission_item' => NULL, 'hide' => NULL), - 'file' => 'user.admin.inc', - ), - 'user_signature' => array( - 'variables' => array('signature' => NULL), - ), 'username' => array( 'variables' => array('account' => NULL, 'attributes' => array()), + 'template' => 'username', ), ); } @@ -610,7 +604,15 @@ function user_template_preprocess_default_variables_alter(&$variables) { } /** - * Preprocesses variables for theme_username(). + * Prepares variables for username templates. + * + * Default template: username.html.twig. + * + * @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 @@ -657,39 +659,13 @@ function template_preprocess_username(&$variables) { $variables['link_options']['html'] = TRUE; // Set a default class. $variables['link_options']['attributes']['class'] = array('username'); -} -/** - * 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() - */ -function theme_username($variables) { + // 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'; 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'] . ''; + $variables['link'] = l($variables['name'] . $variables['extra'], $variables['link_path'], $variables['link_options']); } - return $output; } /** @@ -1679,29 +1655,6 @@ function user_role_revoke_permissions($rid, array $permissions = array()) { } /** - * 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; -} - -/** * Conditionally create and send a notification email when a certain * operation happens on the given user account. *