diff --git a/core/modules/user/lib/Drupal/user/Form/UserCancelForm.php b/core/modules/user/lib/Drupal/user/Form/UserCancelForm.php index 531aecc..9884011 100644 --- a/core/modules/user/lib/Drupal/user/Form/UserCancelForm.php +++ b/core/modules/user/lib/Drupal/user/Form/UserCancelForm.php @@ -7,13 +7,17 @@ namespace Drupal\user\Form; +use Drupal\Core\Config\ConfigFactory; +use Drupal\Core\Entity\EntityControllerInterface; use Drupal\Core\Entity\EntityNGConfirmFormBase; +use Drupal\Core\Extension\ModuleHandlerInterface; +use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpFoundation\Request; /** * Provides a confirmation form for cancelling user account. */ -class UserCancelForm extends EntityNGConfirmFormBase { +class UserCancelForm extends EntityNGConfirmFormBase implements EntityControllerInterface { /** * Available account cancellation methods. @@ -23,6 +27,37 @@ class UserCancelForm extends EntityNGConfirmFormBase { protected $cancelMethods; /** + * The config factory. + * + * @var \Drupal\Core\Config\ConfigFactory + */ + protected $configFactory; + + /** + * Constructs an EntityFormController object. + * + * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler + * The module handler service. + * @param \Drupal\Core\Config\ConfigFactory $config_factory + * The config factory. + */ + public function __construct(ModuleHandlerInterface $module_handler, ConfigFactory $config_factory) { + parent::__construct($module_handler); + + $this->configFactory = $config_factory; + } + + /** + * {@inheritdoc} + */ + public static function createInstance(ContainerInterface $container, $entity_type, array $entity_info) { + return new static( + $container->get('module_handler'), + $container->get('config.factory') + ); + } + + /** * {@inheritdoc} */ public function getQuestion() { @@ -45,7 +80,7 @@ public function getCancelPath() { */ public function getDescription() { $description = ''; - $default_method = config('user.settings')->get('cancel_method'); + $default_method = $this->configFactory->get('user.settings')->get('cancel_method'); if (user_access('administer users') || user_access('select account cancellation method')) { $description = t('Select the method to cancel the account above.'); } @@ -94,7 +129,7 @@ public function buildForm(array $form, array &$form_state, Request $request = NU '#description' => t('When enabled, the user must confirm the account cancellation via e-mail.'), ); // Also allow to send account canceled notification mail, if enabled. - $default_notify = config('user.settings')->get('notify.status_canceled'); + $default_notify = $this->configFactory->get('user.settings')->get('notify.status_canceled'); $form['user_cancel_notify'] = array( '#type' => 'checkbox', '#title' => t('Notify user when account is canceled.'), diff --git a/core/modules/user/lib/Drupal/user/Form/UserMultipleCancelConfirm.php b/core/modules/user/lib/Drupal/user/Form/UserMultipleCancelConfirm.php index 42daa9f..461a177 100644 --- a/core/modules/user/lib/Drupal/user/Form/UserMultipleCancelConfirm.php +++ b/core/modules/user/lib/Drupal/user/Form/UserMultipleCancelConfirm.php @@ -10,11 +10,12 @@ use Drupal\Component\Utility\String; use Drupal\Core\Config\ConfigFactory; use Drupal\Core\Controller\ControllerInterface; +use Drupal\Core\Entity\EntityManager; use Drupal\Core\Form\ConfirmFormBase; -use Drupal\user\Form\UserCancelForm; use Drupal\user\TempStoreFactory; use Drupal\user\UserStorageControllerInterface; use Symfony\Component\DependencyInjection\ContainerInterface; +use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Request; /** @@ -23,32 +24,57 @@ class UserMultipleCancelConfirm extends ConfirmFormBase implements ControllerInterface { /** + * The temp store factory. + * * @var \Drupal\user\TempStoreFactory */ protected $tempStoreFactory; /** + * The config factory. + * * @var \Drupal\Core\Config\ConfigFactory */ protected $configFactory; /** + * The user storage controller. + * * @var \Drupal\user\UserStorageControllerInterface */ protected $storageController; /** + * The entity manager. + * + * @var \Drupal\Core\Entity\EntityManager + */ + protected $entityManager; + + /** + * The request object. + * * @var \Symfony\Component\HttpFoundation\Request */ protected $request; /** * Constructs a new UserMultipleCancelConfirm. + * + * @param \Drupal\user\TempStoreFactory $temp_store_factory + * The temp store factory. + * @param \Drupal\Core\Config\ConfigFactory $config_factory + * The config factory. + * @param \Drupal\user\UserStorageControllerInterface $storage_controller + * The user storage controller. + * @param \Drupal\Core\Entity\EntityManager $entity_manager + * The entity manager. */ - public function __construct(TempStoreFactory $temp_store_factory, ConfigFactory $config_factory, UserStorageControllerInterface $storage_controller) { + public function __construct(TempStoreFactory $temp_store_factory, ConfigFactory $config_factory, UserStorageControllerInterface $storage_controller, EntityManager $entity_manager) { $this->tempStoreFactory = $temp_store_factory; $this->configFactory = $config_factory; $this->storageController = $storage_controller; + $this->entityManager = $entity_manager; } /** @@ -58,7 +84,8 @@ public static function create(ContainerInterface $container) { return new static( $container->get('user.tempstore'), $container->get('config.factory'), - $container->get('plugin.manager.entity')->getStorageController('user') + $container->get('plugin.manager.entity')->getStorageController('user'), + $container->get('plugin.manager.entity') ); } @@ -177,9 +204,8 @@ public function submitForm(array &$form, array &$form_state) { unset($admin_form_state['values']['user_cancel_confirm']); // The $user global is not a complete user entity, so load the full // entity. - $accounts = $this->storageController->load((array($uid))); - $account = reset($accounts); - $admin_form = new UserCancelForm(); + $account = $this->storageController->load($uid); + $admin_form = $this->entityManager->getFormController('user', 'cancel'); $admin_form->setEntity($account); // Calling this directly required to init form object with $account. $admin_form->buildForm($admin_form_mock, $admin_form_state, $this->request);