class SiteConfigureForm in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/lib/Drupal/Core/Installer/Form/SiteConfigureForm.php \Drupal\Core\Installer\Form\SiteConfigureForm
Provides the site configuration form.
Hierarchy
- class \Drupal\Core\Form\FormBase implements ContainerInjectionInterface, FormInterface uses DependencySerializationTrait, LinkGeneratorTrait, RedirectDestinationTrait, UrlGeneratorTrait, StringTranslationTrait
- class \Drupal\Core\Form\ConfigFormBase uses ConfigFormBaseTrait
- class \Drupal\Core\Installer\Form\SiteConfigureForm
- class \Drupal\Core\Form\ConfigFormBase uses ConfigFormBaseTrait
Expanded class hierarchy of SiteConfigureForm
File
- core/
lib/ Drupal/ Core/ Installer/ Form/ SiteConfigureForm.php, line 21 - Contains \Drupal\Core\Installer\Form\SiteConfigureForm.
Namespace
Drupal\Core\Installer\FormView source
class SiteConfigureForm extends ConfigFormBase {
/**
* The site path.
*
* @var string
*/
protected $sitePath;
/**
* The user storage.
*
* @var \Drupal\user\UserStorageInterface
*/
protected $userStorage;
/**
* The state service.
*
* @var \Drupal\Core\State\StateInterface
*/
protected $state;
/**
* The module installer.
*
* @var \Drupal\Core\Extension\ModuleInstallerInterface
*/
protected $moduleInstaller;
/**
* The country manager.
*
* @var \Drupal\Core\Locale\CountryManagerInterface
*/
protected $countryManager;
/**
* The app root.
*
* @var string
*/
protected $root;
/**
* 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\ModuleInstallerInterface $module_installer
* The module installer.
* @param \Drupal\Core\Locale\CountryManagerInterface $country_manager
* The country manager.
*/
public function __construct($root, $site_path, UserStorageInterface $user_storage, StateInterface $state, ModuleInstallerInterface $module_installer, CountryManagerInterface $country_manager) {
$this->root = $root;
$this->sitePath = $site_path;
$this->userStorage = $user_storage;
$this->state = $state;
$this->moduleInstaller = $module_installer;
$this->countryManager = $country_manager;
}
/**
* {@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_installer'), $container
->get('country_manager'));
}
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'install_configure_form';
}
/**
* {@inheritdoc}
*/
protected function getEditableConfigNames() {
return [
'system.date',
'system.site',
'update.settings',
];
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$form['#title'] = $this
->t('Configure site');
// Warn about settings.php permissions risk
$settings_dir = $this->sitePath;
$settings_file = $settings_dir . '/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) && (!drupal_verify_install_file($this->root . '/' . $settings_file, FILE_EXIST | FILE_READABLE | FILE_NOT_WRITABLE) || !drupal_verify_install_file($this->root . '/' . $settings_dir, 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>.', array(
'%dir' => $settings_dir,
'%file' => $settings_file,
':handbook_url' => 'https://www.drupal.org/server-permissions',
)), 'warning');
}
$form['#attached']['library'][] = 'system/drupal.system';
// Add JavaScript time zone detection.
$form['#attached']['library'][] = 'core/drupal.timezone';
// We add these strings as settings because JavaScript translation does not
// work during installation.
$form['#attached']['drupalSettings']['copyFieldValue']['edit-site-mail'] = [
'edit-account-mail',
];
$form['site_information'] = array(
'#type' => 'fieldgroup',
'#title' => $this
->t('Site information'),
);
$form['site_information']['site_name'] = array(
'#type' => 'textfield',
'#title' => $this
->t('Site name'),
'#required' => TRUE,
'#weight' => -20,
);
$form['site_information']['site_mail'] = array(
'#type' => 'email',
'#title' => $this
->t('Site email address'),
'#default_value' => ini_get('sendmail_from'),
'#description' => $this
->t("Automated emails, such as registration information, will be sent from this address. Use an address ending in your site's domain to help prevent these emails from being flagged as spam."),
'#required' => TRUE,
'#weight' => -15,
);
$form['admin_account'] = array(
'#type' => 'fieldgroup',
'#title' => $this
->t('Site maintenance account'),
);
$form['admin_account']['account']['name'] = array(
'#type' => 'textfield',
'#title' => $this
->t('Username'),
'#maxlength' => USERNAME_MAX_LENGTH,
'#description' => $this
->t("Several special characters are allowed, including space, period (.), hyphen (-), apostrophe ('), underscore (_), and the @ sign."),
'#required' => TRUE,
'#attributes' => array(
'class' => array(
'username',
),
),
);
$form['admin_account']['account']['pass'] = array(
'#type' => 'password_confirm',
'#required' => TRUE,
'#size' => 25,
);
$form['admin_account']['account']['#tree'] = TRUE;
$form['admin_account']['account']['mail'] = array(
'#type' => 'email',
'#title' => $this
->t('Email address'),
'#required' => TRUE,
);
$form['regional_settings'] = array(
'#type' => 'fieldgroup',
'#title' => $this
->t('Regional settings'),
);
$countries = $this->countryManager
->getList();
$form['regional_settings']['site_default_country'] = array(
'#type' => 'select',
'#title' => $this
->t('Default country'),
'#empty_value' => '',
'#default_value' => $this
->config('system.date')
->get('country.default'),
'#options' => $countries,
'#description' => $this
->t('Select the default country for the site.'),
'#weight' => 0,
);
$form['regional_settings']['date_default_timezone'] = array(
'#type' => 'select',
'#title' => $this
->t('Default time zone'),
// Use system timezone if set, but avoid throwing a warning in PHP >=5.4
'#default_value' => @date_default_timezone_get(),
'#options' => system_time_zones(),
'#description' => $this
->t('By default, dates in this site will be displayed in the chosen time zone.'),
'#weight' => 5,
'#attributes' => array(
'class' => array(
'timezone-detect',
),
),
);
$form['update_notifications'] = array(
'#type' => 'fieldgroup',
'#title' => $this
->t('Update notifications'),
);
$form['update_notifications']['update_status_module'] = array(
'#type' => 'checkboxes',
'#title' => $this
->t('Update notifications'),
'#options' => array(
1 => $this
->t('Check for updates automatically'),
2 => $this
->t('Receive email notifications'),
),
'#default_value' => array(
1,
2,
),
'#description' => $this
->t('The system will notify you when updates and important security releases are available for installed components. Anonymous information about your site is sent to <a href=":drupal">Drupal.org</a>.', array(
':drupal' => 'https://www.drupal.org',
)),
'#weight' => 15,
);
$form['update_notifications']['update_status_module'][2] = array(
'#states' => array(
'visible' => array(
'input[name="update_status_module[1]"]' => array(
'checked' => TRUE,
),
),
),
);
$form['actions'] = array(
'#type' => 'actions',
);
$form['actions']['submit'] = array(
'#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(array(
'account',
'name',
)))) {
$form_state
->setErrorByName('account][name', $error);
}
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$this
->config('system.site')
->set('name', (string) $form_state
->getValue('site_name'))
->set('mail', (string) $form_state
->getValue('site_mail'))
->save(TRUE);
$this
->config('system.date')
->set('timezone.default', (string) $form_state
->getValue('date_default_timezone'))
->set('country.default', (string) $form_state
->getValue('site_default_country'))
->save(TRUE);
$account_values = $form_state
->getValue('account');
// Enable update.module if this option was selected.
$update_status_module = $form_state
->getValue('update_status_module');
if ($update_status_module[1]) {
$this->moduleInstaller
->install(array(
'file',
'update',
), FALSE);
// Add the site maintenance account's email address to the list of
// addresses to be notified when updates are available, if selected.
if ($update_status_module[2]) {
// Reset the configuration factory so it is updated with the new module.
$this
->resetConfigFactory();
$this
->config('update.settings')
->set('notification.emails', array(
$account_values['mail'],
))
->save(TRUE);
}
}
// 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']);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ConfigFormBaseTrait:: |
protected | function | Retrieves a configuration object. | |
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. | 3 |
FormBase:: |
protected | property | The logger factory. | |
FormBase:: |
protected | property | The request stack. | 1 |
FormBase:: |
protected | property | The route match. | |
FormBase:: |
protected | function | Gets the config factory for this form. | 3 |
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:: |
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. | |
RedirectDestinationTrait:: |
protected | property | The redirect destination service. | |
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 country manager. | |
SiteConfigureForm:: |
protected | property | The module installer. | |
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 ConfigFormBase:: |
|
SiteConfigureForm:: |
public static | function |
Instantiates a new instance of this class. Overrides ConfigFormBase:: |
|
SiteConfigureForm:: |
protected | function |
Gets the configuration names that will be editable. Overrides ConfigFormBaseTrait:: |
|
SiteConfigureForm:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
SiteConfigureForm:: |
public | function |
Form submission handler. Overrides ConfigFormBase:: |
|
SiteConfigureForm:: |
public | function |
Form validation handler. Overrides FormBase:: |
|
SiteConfigureForm:: |
public | function |
Constructs a new SiteConfigureForm. Overrides ConfigFormBase:: |
|
StringTranslationTrait:: |
protected | property | The string translation service. | |
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:: |
protected | function | Returns a redirect response object for the specified route. | |
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. |