You are here

class AdminSettingsForm in Mass Contact 8

Admin settings form for Mass Contact.

Hierarchy

Expanded class hierarchy of AdminSettingsForm

1 file declares its use of AdminSettingsForm
AdminSettingsFormTest.php in src/Tests/Form/AdminSettingsFormTest.php
1 string reference to 'AdminSettingsForm'
mass_contact.routing.yml in ./mass_contact.routing.yml
mass_contact.routing.yml

File

src/Form/AdminSettingsForm.php, line 12

Namespace

Drupal\mass_contact\Form
View source
class AdminSettingsForm extends SettingsFormBase {

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

  /**
   * {@inheritdoc}
   */
  protected function getConfigKeys() {
    return [
      'form_information',
      'recipient_limit',
      'send_with_cron',
      'optout_enabled',
      'create_archive_copy',
      'hourly_threshold',
      'category_display',
    ];
  }

  /**
   * {@inheritdoc}
   */
  public function buildForm(array $form, FormStateInterface $form_state) {
    $form = parent::buildForm($form, $form_state);
    $config = $this
      ->config('mass_contact.settings');
    $form['form_information'] = [
      '#type' => 'textarea',
      '#title' => $this
        ->t('Additional information for Mass Contact form'),
      '#default_value' => $config
        ->get('form_information'),
      '#description' => $this
        ->t('Information to show on the <a href=":url">Mass Contact page</a>.', [
        ':url' => Url::fromRoute('entity.mass_contact_message.add_form')
          ->toString(),
      ]),
    ];

    // Rate limiting options.
    $form['limiting_options'] = [
      '#type' => 'details',
      '#open' => TRUE,
      '#title' => $this
        ->t('Rate limiting options'),
      '#description' => $this
        ->t('By combining the two options below, messages sent through this module will be queued to be sent drung cron runs. Keep in mind that if you set your number of recipients to be the same as your limit, messages from this or other modules may be blocked by your hosting provider.'),
    ];

    // The maximum number of users to send to at one time.
    $form['limiting_options']['recipient_limit'] = [
      '#type' => 'number',
      '#title' => $this
        ->t('Maximum number of recipients before splitting up the email'),
      '#min' => 0,
      '#default_value' => $config
        ->get('recipient_limit'),
      '#description' => $this
        ->t('This is a workaround for server-side limits on the number of recipients in a single mail message. Once this limit is reached, the recipient list will be broken up and multiple copies of the message will be sent out until all recipients receive the mail. Setting this to 0 (zero) will turn this feature off.'),
      '#required' => TRUE,
    ];

    // The maximum number of users to send to at one time.
    $form['mass_contact_rate_limiting_options']['send_with_cron'] = [
      '#type' => 'checkbox',
      '#title' => $this
        ->t('Send messages with Cron'),
      '#default_value' => $config
        ->get('send_with_cron'),
      '#description' => $this
        ->t('This is another workaround for server-side limits. Check this box to delay sending until the next Cron run(s).'),
    ];

    // Opt out options.
    $form['mass_contact_optout_options'] = [
      '#type' => 'details',
      '#title' => $this
        ->t('Opt-out options'),
    ];

    // @todo Refactor this when adding optout functionality to utilize a field.
    $form['mass_contact_optout_options']['optout_enabled'] = [
      '#type' => 'radios',
      '#title' => $this
        ->t('Allow users to opt-out of mass email messages'),
      '#default_value' => $config
        ->get('optout_enabled'),
      '#options' => [
        MassContactInterface::OPT_OUT_DISABLED => $this
          ->t('No'),
        MassContactInterface::OPT_OUT_GLOBAL => $this
          ->t('Yes'),
        MassContactInterface::OPT_OUT_CATEGORY => $this
          ->t('Selected categories'),
      ],
      '#description' => $this
        ->t("Allow users to opt-out of receiving mass email messages. If 'No' is chosen, then the site's users will not be able to opt-out of receiving mass email messages. If 'Yes' is chosen, then the site's users will be able to opt-out of receiving mass email messages, and they will not receive any from any category. If 'Selected categories' is chosen, then the site's users will be able to opt-out of receiving mass email messages from which ever categories they choose."),
    ];

    // Node copy options.
    $form['create_archive_copy'] = [
      '#type' => 'checkbox',
      '#title' => $this
        ->t('Archive messages by saving a copy as a node'),
      '#default_value' => $config
        ->get('create_archive_copy'),
    ];

    // Flood control options.
    $form['hourly_threshold'] = [
      '#type' => 'number',
      '#title' => $this
        ->t('Hourly threshold'),
      '#min' => 0,
      '#default_value' => $config
        ->get('hourly_threshold'),
      '#description' => $this
        ->t('The maximum number of Mass Contact form submissions a user can perform per hour.'),
    ];

    // Category options.
    $form['category_display'] = [
      '#type' => 'radios',
      '#title' => $this
        ->t('Field to use to display the categories'),
      '#default_value' => $config
        ->get('category_display'),
      '#options' => [
        'select' => 'Select list',
        'checkboxes' => 'Check boxes',
      ],
      '#description' => $this
        ->t("Select the form field to use to display the available categories to the message sender."),
    ];
    return $form;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
AdminSettingsForm::buildForm public function Form constructor. Overrides ConfigFormBase::buildForm
AdminSettingsForm::getConfigKeys protected function Get config keys to save. Overrides SettingsFormBase::getConfigKeys
AdminSettingsForm::getFormId public function Returns a unique string identifying the form. Overrides FormInterface::getFormId
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.
SettingsFormBase::getEditableConfigNames protected function Gets the configuration names that will be editable. Overrides ConfigFormBaseTrait::getEditableConfigNames
SettingsFormBase::submitForm public function Form submission handler. Overrides ConfigFormBase::submitForm
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.
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.