You are here

class ModalPageSettingsForm in Modal 5.0.x

Same name and namespace in other branches
  1. 8.3 src/Form/ModalPageSettingsForm.php \Drupal\modal_page\Form\ModalPageSettingsForm
  2. 8 src/Form/ModalPageSettingsForm.php \Drupal\modal_page\Form\ModalPageSettingsForm
  3. 8.2 src/Form/ModalPageSettingsForm.php \Drupal\modal_page\Form\ModalPageSettingsForm
  4. 4.0.x src/Form/ModalPageSettingsForm.php \Drupal\modal_page\Form\ModalPageSettingsForm
  5. 4.1.x src/Form/ModalPageSettingsForm.php \Drupal\modal_page\Form\ModalPageSettingsForm

Form for configure messages.

Hierarchy

Expanded class hierarchy of ModalPageSettingsForm

1 string reference to 'ModalPageSettingsForm'
modal_page.routing.yml in ./modal_page.routing.yml
modal_page.routing.yml

File

src/Form/ModalPageSettingsForm.php, line 15

Namespace

Drupal\modal_page\Form
View source
class ModalPageSettingsForm extends ConfigFormBase {
  use ModalPageSettersTraitHelper;

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container) {

    /** @var static $instance */
    $instance = parent::create($container);
    $instance
      ->setModuleHandler($container
      ->get('module_handler'));
    return $instance;
  }

  /**
   * Set Message info.
   */
  public function setMessagesInfo() {
    $type = 'status';

    // Transform to Info if Info Messages is enabled.
    if ($this->moduleHandler
      ->moduleExists('info_messages')) {
      $type = 'info';
    }
    $this
      ->messenger()
      ->addMessage($this
      ->t('You can create your Modal at <a href="@url_settings">@url_settings</a>', [
      '@url_settings' => Url::fromRoute('modal_page.default')
        ->toString(),
    ]), $type);
    return NULL;
  }

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

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

  /**
   * {@inheritdoc}
   */
  public function buildForm(array $form, FormStateInterface $form_state) {
    $this
      ->setMessagesInfo();
    $config = $this
      ->config('modal_page.settings');
    $form['no_modal_page_external_js'] = [
      '#title' => $this
        ->t("Don't load external JS Bootstrap (bootstrap.min.js)"),
      '#type' => 'checkbox',
      '#description' => $this
        ->t('Just check if the js bootstrap (bootstrap.min.js) is already loaded elsewhere.'),
      '#default_value' => $config
        ->get('no_modal_page_external_js'),
    ];
    $form['allowed_tags'] = [
      '#type' => 'textarea',
      '#title' => $this
        ->t('Allowed Tags'),
      '#description' => $this
        ->t("A list of HTML tags that can be used, separated by commas(,)."),
      '#default_value' => $config
        ->get('allowed_tags') ?? "h1,h2,a,b,big,code,del,em,i,ins,pre,q,small,span,strong,sub,sup,tt,ol,ul,li,p,br,img",
    ];
    $form['actions'] = [
      '#type' => 'actions',
    ];
    $form['actions']['submit'] = [
      '#type' => 'submit',
      '#value' => $this
        ->t('Submit'),
    ];
    return $form;
  }

  /**
   * {@inheritdoc}
   */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    $no_modal_page_external_js = $form_state
      ->getValue('no_modal_page_external_js');
    $config = $this
      ->config('modal_page.settings');
    $config
      ->set('no_modal_page_external_js', $no_modal_page_external_js);
    $config
      ->set('allowed_tags', $form_state
      ->getValue('allowed_tags'));
    $config
      ->save();
    PhpStorageFactory::get('twig')
      ->deleteAll();
    parent::submitForm($form, $form_state);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ConfigFormBase::__construct public function Constructs a \Drupal\system\ConfigFormBase object. 16
ConfigFormBaseTrait::config protected function Retrieves a configuration object.
DependencySerializationTrait::$_entityStorages protected property
DependencySerializationTrait::$_serviceIds protected property
DependencySerializationTrait::__sleep public function 2
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.
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 72
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. 27
MessengerTrait::messenger public function Gets the messenger. 27
MessengerTrait::setMessenger public function Sets the messenger.
ModalPageSettersTraitHelper::$languageManager protected property The language manager.
ModalPageSettersTraitHelper::$moduleHandler protected property Module handler.
ModalPageSettersTraitHelper::setLanguageManager public function Set Language Manager.
ModalPageSettersTraitHelper::setModuleHandler public function Set Module Handler.
ModalPageSettingsForm::buildForm public function Form constructor. Overrides ConfigFormBase::buildForm
ModalPageSettingsForm::create public static function Instantiates a new instance of this class. Overrides ConfigFormBase::create
ModalPageSettingsForm::getEditableConfigNames protected function Gets the configuration names that will be editable. Overrides ConfigFormBaseTrait::getEditableConfigNames
ModalPageSettingsForm::getFormId public function Returns a unique string identifying the form. Overrides FormInterface::getFormId
ModalPageSettingsForm::setMessagesInfo public function Set Message info.
ModalPageSettingsForm::submitForm public function Form submission handler. Overrides ConfigFormBase::submitForm
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. 4
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.