CancelUser.php 1.95 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
<?php

/**
 * @file
 * Contains \Drupal\user\Plugin\Action\CancelUser.
 */

namespace Drupal\user\Plugin\Action;

use Drupal\Core\Action\ActionBase;
11
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
12 13 14 15 16 17 18 19 20 21
use Drupal\user\TempStoreFactory;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
 * Cancels a user account.
 *
 * @Action(
 *   id = "user_cancel_user_action",
 *   label = @Translation("Cancel the selected user accounts"),
 *   type = "user",
22
 *   confirm_form_route_name = "user.multiple_cancel_confirm"
23 24
 * )
 */
25
class CancelUser extends ActionBase implements ContainerFactoryPluginInterface {
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40

  /**
   * The tempstore factory.
   *
   * @var \Drupal\user\TempStoreFactory
   */
  protected $tempStoreFactory;

  /**
   * Constructs a DeleteNode object.
   *
   * @param array $configuration
   *   A configuration array containing information about the plugin instance.
   * @param string $plugin_id
   *   The plugin ID for the plugin instance.
41
   * @param mixed $plugin_definition
42 43 44 45
   *   The plugin implementation definition.
   * @param \Drupal\user\TempStoreFactory $temp_store_factory
   *   The tempstore factory.
   */
46
  public function __construct(array $configuration, $plugin_id, $plugin_definition, TempStoreFactory $temp_store_factory) {
47 48 49 50 51 52 53 54
    parent::__construct($configuration, $plugin_id, $plugin_definition);

    $this->tempStoreFactory = $temp_store_factory;
  }

  /**
   * {@inheritdoc}
   */
55
  public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
56 57 58 59 60 61 62
    return new static($configuration, $plugin_id, $plugin_definition, $container->get('user.tempstore'));
  }

  /**
   * {@inheritdoc}
   */
  public function executeMultiple(array $entities) {
63
    $this->tempStoreFactory->get('user_user_operations_cancel')->set(\Drupal::currentUser()->id(), $entities);
64 65 66 67 68 69 70 71 72 73
  }

  /**
   * {@inheritdoc}
   */
  public function execute($object = NULL) {
    $this->executeMultiple(array($object));
  }

}