class SiteConfigureForm in Configuration installer 8
Updates the user 1 account.
This is based on the install_configure_form provided by core.
Hierarchy
- class \Drupal\Core\Form\FormBase implements ContainerInjectionInterface, FormInterface uses DependencySerializationTrait, LoggerChannelTrait, MessengerTrait, LinkGeneratorTrait, RedirectDestinationTrait, UrlGeneratorTrait, StringTranslationTrait
- class \Drupal\config_installer\Form\SiteConfigureForm
 
 
Expanded class hierarchy of SiteConfigureForm
See also
\Drupal\Core\Installer\Form\SiteConfigureForm
File
- src/
Form/ SiteConfigureForm.php, line 20  
Namespace
Drupal\config_installer\FormView source
class SiteConfigureForm extends FormBase {
  /**
   * The user storage.
   *
   * @var \Drupal\user\UserStorageInterface
   */
  protected $userStorage;
  /**
   * The state service.
   *
   * @var \Drupal\Core\State\StateInterface
   */
  protected $state;
  /**
   * The app root.
   *
   * @var string
   */
  protected $root;
  /**
   * The site path.
   *
   * @var string
   */
  protected $sitePath;
  /**
   * The module handler.
   *
   * @var ModuleHandlerInterface
   */
  protected $moduleHandler;
  /**
   * Constructs a new SiteConfigureForm.
   *
   * @param string $root
   *   The app root.
   * @param string $site_path
   *   The site path.
   * @param \Drupal\user\UserStorageInterface $user_storage
   *   The user storage.
   * @param \Drupal\Core\State\StateInterface $state
   *   The state service.
   * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
   *   The module handler.
   */
  public function __construct($root, $site_path, UserStorageInterface $user_storage, StateInterface $state, ModuleHandlerInterface $module_handler) {
    $this->root = $root;
    $this->sitePath = $site_path;
    $this->userStorage = $user_storage;
    $this->state = $state;
    $this->moduleHandler = $module_handler;
  }
  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container) {
    return new static($container
      ->get('app.root'), $container
      ->get('site.path'), $container
      ->get('entity.manager')
      ->getStorage('user'), $container
      ->get('state'), $container
      ->get('module_handler'));
  }
  /**
   * {@inheritdoc}
   */
  public function getFormId() {
    return 'config_installer_site_configure_form';
  }
  /**
   * {@inheritdoc}
   */
  public function buildForm(array $form, FormStateInterface $form_state) {
    $form['#title'] = $this
      ->t('Configure site');
    // Warn about settings.php permissions risk.
    $settings_file = $this->sitePath . '/settings.php';
    // Check that $_POST is empty so we only show this message when the form is
    // first displayed, not on the next page after it is submitted. We do not
    // want to repeat it multiple times because it is a general warning that is
    // not related to the rest of the installation process; it would also be
    // especially out of place on the last page of the installer, where it would
    // distract from the message that the Drupal installation has completed
    // successfully.
    $post_params = $this
      ->getRequest()->request
      ->all();
    if (empty($post_params)) {
      $original_profile_name = _config_installer_get_original_install_profile();
      $need_to_write_settings = $original_profile_name !== Settings::get('install_profile');
      // In Drupal 8.3.x it is not necessary to have an install profile written
      // to settings.php.
      if (version_compare(\Drupal::VERSION, '8.3', '>=') && !is_writable(\Drupal::service('site.path') . '/settings.php')) {
        \Drupal::service('kernel')
          ->invalidateContainer();
        $need_to_write_settings = FALSE;
      }
      if ($need_to_write_settings) {
        $settings['settings']['install_profile'] = (object) [
          'value' => $original_profile_name,
          'required' => TRUE,
        ];
        drupal_rewrite_settings($settings);
      }
      if (!drupal_verify_install_file($this->root . '/' . $settings_file, FILE_EXIST | FILE_READABLE | FILE_NOT_WRITABLE) || !drupal_verify_install_file($this->root . '/' . $this->sitePath, FILE_NOT_WRITABLE, 'dir')) {
        drupal_set_message(t('All necessary changes to %dir and %file have been made, so you should remove write permissions to them now in order to avoid security risks. If you are unsure how to do so, consult the <a href="@handbook_url">online handbook</a>.', [
          '%dir' => $this->sitePath,
          '%file' => $settings_file,
          '@handbook_url' => 'http://drupal.org/server-permissions',
        ]), 'warning');
      }
    }
    $form['#attached']['library'][] = 'system/drupal.system';
    $form['admin_account'] = [
      '#type' => 'fieldgroup',
      '#title' => $this
        ->t('Site maintenance account'),
    ];
    $form['admin_account']['account']['name'] = [
      '#type' => 'textfield',
      '#title' => $this
        ->t('Username'),
      '#maxlength' => USERNAME_MAX_LENGTH,
      '#description' => $this
        ->t('Spaces are allowed; punctuation is not allowed except for periods, hyphens, and underscores.'),
      '#required' => TRUE,
      '#attributes' => [
        'class' => [
          'username',
        ],
      ],
    ];
    $form['admin_account']['account']['pass'] = [
      '#type' => 'password_confirm',
      '#required' => TRUE,
      '#size' => 25,
    ];
    $form['admin_account']['account']['#tree'] = TRUE;
    $form['admin_account']['account']['mail'] = [
      '#type' => 'email',
      '#title' => $this
        ->t('Email address'),
      '#required' => TRUE,
    ];
    // Check drush context and use default drush options if available.
    if (function_exists('drush_get_option')) {
      $form['admin_account']['account']['name']['#default_value'] = drush_get_option('account-name', 'admin');
      $form['admin_account']['account']['pass']['#type'] = 'textfield';
      // Targets Drush 9 or higher.
      if (class_exists('\\Drush\\Utils\\StringUtils')) {
        $default_password = drush_get_option('account-pass', \Drush\Utils\StringUtils::generatePassword());
      }
      elseif (function_exists('drush_generate_password')) {
        $default_password = drush_get_option('account-pass', drush_generate_password());
      }
      $form['admin_account']['account']['pass']['#default_value'] = $default_password;
      $form['admin_account']['account']['mail']['#default_value'] = drush_get_option('account-mail', 'admin@example.com');
    }
    $form['actions'] = [
      '#type' => 'actions',
    ];
    $form['actions']['submit'] = [
      '#type' => 'submit',
      '#value' => $this
        ->t('Save and continue'),
      '#weight' => 15,
      '#button_type' => 'primary',
    ];
    return $form;
  }
  /**
   * {@inheritdoc}
   */
  public function validateForm(array &$form, FormStateInterface $form_state) {
    if ($error = user_validate_name($form_state
      ->getValue([
      'account',
      'name',
    ]))) {
      $form_state
        ->setErrorByName('account][name', $error);
    }
  }
  /**
   * {@inheritdoc}
   */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    $account_values = $form_state
      ->getValue('account');
    // We precreated user 1 with placeholder values. Let's save the real values.
    $account = $this->userStorage
      ->load(1);
    $account->init = $account->mail = $account_values['mail'];
    $account->roles = $account
      ->getRoles();
    $account
      ->activate();
    $account->timezone = $form_state
      ->getValue('date_default_timezone');
    $account->pass = $account_values['pass'];
    $account->name = $account_values['name'];
    $account
      ->save();
    // Record when this install ran.
    $this->state
      ->set('install_time', $_SERVER['REQUEST_TIME']);
    if (version_compare(\Drupal::VERSION, '8.3', '>=')) {
      // We need to invalidate the container to ensure that the correct profile
      // is used on after installation.
      \Drupal::service('kernel')
        ->invalidateContainer();
    }
  }
}Members
| 
            Name | 
                  Modifiers | Type | Description | Overrides | 
