You are here

class SubscriptionSettingsForm in Simplenews 8.2

Same name and namespace in other branches
  1. 8 src/Form/SubscriptionSettingsForm.php \Drupal\simplenews\Form\SubscriptionSettingsForm
  2. 3.x src/Form/SubscriptionSettingsForm.php \Drupal\simplenews\Form\SubscriptionSettingsForm

Configure simplenews subscription settings.

Hierarchy

Expanded class hierarchy of SubscriptionSettingsForm

1 string reference to 'SubscriptionSettingsForm'
simplenews.routing.yml in ./simplenews.routing.yml
simplenews.routing.yml

File

src/Form/SubscriptionSettingsForm.php, line 11

Namespace

Drupal\simplenews\Form
View source
class SubscriptionSettingsForm extends ConfigFormBase {

  /**
   * {@inheritdoc}
   */
  public function getFormId() {
    return 'simplenews_admin_settings_subscription';
  }

  /**
   * {@inheritdoc}
   */
  protected function getEditableConfigNames() {
    return [
      'simplenews.settings',
    ];
  }

  /**
   * {@inheritdoc}
   */
  public function buildForm(array $form, FormStateInterface $form_state) {
    $config = $this
      ->config('simplenews.settings');
    $form['subscription_tidy'] = [
      '#type' => 'fieldset',
      '#title' => $this
        ->t('Tidy unconfirmed subscriptions'),
      '#collapsible' => FALSE,
    ];
    $form['subscription_tidy']['simplenews_tidy_unconfirmed'] = [
      '#type' => 'number',
      '#title' => t('Days'),
      '#default_value' => empty($database['port']) ? '' : $database['port'],
      '#min' => 0,
      '#max' => 365,
      '#description' => $this
        ->t('Tidy unconfirmed subscriptions after a number of days (recommended), or zero to skip.'),
      '#default_value' => $config
        ->get('subscription.tidy_unconfirmed'),
    ];
    $form['subscription_mail'] = [
      '#type' => 'fieldset',
      '#title' => $this
        ->t('Confirmation emails'),
      '#collapsible' => FALSE,
    ];
    $form['subscription_mail']['simplenews_use_combined'] = [
      '#type' => 'select',
      '#title' => $this
        ->t('Use combined confirmation mails'),
      '#options' => [
        'multiple' => $this
          ->t('For multiple changes'),
        'always' => $this
          ->t('Always'),
        'never' => $this
          ->t('Never'),
      ],
      '#description' => $this
        ->t('Combined confirmation mails allow subscribers to confirm multiple newsletter changes with single mail.'),
      '#default_value' => $config
        ->get('subscription.use_combined'),
    ];
    if (\Drupal::moduleHandler()
      ->moduleExists('token')) {
      $form['subscription_mail']['token_help'] = [
        '#title' => $this
          ->t('Replacement patterns'),
        '#type' => 'fieldset',
        '#collapsible' => TRUE,
        '#collapsed' => TRUE,
      ];
      $form['subscription_mail']['token_help']['browser'] = [
        '#theme' => 'token_tree_link',
        '#token_types' => [
          'simplenews-newsletter',
          'simplenews-subscriber',
        ],
      ];
    }
    $form['subscription_mail']['single'] = [
      '#type' => 'fieldset',
      '#title' => $this
        ->t('Single confirmation mails'),
      '#collapsed' => TRUE,
      '#collapsible' => TRUE,
      '#states' => [
        'invisible' => [
          ':input[name="simplenews_use_combined"]' => [
            'value' => 'always',
          ],
        ],
      ],
    ];
    $form['subscription_mail']['single']['simplenews_confirm_subscribe_subject'] = [
      '#type' => 'textfield',
      '#title' => $this
        ->t('Subject'),
      '#default_value' => $config
        ->get('subscription.confirm_subscribe_subject'),
      '#maxlength' => 180,
    ];
    $form['subscription_mail']['single']['simplenews_confirm_subscribe_unsubscribed'] = [
      '#type' => 'textarea',
      '#title' => $this
        ->t('Body text of subscribe email'),
      '#default_value' => $config
        ->get('subscription.confirm_subscribe_unsubscribed'),
      '#rows' => 5,
    ];
    $form['subscription_mail']['single']['simplenews_confirm_subscribe_subscribed'] = [
      '#type' => 'textarea',
      '#title' => $this
        ->t('Body text for already subscribed visitor'),
      '#default_value' => $config
        ->get('subscription.confirm_subscribe_subscribed'),
      '#rows' => 5,
    ];
    $form['subscription_mail']['single']['simplenews_confirm_unsubscribe_subscribed'] = [
      '#type' => 'textarea',
      '#title' => $this
        ->t('Body text of unsubscribe email'),
      '#default_value' => $config
        ->get('subscription.confirm_unsubscribe_subscribed'),
      '#rows' => 5,
    ];
    $form['subscription_mail']['single']['simplenews_confirm_unsubscribe_unsubscribed'] = [
      '#type' => 'textarea',
      '#title' => $this
        ->t('Body text for not yet subscribed visitor'),
      '#default_value' => $config
        ->get('subscription.confirm_unsubscribe_unsubscribed'),
      '#rows' => 5,
    ];
    $form['subscription_mail']['combined'] = [
      '#type' => 'fieldset',
      '#title' => $this
        ->t('Combined confirmation mails'),
      '#collapsed' => TRUE,
      '#collapsible' => TRUE,
      '#states' => [
        'invisible' => [
          ':input[name="simplenews_use_combined"]' => [
            'value' => 'never',
          ],
        ],
      ],
    ];
    $form['subscription_mail']['combined']['simplenews_confirm_combined_subject'] = [
      '#type' => 'textfield',
      '#title' => $this
        ->t('Subject text for combined confirmation mail'),
      '#default_value' => $config
        ->get('subscription.confirm_combined_subject'),
    ];
    $form['subscription_mail']['combined']['simplenews_confirm_combined_body'] = [
      '#type' => 'textarea',
      '#title' => $this
        ->t('Body text for combined confirmation mail'),
      '#default_value' => $config
        ->get('subscription.confirm_combined_body'),
      '#rows' => 5,
    ];
    $form['subscription_mail']['combined']['simplenews_confirm_combined_body_unchanged'] = [
      '#type' => 'textarea',
      '#title' => $this
        ->t('Body text for unchanged combined confirmation mail'),
      '#default_value' => $config
        ->get('subscription.confirm_combined_body_unchanged'),
      '#rows' => 5,
      '#description' => $this
        ->t('This body is used when there are no change requests which have no effect, e.g trying to subscribe when already being subscribed to a newsletter.'),
    ];
    $form['subscription_mail']['combined']['simplenews_confirm_combined_line_subscribe_unsubscribed'] = [
      '#type' => 'textfield',
      '#title' => $this
        ->t('Change text for a new subscription'),
      '#default_value' => $config
        ->get('subscription.confirm_combined_line_subscribe_unsubscribed'),
    ];
    $form['subscription_mail']['combined']['simplenews_confirm_combined_line_subscribe_subscribed'] = [
      '#type' => 'textfield',
      '#title' => $this
        ->t('Change text when already subscribed'),
      '#default_value' => $config
        ->get('subscription.confirm_combined_line_subscribe_subscribed'),
    ];
    $form['subscription_mail']['combined']['simplenews_confirm_combined_line_unsubscribe_subscribed'] = [
      '#type' => 'textfield',
      '#title' => $this
        ->t('Change text for an unsubscription'),
      '#default_value' => $config
        ->get('subscription.confirm_combined_line_unsubscribe_subscribed'),
    ];
    $form['subscription_mail']['combined']['simplenews_confirm_combined_line_unsubscribe_unsubscribed'] = [
      '#type' => 'textfield',
      '#title' => $this
        ->t('Change text when already unsubscribed'),
      '#default_value' => $config
        ->get('subscription.confirm_combined_line_unsubscribe_unsubscribed'),
    ];
    $form['confirm_pages'] = [
      '#type' => 'fieldset',
      '#title' => $this
        ->t('Confirmation pages'),
      '#collapsible' => FALSE,
    ];
    $form['confirm_pages']['simplenews_confirm_subscribe_page'] = [
      '#type' => 'textfield',
      '#title' => $this
        ->t('Subscribe confirmation'),
      '#description' => $this
        ->t('Drupal path or URL of the destination page where after the subscription is confirmed (e.g. /node/123). Leave empty to go to the front page.'),
      '#default_value' => $config
        ->get('subscription.confirm_subscribe_page'),
    ];
    $form['confirm_pages']['simplenews_confirm_unsubscribe_page'] = [
      '#type' => 'textfield',
      '#title' => $this
        ->t('Unsubscribe confirmation'),
      '#description' => $this
        ->t('Drupal path or URL of the destination page when the subscription removal is confirmed (e.g. /node/123). Leave empty to go to the front page.'),
      '#default_value' => $config
        ->get('subscription.confirm_unsubscribe_page'),
    ];
    return parent::buildForm($form, $form_state);
  }

