Verified Commit 7886a7ed authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3443049 by nicxvan, Arun.k, longwave, alexpott: Remove deprecations in SiteConfigureForm

parent 280a46c0
Loading
Loading
Loading
Loading
Loading
+13 −72
Original line number Diff line number Diff line
@@ -3,15 +3,12 @@
namespace Drupal\Core\Installer\Form;

use Drupal\Core\Datetime\TimeZoneFormHelper;
use Drupal\Core\DependencyInjection\DeprecatedServicePropertyTrait;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Extension\ModuleInstallerInterface;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Locale\CountryManagerInterface;
use Drupal\Core\Site\Settings;
use Drupal\user\UserInterface;
use Drupal\user\UserStorageInterface;
use Drupal\user\UserNameValidator;
use Symfony\Component\DependencyInjection\ContainerInterface;

@@ -22,86 +19,30 @@
 */
class SiteConfigureForm extends ConfigFormBase {

  use DeprecatedServicePropertyTrait;

  /**
   * Defines deprecated injected properties.
   *
   * @var array
   */
  protected array $deprecatedProperties = [
    'countryManager' => 'country_manager',
  ];

  /**
   * The site path.
   *
   * @var string
   */
  protected $sitePath;

  /**
   * The user storage.
   *
   * @var \Drupal\user\UserStorageInterface
   */
  protected $userStorage;

  /**
   * The module installer.
   *
   * @var \Drupal\Core\Extension\ModuleInstallerInterface
   */
  protected $moduleInstaller;

  /**
   * The app root.
   *
   * @var string
   */
  protected $root;

  /**
   * Constructs a new SiteConfigureForm.
   *
   * @param string $root
   *   The app root.
   * @param string $site_path
   * @param string $sitePath
   *   The site path.
   * @param \Drupal\Core\Entity\EntityTypeManagerInterface|\Drupal\user\UserStorageInterface $entityTypeManager
   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager
   *   The entity type manager.
   * @param \Drupal\Core\Extension\ModuleInstallerInterface $module_installer
   * @param \Drupal\Core\Extension\ModuleInstallerInterface $moduleInstaller
   *   The module installer.
   * @param \Drupal\Core\Locale\CountryManagerInterface|\Drupal\user\UserNameValidator $userNameValidator
   * @param \Drupal\user\UserNameValidator $userNameValidator
   *   The user validator.
   * @param bool|null $superUserAccessPolicy
   * @param bool $superUserAccessPolicy
   *   The value of the 'security.enable_super_user' container parameter.
   */
  public function __construct(
    $root,
    $site_path,
    protected EntityTypeManagerInterface|UserStorageInterface $entityTypeManager,
    ModuleInstallerInterface $module_installer,
    protected CountryManagerInterface|UserNameValidator $userNameValidator,
    protected ?bool $superUserAccessPolicy = NULL,
  ) {
    $this->root = $root;
    $this->sitePath = $site_path;
    if ($this->entityTypeManager instanceof UserStorageInterface) {
      @trigger_error('Calling ' . __METHOD__ . '() with the $entityTypeManager argument as UserStorageInterface is deprecated in drupal:10.3.0 and must be EntityTypeManagerInterface in drupal:11.0.0. See https://www.drupal.org/node/3443172', E_USER_DEPRECATED);
      $this->entityTypeManager = \Drupal::entityTypeManager();
    }
    $this->userStorage = $this->entityTypeManager->getStorage('user');
    $this->moduleInstaller = $module_installer;
    if ($userNameValidator instanceof CountryManagerInterface) {
      @trigger_error('Calling ' . __METHOD__ . '() with the $userNameValidator argument as CountryManagerInterface is deprecated in drupal:10.3.0 and must be UserNameValidator in drupal:11.0.0. See https://www.drupal.org/node/3431205', E_USER_DEPRECATED);
      $this->userNameValidator = \Drupal::service('user.name_validator');
    }
    if ($this->superUserAccessPolicy === NULL) {
      @trigger_error('Calling ' . __METHOD__ . '() without the $superUserAccessPolicy argument is deprecated in drupal:10.3.0 and must be passed in drupal:11.0.0. See https://www.drupal.org/node/3443172', E_USER_DEPRECATED);
      $this->superUserAccessPolicy = \Drupal::getContainer()->getParameter('security.enable_super_user') ?? TRUE;
    }
  }
    protected $root,
    protected $sitePath,
    protected EntityTypeManagerInterface $entityTypeManager,
    protected ModuleInstallerInterface $moduleInstaller,
    protected UserNameValidator $userNameValidator,
    protected bool $superUserAccessPolicy,
  ) {}

  /**
   * {@inheritdoc}
@@ -323,7 +264,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) {

    // We created user 1 with placeholder values. Let's save the real values.
    /** @var \Drupal\user\UserInterface $account */
    $account = $this->userStorage->load(1);
    $account = $this->entityTypeManager->getStorage('user')->load(1);
    $account->init = $account->mail = $account_values['mail'];
    $account->roles = $account->getRoles();
    $account->activate();