|---|---|---|---|---|
| 
            DependencySerializationTrait:: | 
                  protected | property | An array of entity type IDs keyed by the property name of their storages. | |
| 
            DependencySerializationTrait:: | 
                  protected | property | An array of service IDs keyed by property name used for serialization. | |
| 
            DependencySerializationTrait:: | 
                  public | function | 1 | |
| 
            DependencySerializationTrait:: | 
                  public | function | 2 | |
| 
            FormBase:: | 
                  protected | property | The config factory. | 1 | 
| 
            FormBase:: | 
                  protected | property | The request stack. | 1 | 
| 
            FormBase:: | 
                  protected | property | The route match. | |
| 
            FormBase:: | 
                  protected | function | Retrieves a configuration object. | |
| 
            FormBase:: | 
                  protected | function | Gets the config factory for this form. | 1 | 
| 
            FormBase:: | 
                  private | function | Returns the service container. | |
| 
            FormBase:: | 
                  protected | function | Gets the current user. | |
| 
            FormBase:: | 
                  protected | function | Gets the request object. | |
| 
            FormBase:: | 
                  protected | function | Gets the route match. | |
| 
            FormBase:: | 
                  protected | function | Gets the logger for a specific channel. | |
| 
            FormBase:: | 
                  protected | function | 
            Returns a redirect response object for the specified route. Overrides UrlGeneratorTrait:: | 
                  |
