class UpdateSettingsForm
Same name in other branches
- 9 core/modules/update/src/UpdateSettingsForm.php \Drupal\update\UpdateSettingsForm
- 10 core/modules/update/src/UpdateSettingsForm.php \Drupal\update\UpdateSettingsForm
- 11.x core/modules/update/src/UpdateSettingsForm.php \Drupal\update\UpdateSettingsForm
Configure update settings for this site.
@internal
Hierarchy
- class \Drupal\Core\Form\FormBase implements \Drupal\Core\Form\FormInterface, \Drupal\Core\DependencyInjection\ContainerInjectionInterface uses \Drupal\Core\DependencyInjection\DependencySerializationTrait, \Drupal\Core\Routing\LinkGeneratorTrait, \Drupal\Core\Logger\LoggerChannelTrait, \Drupal\Core\Messenger\MessengerTrait, \Drupal\Core\Routing\RedirectDestinationTrait, \Drupal\Core\StringTranslation\StringTranslationTrait, \Drupal\Core\Routing\UrlGeneratorTrait
- class \Drupal\Core\Form\ConfigFormBase extends \Drupal\Core\Form\FormBase uses \Drupal\Core\Form\ConfigFormBaseTrait
- class \Drupal\update\UpdateSettingsForm extends \Drupal\Core\Form\ConfigFormBase implements \Drupal\Core\DependencyInjection\ContainerInjectionInterface
- class \Drupal\Core\Form\ConfigFormBase extends \Drupal\Core\Form\FormBase uses \Drupal\Core\Form\ConfigFormBaseTrait
Expanded class hierarchy of UpdateSettingsForm
1 string reference to 'UpdateSettingsForm'
- update.routing.yml in core/
modules/ update/ update.routing.yml - core/modules/update/update.routing.yml
File
-
core/
modules/ update/ src/ UpdateSettingsForm.php, line 16
Namespace
Drupal\updateView source
class UpdateSettingsForm extends ConfigFormBase implements ContainerInjectionInterface {
/**
* The email validator.
*
* @var \Drupal\Component\Utility\EmailValidatorInterface
*/
protected $emailValidator;
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
$instance = parent::create($container);
$instance->emailValidator = $container->get('email.validator');
return $instance;
}
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'update_settings';
}
/**
* {@inheritdoc}
*/
protected function getEditableConfigNames() {
return [
'update.settings',
];
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this->config('update.settings');
$form['update_check_frequency'] = [
'#type' => 'radios',
'#title' => t('Check for updates'),
'#default_value' => $config->get('check.interval_days'),
'#options' => [
'1' => t('Daily'),
'7' => t('Weekly'),
],
'#description' => t('Select how frequently you want to automatically check for new releases of your currently installed modules and themes.'),
];
$form['update_check_disabled'] = [
'#type' => 'checkbox',
'#title' => t('Check for updates of uninstalled modules and themes'),
'#default_value' => $config->get('check.disabled_extensions'),
];
$notification_emails = $config->get('notification.emails');
$form['update_notify_emails'] = [
'#type' => 'textarea',
'#title' => t('Email addresses to notify when updates are available'),
'#rows' => 4,
'#default_value' => implode("\n", $notification_emails),
'#description' => t('Whenever your site checks for available updates and finds new releases, it can notify a list of users via email. Put each address on a separate line. If blank, no emails will be sent.'),
];
$form['update_notification_threshold'] = [
'#type' => 'radios',
'#title' => t('Email notification threshold'),
'#default_value' => $config->get('notification.threshold'),
'#options' => [
'all' => t('All newer versions'),
'security' => t('Only security updates'),
],
'#description' => t('You can choose to send email only if a security update is available, or to be notified about all newer versions. If there are updates available of Drupal core or any of your installed modules and themes, your site will always print a message on the <a href=":status_report">status report</a> page, and will also display an error message on administration pages if there is a security update.', [
':status_report' => Url::fromRoute('system.status')->toString(),
]),
];
return parent::buildForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function validateForm(array &$form, FormStateInterface $form_state) {
$form_state->set('notify_emails', []);
if (!$form_state->isValueEmpty('update_notify_emails')) {
$valid = [];
$invalid = [];
foreach (explode("\n", trim($form_state->getValue('update_notify_emails'))) as $email) {
$email = trim($email);
if (!empty($email)) {
if ($this->emailValidator
->isValid($email)) {
$valid[] = $email;
}
else {
$invalid[] = $email;
}
}
}
if (empty($invalid)) {
$form_state->set('notify_emails', $valid);
}
elseif (count($invalid) == 1) {
$form_state->setErrorByName('update_notify_emails', $this->t('%email is not a valid email address.', [
'%email' => reset($invalid),
]));
}
else {
$form_state->setErrorByName('update_notify_emails', $this->t('%emails are not valid email addresses.', [
'%emails' => implode(', ', $invalid),
]));
}
}
parent::validateForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$config = $this->config('update.settings');
// See if the update_check_disabled setting is being changed, and if so,
// invalidate all update status data.
if ($form_state->getValue('update_check_disabled') != $config->get('check.disabled_extensions')) {
update_storage_clear();
}
$config->set('check.disabled_extensions', $form_state->getValue('update_check_disabled'))
->set('check.interval_days', $form_state->getValue('update_check_frequency'))
->set('notification.emails', $form_state->get('notify_emails'))
->set('notification.threshold', $form_state->getValue('update_notification_threshold'))
->save();
parent::submitForm($form, $form_state);
}
}
Members
Title Sort descending | Deprecated | Modifiers | Object type | Summary | Overriden Title | Overrides |
---|---|---|---|---|---|---|
ConfigFormBase::__construct | public | function | Constructs a \Drupal\system\ConfigFormBase object. | 16 | ||
ConfigFormBaseTrait::config | protected | function | Retrieves a configuration object. | |||
DependencySerializationTrait::$_entityStorages | protected | property | An array of entity type IDs keyed by the property name of their storages. | |||
DependencySerializationTrait::$_serviceIds | protected | property | An array of service IDs keyed by property name used for serialization. | |||
DependencySerializationTrait::__sleep | public | function | 1 | |||
DependencySerializationTrait::__wakeup | public | function | 2 | |||
FormBase::$configFactory | protected | property | The config factory. | 3 | ||
FormBase::$requestStack | protected | property | The request stack. | 1 | ||
FormBase::$routeMatch | protected | property | The route match. | |||
FormBase::configFactory | protected | function | Gets the config factory for this form. | 3 | ||
FormBase::container | private | function | Returns the service container. | |||
FormBase::currentUser | protected | function | Gets the current user. | |||
FormBase::getRequest | protected | function | Gets the request object. | |||
FormBase::getRouteMatch | protected | function | Gets the route match. | |||
FormBase::logger | protected | function | Gets the logger for a specific channel. | |||
FormBase::redirect | protected | function | Returns a redirect response object for the specified route. | Overrides UrlGeneratorTrait::redirect | ||
FormBase::resetConfigFactory | public | function | Resets the configuration factory. | |||
FormBase::setConfigFactory | public | function | Sets the config factory for this form. | |||
FormBase::setRequestStack | public | function | Sets the request stack object to use. | |||
LinkGeneratorTrait::$linkGenerator | protected | property | The link generator. | 1 | ||
LinkGeneratorTrait::getLinkGenerator | Deprecated | protected | function | Returns the link generator. | ||
LinkGeneratorTrait::l | Deprecated | protected | function | Renders a link to a route given a route name and its parameters. | ||
LinkGeneratorTrait::setLinkGenerator | Deprecated | public | function | Sets the link generator service. | ||
LoggerChannelTrait::$loggerFactory | protected | property | The logger channel factory service. | |||
LoggerChannelTrait::getLogger | protected | function | Gets the logger for a specific channel. | |||
LoggerChannelTrait::setLoggerFactory | public | function | Injects the logger channel factory. | |||
MessengerTrait::$messenger | protected | property | The messenger. | 17 | ||
MessengerTrait::messenger | public | function | Gets the messenger. | 17 | ||
MessengerTrait::setMessenger | public | function | Sets the messenger. | |||
RedirectDestinationTrait::$redirectDestination | protected | property | The redirect destination service. | 1 | ||
RedirectDestinationTrait::getDestinationArray | protected | function | Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url. | |||
RedirectDestinationTrait::getRedirectDestination | protected | function | Returns the redirect destination service. | |||
RedirectDestinationTrait::setRedirectDestination | public | function | Sets the redirect destination service. | |||
StringTranslationTrait::$stringTranslation | protected | property | The string translation service. | |||
StringTranslationTrait::formatPlural | protected | function | Formats a string containing a count of items. | |||
StringTranslationTrait::getNumberOfPlurals | protected | function | Returns the number of plurals supported by a given language. | |||
StringTranslationTrait::getStringTranslation | protected | function | Gets the string translation service. | |||
StringTranslationTrait::setStringTranslation | public | function | Sets the string translation service to use. | 2 | ||
StringTranslationTrait::t | protected | function | Translates a string to the current language or to a given language. | |||
UpdateSettingsForm::$emailValidator | protected | property | The email validator. | |||
UpdateSettingsForm::buildForm | public | function | Form constructor. | Overrides ConfigFormBase::buildForm | ||
UpdateSettingsForm::create | public static | function | Instantiates a new instance of this class. | Overrides ConfigFormBase::create | ||
UpdateSettingsForm::getEditableConfigNames | protected | function | Gets the configuration names that will be editable. | Overrides ConfigFormBaseTrait::getEditableConfigNames | ||
UpdateSettingsForm::getFormId | public | function | Returns a unique string identifying the form. | Overrides FormInterface::getFormId | ||
UpdateSettingsForm::submitForm | public | function | Form submission handler. | Overrides ConfigFormBase::submitForm | ||
UpdateSettingsForm::validateForm | public | function | Form validation handler. | Overrides FormBase::validateForm | ||
UrlGeneratorTrait::$urlGenerator | protected | property | The url generator. | |||
UrlGeneratorTrait::getUrlGenerator | Deprecated | protected | function | Returns the URL generator service. | ||
UrlGeneratorTrait::setUrlGenerator | Deprecated | public | function | Sets the URL generator service. | ||
UrlGeneratorTrait::url | Deprecated | protected | function | Generates a URL or path for a specific route based on the given parameters. |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.