  /**
   * {@inheritdoc}
   */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    $this
      ->config('simplenews.settings')
      ->set('subscription.tidy_unconfirmed', $form_state
      ->getValue('simplenews_tidy_unconfirmed'))
      ->set('subscription.use_combined', $form_state
      ->getValue('simplenews_use_combined'))
      ->set('subscription.confirm_subscribe_subject', $form_state
      ->getValue('simplenews_confirm_subscribe_subject'))
      ->set('subscription.confirm_subscribe_unsubscribed', $form_state
      ->getValue('simplenews_confirm_subscribe_unsubscribed'))
      ->set('subscription.confirm_subscribe_subscribed', $form_state
      ->getValue('simplenews_confirm_subscribe_subscribed'))
      ->set('subscription.confirm_unsubscribe_subscribed', $form_state
      ->getValue('simplenews_confirm_unsubscribe_subscribed'))
      ->set('subscription.confirm_unsubscribe_unsubscribed', $form_state
      ->getValue('simplenews_confirm_unsubscribe_unsubscribed'))
      ->set('subscription.confirm_combined_subject', $form_state
      ->getValue('simplenews_confirm_combined_subject'))
      ->set('subscription.confirm_combined_body', $form_state
      ->getValue('simplenews_confirm_combined_body'))
      ->set('subscription.confirm_combined_body_unchanged', $form_state
      ->getValue('simplenews_confirm_combined_body_unchanged'))
      ->set('subscription.confirm_combined_line_subscribe_unsubscribed', $form_state
      ->getValue('simplenews_confirm_combined_line_subscribe_unsubscribed'))
      ->set('subscription.confirm_combined_line_subscribe_subscribed', $form_state
      ->getValue('simplenews_confirm_combined_line_subscribe_subscribed'))
      ->set('subscription.confirm_combined_line_unsubscribe_subscribed', $form_state
      ->getValue('simplenews_confirm_combined_line_unsubscribe_subscribed'))
      ->set('subscription.confirm_combined_line_unsubscribe_unsubscribed', $form_state
      ->getValue('simplenews_confirm_combined_line_unsubscribe_unsubscribed'))
      ->set('subscription.confirm_subscribe_page', $form_state
      ->getValue('simplenews_confirm_subscribe_page'))
      ->set('subscription.confirm_unsubscribe_page', $form_state
      ->getValue('simplenews_confirm_unsubscribe_page'))
      ->save();
    parent::submitForm($form, $form_state);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ConfigFormBase::create public static function Instantiates a new instance of this class. Overrides FormBase::create 13
ConfigFormBase::__construct public function Constructs a \Drupal\system\ConfigFormBase object. 11
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. 1
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. 1
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.
FormBase::validateForm public function Form validation handler. Overrides FormInterface::validateForm 62
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. 29
MessengerTrait::messenger public function Gets the messenger. 29
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. 1
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.
SubscriptionSettingsForm::buildForm public function Form constructor. Overrides ConfigFormBase::buildForm
SubscriptionSettingsForm::getEditableConfigNames protected function Gets the configuration names that will be editable. Overrides ConfigFormBaseTrait::getEditableConfigNames
SubscriptionSettingsForm::getFormId public function Returns a unique string identifying the form. Overrides FormInterface::getFormId
SubscriptionSettingsForm::submitForm public function Form submission handler. Overrides ConfigFormBase::submitForm
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.