You are here

class BootstrapModalMessagesAdminForm in Bootstrap Modal Messages 8

Class BootstrapModalMessagesAdminForm.

@package Drupal\bootstrap_modal_messages\Form

Hierarchy

Expanded class hierarchy of BootstrapModalMessagesAdminForm

1 string reference to 'BootstrapModalMessagesAdminForm'
bootstrap_modal_messages.routing.yml in ./bootstrap_modal_messages.routing.yml
bootstrap_modal_messages.routing.yml

File

src/Form/BootstrapModalMessagesAdminForm.php, line 13

Namespace

Drupal\bootstrap_modal_messages\Form
View source
class BootstrapModalMessagesAdminForm extends ConfigFormBase {

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

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

  /**
   * {@inheritdoc}
   */
  public function buildForm(array $form, FormStateInterface $form_state) {
    $config = $this
      ->config('bootstrap_modal_messages.settings');
    $form['bootstrap_modal_messages_selector'] = array(
      '#type' => 'textfield',
      '#title' => t('Messages div selector'),
      '#default_value' => \Drupal::config('bootstrap_modal_messages.settings')
        ->get('bootstrap_modal_messages_selector'),
      '#description' => t('The CSS/JS selector to find messages for the modal.'),
    );
    $form['bootstrap_modal_messages_multiple'] = array(
      '#type' => 'select',
      '#title' => t('Multiple messages setting'),
      '#options' => array(
        'single' => t('Single modal'),
        'multiple' => t('Multiple - New modal per message type'),
      ),
      '#default_value' => \Drupal::config('bootstrap_modal_messages.settings')
        ->get('bootstrap_modal_messages_multiple'),
      '#description' => t('How to handle multiple messages on one page?'),
    );
    $form['bootstrap_modal_messages_ignore_admin'] = array(
      '#type' => 'select',
      '#title' => t('Ignore admin pages'),
      '#options' => array(
        1 => t('Yes'),
        0 => t('No'),
      ),
      '#default_value' => \Drupal::config('bootstrap_modal_messages.settings')
        ->get('bootstrap_modal_messages_ignore_admin'),
      '#description' => t('Ignore admin pages so that messages display normally?'),
    );

    // Modal header.
    $form['modal_header'] = array(
      '#type' => 'fieldset',
      '#title' => t('Modal Header'),
      '#collapsible' => TRUE,
    );
    $form['modal_header']['bootstrap_modal_messages_show_header'] = array(
      '#type' => 'select',
      '#title' => t('Show header'),
      '#options' => array(
        1 => t('Yes'),
        0 => t('No'),
      ),
      '#default_value' => \Drupal::config('bootstrap_modal_messages.settings')
        ->get('bootstrap_modal_messages_show_header'),
      '#description' => t('Show the modal header.'),
    );
    $title = $config
      ->get('bootstrap_modal_messages_title');
    $form['modal_header']['bootstrap_modal_messages_title'] = array(
      '#type' => 'text_format',
      '#title' => t('Modal Title'),
      '#default_value' => $title['value'] ?: '',
      '#format' => $title['format'] ?: 'plain_text',
      '#description' => t('Enter text to be used in the modal title. Defaults to "Messages".'),
      '#states' => array(
        'visible' => array(
          ':input[name="bootstrap_modal_messages_show_header"]' => array(
            'value' => 1,
          ),
        ),
      ),
    );
    $form['modal_header']['bootstrap_modal_messages_header_close'] = array(
      '#type' => 'select',
      '#title' => t('Show close button (X)'),
      '#options' => array(
        1 => t('Yes'),
        0 => t('No'),
      ),
      '#default_value' => \Drupal::config('bootstrap_modal_messages.settings')
        ->get('bootstrap_modal_messages_header_close'),
      '#description' => t('Show the close (X) button in modal header.'),
    );

    // Modal footer.
    $form['modal_footer'] = array(
      '#type' => 'fieldset',
      '#title' => t('Modal Footer'),
      '#collapsible' => TRUE,
    );
    $form['modal_footer']['bootstrap_modal_messages_show_footer'] = array(
      '#type' => 'select',
      '#title' => t('Show footer'),
      '#options' => array(
        1 => t('Yes'),
        0 => t('No'),
      ),
      '#default_value' => \Drupal::config('bootstrap_modal_messages.settings')
        ->get('bootstrap_modal_messages_show_footer'),
      '#description' => t('Show the modal footer.'),
    );
    $footer = $config
      ->get('bootstrap_modal_messages_footer_html');
    $form['modal_footer']['bootstrap_modal_messages_footer_html'] = array(
      '#type' => 'text_format',
      '#title' => t('Footer HTML'),
      '#default_value' => $footer['value'] ?: '',
      '#format' => $footer['format'] ?: 'plain_text',
      '#description' => t("Enter text to be displayed in the footer. Leave empty to use Bootstrap's default Close button."),
      '#states' => array(
        'visible' => array(
          ':input[name="bootstrap_modal_messages_show_footer"]' => array(
            'value' => 1,
          ),
        ),
      ),
    );

    // Modal controls.
    $form['controls'] = array(
      '#type' => 'fieldset',
      '#title' => t('Controls'),
      '#collapsible' => TRUE,
    );
    $form['controls']['bootstrap_modal_messages_show_onload'] = array(
      '#type' => 'select',
      '#title' => t('Open modal on page load?'),
      '#options' => array(
        1 => t('Yes'),
        0 => t('No - Should enable "Show controls" to display modal'),
      ),
      '#default_value' => \Drupal::config('bootstrap_modal_messages.settings')
        ->get('bootstrap_modal_messages_show_onload'),
      '#description' => t('Open modal immediately when the page loads.'),
    );
    $form['controls']['bootstrap_modal_messages_onload_expiration'] = array(
      '#type' => 'number',
      '#title' => t('Time (in seconds) browser waits to display messages again.'),
      '#min' => 0,
      '#max' => 86400,
      '#default_value' => \Drupal::config('bootstrap_modal_messages.settings')
        ->get('bootstrap_modal_messages_onload_expiration'),
      '#description' => t('Upon subsequent page loads, the "show onload" will not happen until this time has elapsed. Useful for single, sitewide messages.'),
      '#states' => array(
        'visible' => array(
          ':input[name="bootstrap_modal_messages_show_onload"]' => array(
            'value' => 1,
          ),
        ),
      ),
    );
    $form['controls']['bootstrap_modal_messages_show_controls'] = array(
      '#type' => 'select',
      '#title' => t('Show controls?'),
      '#options' => array(
        0 => t('No'),
        1 => t('Yes'),
      ),
      '#default_value' => \Drupal::config('bootstrap_modal_messages.settings')
        ->get('bootstrap_modal_messages_show_controls'),
      '#description' => t('Creates a div that allows you to show messages again. <strong>This setting can be overridden by the permission "View Bootstrap Modal Messages controls".</strong>'),
    );
    $controls = $config
      ->get('bootstrap_modal_messages_controls_html');
    $form['controls']['bootstrap_modal_messages_controls_html'] = array(
      '#type' => 'text_format',
      '#title' => t('Controls HTML'),
      '#default_value' => $controls['value'] ?: '',
      '#format' => $controls['format'] ?: 'plain_text',
      '#description' => t('Enter the HTML to be used in the div for controls.'),
      '#states' => array(
        'visible' => array(
          ':input[name="bootstrap_modal_messages_show_controls"]' => array(
            'value' => 1,
          ),
        ),
      ),
    );
    return parent::buildForm($form, $form_state);
  }

