class UpdateSettingsForm

Same name in other branches
  1. 9 core/modules/update/src/UpdateSettingsForm.php \Drupal\update\UpdateSettingsForm
  2. 8.9.x core/modules/update/src/UpdateSettingsForm.php \Drupal\update\UpdateSettingsForm
  3. 11.x core/modules/update/src/UpdateSettingsForm.php \Drupal\update\UpdateSettingsForm

Configure update settings for this site.

@internal

Hierarchy

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\update
View source
class UpdateSettingsForm extends ConfigFormBase {
    
    /**
     * {@inheritdoc}
     */
    public function getFormId() {
        return 'update_settings';
    }
    
    /**
     * {@inheritdoc}
     */
    protected function getEditableConfigNames() {
        return [
            'update.settings',
        ];
    }
    
    /**
     * {@inheritdoc}
     */
    public function buildForm(array $form, FormStateInterface $form_state) {
        $form['update_check_frequency'] = [
            '#type' => 'radios',
            '#title' => $this->t('Check for updates'),
            '#config_target' => new ConfigTarget('update.settings', 'check.interval_days', toConfig: fn($value) => intval($value)),
            '#options' => [
                1 => $this->t('Daily'),
                7 => $this->t('Weekly'),
            ],
            '#description' => $this->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' => $this->t('Check for updates of uninstalled modules and themes'),
            '#config_target' => 'update.settings:check.disabled_extensions',
        ];
        $form['update_notify_emails'] = [
            '#type' => 'textarea',
            '#title' => $this->t('Email addresses to notify when updates are available'),
            '#rows' => 4,
            '#config_target' => new ConfigTarget('update.settings', 'notification.emails', static::class . '::arrayToMultiLineString', static::class . '::multiLineStringToArray'),
            '#description' => $this->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' => $this->t('Email notification threshold'),
            '#config_target' => 'update.settings:notification.threshold',
            '#options' => [
                'all' => $this->t('All newer versions'),
                'security' => $this->t('Only security updates'),
            ],
            '#description' => $this->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. If there is a security update, an error message will be printed on administration pages for users with <a href=":update_permissions">permission to view update notifications</a>.', [
                ':status_report' => Url::fromRoute('system.status')->toString(),
                ':update_permissions' => Url::fromRoute('user.admin_permissions', [], [
                    'fragment' => 'module-update',
                ])->toString(),
            ]),
        ];
        return parent::buildForm($form, $form_state);
    }
    
    /**
     * {@inheritdoc}
     */
    protected function formatMultipleViolationsMessage(string $form_element_name, array $violations) : TranslatableMarkup {
        if ($form_element_name !== 'update_notify_emails') {
            return parent::formatMultipleViolationsMessage($form_element_name, $violations);
        }
        $invalid_email_addresses = [];
        foreach ($violations as $violation) {
            $invalid_email_addresses[] = $violation->getInvalidValue();
        }
        return $this->t('%emails are not valid email addresses.', [
            '%emails' => implode(', ', $invalid_email_addresses),
        ]);
    }
    
    /**
     * {@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();
        }
        parent::submitForm($form, $form_state);
    }
    
    /**
     * Prepares the submitted value to be stored in the notify_emails property.
     *
     * @param string $value
     *   The submitted value.
     *
     * @return array
     *   The value to be stored in config.
     */
    public static function multiLineStringToArray(string $value) : array {
        return array_map('trim', explode("\n", trim($value)));
    }
    
    /**
     * Prepares the saved notify_emails property to be displayed in the form.
     *
     * @param array $value
     *   The value saved in config.
     *
     * @return string
     *   The value of the form element.
     */
    public static function arrayToMultiLineString(array $value) : string {
        return implode("\n", $value);
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title Overrides
ConfigFormBase::CONFIG_KEY_TO_FORM_ELEMENT_MAP protected constant The $form_state key which stores a map of config keys to form elements.
ConfigFormBase::copyFormValuesToConfig private static function Copies form values to Config keys.
ConfigFormBase::create public static function Instantiates a new instance of this class. Overrides FormBase::create 18
ConfigFormBase::doStoreConfigMap protected function Helper method for #after_build callback ::storeConfigKeyToFormElementMap().
ConfigFormBase::loadDefaultValuesFromConfig public function Process callback to recursively load default values from #config_target.
ConfigFormBase::storeConfigKeyToFormElementMap public function #after_build callback which stores a map of element names to config keys.
ConfigFormBase::typedConfigManager protected function Returns the typed config manager service.
ConfigFormBase::validateForm public function Form validation handler. Overrides FormBase::validateForm 13
ConfigFormBase::__construct public function Constructs a \Drupal\system\ConfigFormBase object. 17
ConfigFormBaseTrait::config protected function Retrieves a configuration object.
DependencySerializationTrait::$_entityStorages protected property
DependencySerializationTrait::$_serviceIds protected property
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. 2
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.
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.
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. 16
MessengerTrait::messenger public function Gets the messenger. 16
MessengerTrait::setMessenger public function Sets the messenger.
RedirectDestinationTrait::$redirectDestination protected property The redirect destination service. 2
RedirectDestinationTrait::getDestinationArray protected function Prepares a &#039;destination&#039; 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. 3
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::arrayToMultiLineString public static function Prepares the saved notify_emails property to be displayed in the form.
UpdateSettingsForm::buildForm public function Form constructor. Overrides ConfigFormBase::buildForm
UpdateSettingsForm::formatMultipleViolationsMessage protected function Formats multiple violation messages associated with a single form element. Overrides ConfigFormBase::formatMultipleViolationsMessage
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::multiLineStringToArray public static function Prepares the submitted value to be stored in the notify_emails property.
UpdateSettingsForm::submitForm public function Form submission handler. Overrides ConfigFormBase::submitForm

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.