There are a lot of unused classes and one broken 'use' statement in user.module.

Beta phase evaluation

-->

Reference: https://www.drupal.org/core/beta-changes
Issue category Task because it's a minor change that doesn't influence functionality.
Issue priority Normal because if we keep on accumulating unused code eventually it will affect the project size.
Prioritized changes The main goal of this issue is removing unused code./ This is not a prioritized change for the beta phase.

Comments

kim.pepper’s picture

Issue tags: +Novice
dashaforbes’s picture

I have removed the following unused use statements:

use Drupal\Core\Entity\EntityInterface;
use Drupal\file\Entity\File;
use Drupal\Core\Template\Attribute;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;

replaced:use Drupal\menu_link\Entity\MenuLink;
with: use Drupal\migrate_drupal\Plugin\migrate\source\d6\MenuLink;
Realised it wasn't used so I removed it too.

jibran’s picture

Status: Active » Needs review
larowlan’s picture

replaced:use Drupal\menu_link\Entity\MenuLink;
with: use Drupal\migrate_drupal\Plugin\migrate\source\d6\MenuLink;

Yeah we had a MenuLink entity once upon a time, but it became MenuLinkContent so maybe that's what you need

larowlan’s picture

Status: Needs review » Needs work
+++ b/core/modules/user/user.module
@@ -66,9 +60,13 @@ function user_help($route_name, RouteMatchInterface $route_match) {
-      $output .= '<dd>' . t('The <a href="!accounts">Account settings page</a> allows you to manage settings for the displayed name of the Anonymous user role, personal contact forms, user registration settings, and account cancellation settings. On this page you can also manage settings for account personalization (including signatures), and adapt the text for the email messages that users receive when they register or request a password recovery. You may also set which role is automatically assigned new permissions whenever a module is enabled (the Administrator role).', array('!accounts'  => \Drupal::url('entity.user.admin_form'))) . '</dd>';
+      $output .= '<dd>' . t('The <a href="!accounts">Account settings page</a> allows you to manage settings for the displayed name of the Anonymous user role, personal contact forms, user registration settings, and account cancellation settings. On this page you can also manage settings for account personalization (including signatures), and adapt the text for the email messages that users receive when they register or request a password recovery. You may also set which role is automatically assigned new permissions whenever a module is enabled (the Administrator role).', array('!accounts' => \Drupal::url('entity.user.admin_form'))) . '</dd>';
       $output .= '<dt>' . t('Managing user account fields') . '</dt>';
-      $output .= '<dd>' . t('Because User accounts are an <a href="!entity_help">entity type</a>, you can extend them by adding <a href="!field_help">fields</a> through the Manage fields tab on the <a href="!accounts">Account settings page</a>. By adding fields for e.g., a picture, a biography, or address, you can a create a custom profile for the users of the website.', array('!entity_help' => \Drupal::url('help.page', array('name' => 'entity')),'!field_help'=>\Drupal::url('help.page', array('name' => 'field')), '!accounts' => \Drupal::url('entity.user.admin_form'))) . '</dd>';
+      $output .= '<dd>' . t('Because User accounts are an <a href="!entity_help">entity type</a>, you can extend them by adding <a href="!field_help">fields</a> through the Manage fields tab on the <a href="!accounts">Account settings page</a>. By adding fields for e.g., a picture, a biography, or address, you can a create a custom profile for the users of the website.', array(
+          '!entity_help' => \Drupal::url('help.page', array('name' => 'entity')),
+          '!field_help' => \Drupal::url('help.page', array('name' => 'field')),
+          '!accounts' => \Drupal::url('entity.user.admin_form')
+        )) . '</dd>';

@@ -76,7 +74,10 @@ function user_help($route_name, RouteMatchInterface $route_match) {
-      return '<p>' . t('Permissions let you control what users can do and see on your site. You can define a specific set of permissions for each role. (See the <a href="!role">Roles</a> page to create a role.) Any permissions granted to the Authenticated user role will be given to any user who is logged in to your site. From the <a href="!settings">Account settings</a> page, you can make any role into an Administrator role for the site, meaning that role will be granted all new permissions automatically. You should be careful to ensure that only trusted users are given this access and level of control of your site.', array('!role' => \Drupal::url('user.role_list'), '!settings' => \Drupal::url('entity.user.admin_form'))) . '</p>';
+      return '<p>' . t('Permissions let you control what users can do and see on your site. You can define a specific set of permissions for each role. (See the <a href="!role">Roles</a> page to create a role.) Any permissions granted to the Authenticated user role will be given to any user who is logged in to your site. From the <a href="!settings">Account settings</a> page, you can make any role into an Administrator role for the site, meaning that role will be granted all new permissions automatically. You should be careful to ensure that only trusted users are given this access and level of control of your site.', array(
+        '!role' => \Drupal::url('user.role_list'),
+        '!settings' => \Drupal::url('entity.user.admin_form')
+      )) . '</p>';

@@ -102,7 +103,11 @@ function user_theme() {
-      'variables' => array('account' => NULL, 'attributes' => array(), 'link_options' => array()),
+      'variables' => array(
+        'account' => NULL,
+        'attributes' => array(),
+        'link_options' => array()

@@ -118,7 +123,8 @@ function user_js_settings_alter(&$settings) {
-  $settings['user']['permissionsHash'] = \Drupal::service('user.permissions_hash')->generate($user);
+  $settings['user']['permissionsHash'] = \Drupal::service('user.permissions_hash')
+    ->generate($user);

@@ -160,7 +166,8 @@ function user_attach_accounts(array &$build, array $entities) {
-  $field_definitions = \Drupal::entityManager()->getFieldDefinitions('user', 'user');
+  $field_definitions = \Drupal::entityManager()
+    ->getFieldDefinitions('user', 'user');

@@ -392,7 +399,8 @@ function user_role_permissions(array $roles) {
-    $role_permissions[$rid] = \Drupal::config("user.role.$rid")->get('permissions') ?: array();
+    $role_permissions[$rid] = \Drupal::config("user.role.$rid")
+      ->get('permissions') ?: array();

@@ -420,7 +428,8 @@ function user_user_view(array &$build, UserInterface $account, EntityViewDisplay
-      '#markup' => '<h4 class="label">' . t('Member for') . '</h4> ' . \Drupal::service('date.formatter')->formatInterval(REQUEST_TIME - $account->getCreatedTime()),
+      '#markup' => '<h4 class="label">' . t('Member for') . '</h4> ' . \Drupal::service('date.formatter')
+          ->formatInterval(REQUEST_TIME - $account->getCreatedTime()),

@@ -438,7 +447,8 @@ function user_validate_current_pass(&$form, FormStateInterface $form_state) {
-      $current_pass_failed = $form_state->isValueEmpty('current_pass') || !\Drupal::service('password')->check($form_state->getValue('current_pass'), $account);
+      $current_pass_failed = $form_state->isValueEmpty('current_pass') || !\Drupal::service('password')
+          ->check($form_state->getValue('current_pass'), $account);

@@ -542,7 +552,8 @@ function template_preprocess_username(&$variables) {
-  $variables['profile_access'] = \Drupal::currentUser()->hasPermission('access user profiles');
+  $variables['profile_access'] = \Drupal::currentUser()
+    ->hasPermission('access user profiles');

@@ -602,7 +613,8 @@ function user_menu_breadcrumb_alter(&$active_trail, $item) {
-  \Drupal::logger('user')->notice('Session opened for %name.', array('%name' => $account->getUsername()));
+  \Drupal::logger('user')
+    ->notice('Session opened for %name.', array('%name' => $account->getUsername()));

@@ -694,7 +706,10 @@ function user_pass_reset_url($account, $options = array()) {
-  $url_options = array('absolute' => TRUE, 'language' => \Drupal::languageManager()->getLanguage($langcode));
+  $url_options = array(
+    'absolute' => TRUE,
+    'language' => \Drupal::languageManager()->getLanguage($langcode)
+  );

@@ -749,7 +764,8 @@ function user_cancel($edit, $uid, $method) {
-    \Drupal::logger('user')->error('Attempted to cancel non-existing user account: %id.', array('%id' => $uid));
+    \Drupal::logger('user')
+      ->error('Attempted to cancel non-existing user account: %id.', array('%id' => $uid));

@@ -766,7 +782,11 @@ function user_cancel($edit, $uid, $method) {
-    \Drupal::moduleHandler()->invokeAll('user_cancel', array($edit, $account, $method));
+    \Drupal::moduleHandler()->invokeAll('user_cancel', array(
+      $edit,
+      $account,
+      $method
+    ));

@@ -813,7 +833,10 @@ function _user_cancel($edit, $account, $method) {
-      $logger->notice('Blocked user: %name %email.', array('%name' => $account->getUsername(), '%email' => '<' . $account->getEmail() . '>'));
+      $logger->notice('Blocked user: %name %email.', array(
+        '%name' => $account->getUsername(),
+        '%email' => '<' . $account->getEmail() . '>'
+      ));

@@ -824,7 +847,10 @@ function _user_cancel($edit, $account, $method) {
-      $logger->notice('Deleted user: %name %email.', array('%name' => $account->getUsername(), '%email' => '<' . $account->getEmail() . '>'));
+      $logger->notice('Deleted user: %name %email.', array(
+        '%name' => $account->getUsername(),
+        '%email' => '<' . $account->getEmail() . '>'
+      ));

@@ -982,14 +1008,20 @@ function user_mail($key, &$message, $params) {
-  $language = \Drupal::languageManager()->getLanguage($params['account']->getPreferredLangcode());
+  $language = \Drupal::languageManager()
+    ->getLanguage($params['account']->getPreferredLangcode());
...
-   // We do not sanitize the token replacement, since the output of this
-   // replacement is intended for an email message, not a web browser.
-  $token_options = array('langcode' => $langcode, 'callback' => 'user_mail_tokens', 'sanitize' => FALSE, 'clear' => TRUE);
+  // We do not sanitize the token replacement, since the output of this
+  // replacement is intended for an email message, not a web browser.
+  $token_options = array(
+    'langcode' => $langcode,
+    'callback' => 'user_mail_tokens',
+    'sanitize' => FALSE,
+    'clear' => TRUE
+  );

@@ -1049,7 +1081,11 @@ function user_role_names($membersonly = FALSE, $permission = NULL) {
-  if (in_array($role->id(), array(DRUPAL_AUTHENTICATED_RID, DRUPAL_ANONYMOUS_RID)) || $role->isSyncing()) {
+  if (in_array($role->id(), array(
+      DRUPAL_AUTHENTICATED_RID,
+      DRUPAL_ANONYMOUS_RID
+    )) || $role->isSyncing()
+  ) {

@@ -1086,7 +1122,11 @@ function user_user_role_insert(RoleInterface $role) {
-  if (in_array($role->id(), array(DRUPAL_AUTHENTICATED_RID, DRUPAL_ANONYMOUS_RID)) || $role->isSyncing()) {
+  if (in_array($role->id(), array(
+      DRUPAL_AUTHENTICATED_RID,
+      DRUPAL_ANONYMOUS_RID
+    )) || $role->isSyncing()
+  ) {

@@ -1174,7 +1214,7 @@ function user_role_load($rid) {
- *   @code
+ * @code
  *     array(

@@ -1182,7 +1222,7 @@ function user_role_load($rid) {
- *   @endcode
+ * @endcode

@@ -1289,11 +1329,15 @@ function _user_mail_notify($op, $account, $langcode = NULL) {
-    $mail = \Drupal::service('plugin.manager.mail')->mail('user', $op, $account->getEmail(), $langcode, $params, $site_mail);
+    $mail = \Drupal::service('plugin.manager.mail')
+      ->mail('user', $op, $account->getEmail(), $langcode, $params, $site_mail);
...
-      \Drupal::service('plugin.manager.mail')->mail('user', 'register_pending_approval_admin', $site_mail, \Drupal::languageManager()->getDefaultLanguage()->getId(), $params);
+      \Drupal::service('plugin.manager.mail')
+        ->mail('user', 'register_pending_approval_admin', $site_mail, \Drupal::languageManager()
+          ->getDefaultLanguage()
+          ->getId(), $params);

@@ -1434,7 +1478,7 @@ function user_toolbar() {
-     $links = array(
+    $links = array(

@@ -1480,7 +1524,8 @@ function user_toolbar() {
-  \Drupal::logger('user')->notice('Session closed for %name.', array('%name' => $user->getUsername()));
+  \Drupal::logger('user')
+    ->notice('Session closed for %name.', array('%name' => $user->getUsername()));

Looks like unrelated changes - IDE auto-formatting perhaps?

You can use git fetch origin && git checkout -p origin/8.0.x to selectively discard the bits you didn't mean to change (hit y for the ones you didn't mean, n for the ones you did)

dashaforbes’s picture

changed to: use Drupal\menu_link_content\Entity\MenuLinkContent; still unused
Removed IDE auto-formatting.

larowlan’s picture

Status: Needs work » Reviewed & tested by the community

unless bot disagrees

larowlan’s picture

Issue tags: +Quick fix
alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Thanks this has bugged me for a while. Committed b0faab2 and pushed to 8.0.x. Thanks!

  • alexpott committed b0faab2 on 8.0.x
    Issue #2407493 by dashaforbes, kim.pepper: Clean up use statements in...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.