  /**
   * {@inheritdoc}
   */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    $values = $form_state
      ->getValues();
    $this
      ->config('bootstrap_modal_messages.settings')
      ->set('bootstrap_modal_messages_selector', $values['bootstrap_modal_messages_selector'])
      ->set('bootstrap_modal_messages_multiple', $values['bootstrap_modal_messages_multiple'])
      ->set('bootstrap_modal_messages_ignore_admin', $values['bootstrap_modal_messages_ignore_admin'])
      ->set('bootstrap_modal_messages_show_header', $values['bootstrap_modal_messages_show_header'])
      ->set('bootstrap_modal_messages_title', $values['bootstrap_modal_messages_title'])
      ->set('bootstrap_modal_messages_header_close', $values['bootstrap_modal_messages_header_close'])
      ->set('bootstrap_modal_messages_show_footer', $values['bootstrap_modal_messages_show_footer'])
      ->set('bootstrap_modal_messages_footer_html', $values['bootstrap_modal_messages_footer_html'])
      ->set('bootstrap_modal_messages_show_onload', $values['bootstrap_modal_messages_show_onload'])
      ->set('bootstrap_modal_messages_show_controls', $values['bootstrap_modal_messages_show_controls'])
      ->set('bootstrap_modal_messages_controls_html', $values['bootstrap_modal_messages_controls_html'])
      ->set('bootstrap_modal_messages_onload_expiration', $values['bootstrap_modal_messages_onload_expiration'])
      ->save();
    parent::submitForm($form, $form_state);
  }

}

Members

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