Add an entity operation instead of a user list

Created on 14 October 2019, about 5 years ago
Updated 10 April 2024, 8 months ago

Instead of using a new route, the module should add a new operation to the user entity operations to switch user from the user list shown on /admin/people.

This in turn also fixes:

- #3086736: The user list doesn't have a pager →
- #3087718: Add a user filter on /admin/people/switch-user-list →

✨ Feature request
Status

Needs review

Version

1.0

Component

Code

Created by

🇦🇷Argentina hanoii 🇦🇷UTC-3

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇺🇸United States astringer

    The patch in #29, works for me on Drupal 9.5.3 using 8.x-1.9 of Userswitch.

  • This fixes the `LoggerChannelFactory` type in the `__construct()` function to be `LoggerChannelFactoryInterface`, so alternative logging methods can be used (such as the `Monolog Datadog` module).

  • Correcting an import mistake in previous patch.

  • 🇮🇹Italy apaderno Brescia, 🇮🇹
    +  /**
    +   * Drupal\userswitch\UserSwitch definition.
    +   *
    +   * @var \Drupal\userswitch\UserSwitch
    +   */
       protected $userSwitch;
    +
    +  /**
    +   * Drupal\Core\Session\AccountInterface definition.
    +   *
    +   * @var \Drupal\Core\Session\AccountInterface
    +   */
       protected $currentUser;
    +
    +  /**
    +   * Drupal\Core\Database\Connection definition.
    +   *
    +   * @var \Drupal\Core\Database\Connection
    +   */
       protected $database;
    +
    +  /**
    +   * Drupal\Core\Messenger\MessengerInterface definition.
    +   *
    +   * @var \Drupal\Core\Messenger\MessengerInterface
    +   */
       protected $messenger;

    Property descriptions must not repeat the property type, which is already given in the @var line.

    +      // Initialize an empty array.
    +      $output = [];
    

    That comment is not necessary, since $output = []; is quiet clear.

    +    catch (PluginException $e) {
    +      \Drupal::logger('userswitch')->error($e->getMessage());
    +      return [];

    Like other dependencies, also the logger must be injected using the dependency container.

    -  public function switchuser($uid) {
    -    if ($this->userswitch->switchToOther($uid)) {
    +  public function switchuser(User $user) {
    

    Since that line is changed, also the method name should be changed to switchUser().

    +   * @return \Symfony\Component\HttpFoundation\Response
    +   *   Returns redirect response.
    

    Return value descriptions must not start with Returns nor Return.

  • 🇫🇷France nicodh

    Hi,

    I rerolled the patch with @apaderno comments (services declarations, comments, method names).
    I added a retro compat test for switchToOther service method (accepts uid or User entity).
    I also unified route paths, and fix user toolbar link for switching back (with Gin theme - not tested in others - classes made the link hidden).
    As it is this module is unusable IMHO (without entity operation and without switch back link).

  • 🇮🇹Italy apaderno Brescia, 🇮🇹
    +  /**
    +   * @var \Drupal\userswitch\UserSwitch
    +   */
       protected $userSwitch;
    +
    +  /**
    +   * @var \Drupal\Core\Session\AccountInterface
    +   */
       protected $currentUser;

    The property descriptions are missing.

  • 🇫🇷France nicodh

    I thought the property names were self-describing, but I rerolled the patch

  • Status changed to Needs review about 1 year ago
  • 🇮🇹Italy apaderno Brescia, 🇮🇹
  • 🇮🇳India ash2303

    Fixed small entityquery accesscheck issue.
    Kept it to TRUE as per module functionality.

  • 🇺🇸United States tenten71

    #29 helped me with my issue. Thank you.

Production build 0.71.5 2024