| 
            FormBase:: | 
                  public | function | Resets the configuration factory. | |
| 
            FormBase:: | 
                  public | function | Sets the config factory for this form. | |
| 
            FormBase:: | 
                  public | function | Sets the request stack object to use. | |
| 
            LinkGeneratorTrait:: | 
                  protected | property | The link generator. | 1 | 
| 
            LinkGeneratorTrait:: | 
                  protected | function | Returns the link generator. | |
| 
            LinkGeneratorTrait:: | 
                  protected | function | Renders a link to a route given a route name and its parameters. | |
| 
            LinkGeneratorTrait:: | 
                  public | function | Sets the link generator service. | |
| 
            LoggerChannelTrait:: | 
                  protected | property | The logger channel factory service. | |
| 
            LoggerChannelTrait:: | 
                  protected | function | Gets the logger for a specific channel. | |
| 
            LoggerChannelTrait:: | 
                  public | function | Injects the logger channel factory. | |
| 
            MessengerTrait:: | 
                  protected | property | The messenger. | 29 | 
| 
            MessengerTrait:: | 
                  public | function | Gets the messenger. | 29 | 
| 
            MessengerTrait:: | 
                  public | function | Sets the messenger. | |
| 
            RedirectDestinationTrait:: | 
                  protected | property | The redirect destination service. | 1 | 
| 
            RedirectDestinationTrait:: | 
                  protected | function | Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url. | |
| 
            RedirectDestinationTrait:: | 
                  protected | function | Returns the redirect destination service. | |
| 
            RedirectDestinationTrait:: | 
                  public | function | Sets the redirect destination service. | |
| 
            SiteConfigureForm:: | 
                  protected | property | The module handler. | |
| 
            SiteConfigureForm:: | 
                  protected | property | The app root. | |
| 
            SiteConfigureForm:: | 
                  protected | property | The site path. | |
| 
            SiteConfigureForm:: | 
                  protected | property | The state service. | |
| 
            SiteConfigureForm:: | 
                  protected | property | The user storage. | |
| 
            SiteConfigureForm:: | 
                  public | function | 
            Form constructor. Overrides FormInterface:: | 
                  |
| 
            SiteConfigureForm:: | 
                  public static | function | 
            Instantiates a new instance of this class. Overrides FormBase:: | 
                  |
| 
            SiteConfigureForm:: | 
                  public | function | 
            Returns a unique string identifying the form. Overrides FormInterface:: | 
                  |
| 
            SiteConfigureForm:: | 
                  public | function | 
            Form submission handler. Overrides FormInterface:: | 
                  |
| 
            SiteConfigureForm:: | 
                  public | function | 
            Form validation handler. Overrides FormBase:: | 
                  |
| 
            SiteConfigureForm:: | 
                  public | function | Constructs a new SiteConfigureForm. | |
| 
            StringTranslationTrait:: | 
                  protected | property | The string translation service. | 1 | 
| 
            StringTranslationTrait:: | 
                  protected | function | Formats a string containing a count of items. | |
| 
            StringTranslationTrait:: | 
                  protected | function | Returns the number of plurals supported by a given language. | |
| 
            StringTranslationTrait:: | 
                  protected | function | Gets the string translation service. | |
| 
            StringTranslationTrait:: | 
                  public | function | Sets the string translation service to use. | 2 | 
| 
            StringTranslationTrait:: | 
                  protected | function | Translates a string to the current language or to a given language. | |
| 
            UrlGeneratorTrait:: | 
                  protected | property | The url generator. | |
| 
            UrlGeneratorTrait:: | 
                  protected | function | Returns the URL generator service. | |
| 
            UrlGeneratorTrait:: | 
                  public | function | Sets the URL generator service. | |
| 
            UrlGeneratorTrait:: | 
                  protected | function | Generates a URL or path for a specific route based on the given parameters. |