class ModalPageSettingsForm in Modal 4.0.x
Same name and namespace in other branches
- 8.3 src/Form/ModalPageSettingsForm.php \Drupal\modal_page\Form\ModalPageSettingsForm
- 8 src/Form/ModalPageSettingsForm.php \Drupal\modal_page\Form\ModalPageSettingsForm
- 8.2 src/Form/ModalPageSettingsForm.php \Drupal\modal_page\Form\ModalPageSettingsForm
- 5.0.x src/Form/ModalPageSettingsForm.php \Drupal\modal_page\Form\ModalPageSettingsForm
- 4.1.x src/Form/ModalPageSettingsForm.php \Drupal\modal_page\Form\ModalPageSettingsForm
Form for configure messages.
Hierarchy
- class \Drupal\Core\Form\FormBase implements ContainerInjectionInterface, FormInterface uses DependencySerializationTrait, LoggerChannelTrait, MessengerTrait, RedirectDestinationTrait, StringTranslationTrait
- class \Drupal\Core\Form\ConfigFormBase uses ConfigFormBaseTrait
- class \Drupal\modal_page\Form\ModalPageSettingsForm uses ModalPageSettersTraitHelper
- class \Drupal\Core\Form\ConfigFormBase uses ConfigFormBaseTrait
Expanded class hierarchy of ModalPageSettingsForm
1 string reference to 'ModalPageSettingsForm'
File
- src/
Form/ ModalPageSettingsForm.php, line 15
Namespace
Drupal\modal_page\FormView 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['global_settings'] = [
'#type' => 'details',
'#title' => $this
->t('Global Settings'),
'#open' => TRUE,
];
$form['global_settings']['bootstrap'] = [
'#type' => 'details',
'#title' => $this
->t('Bootstrap'),
'#open' => TRUE,
];
$form['global_settings']['bootstrap']['verify_load_bootstrap_automatically'] = [
'#title' => $this
->t("Verify and Load Bootstrap automatically if necessary (Recommended)"),
'#type' => 'checkbox',
'#description' => $this
->t("It will verify and load bootstrap.min.js only if you don't have it loaded yet."),
'#default_value' => $config
->get('verify_load_bootstrap_automatically'),
];
$form['global_settings']['bootstrap']['load_bootstrap'] = [
'#title' => $this
->t("Load Bootstrap with Modal Page"),
'#type' => 'checkbox',
'#description' => $this
->t('It will load bootstrap.min.js. If you already have it loaded in other place you can disable this option.'),
'#default_value' => $config
->get('load_bootstrap'),
'#states' => [
'disabled' => [
':input[name="verify_load_bootstrap_automatically"]' => [
'checked' => TRUE,
],
],
],
];
$form['global_settings']['html_tags'] = [
'#type' => 'details',
'#title' => $this
->t('HTML Tags'),
'#open' => TRUE,
];
$form['global_settings']['html_tags']['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['global_settings']['performance'] = [
'#type' => 'details',
'#title' => $this
->t('Performance'),
'#open' => TRUE,
];
$form['global_settings']['performance']['clear_caches_on_modal_save'] = [
'#title' => $this
->t("Clear caches when save Modal"),
'#type' => 'checkbox',
'#default_value' => $config
->get('clear_caches_on_modal_save'),
];
$form['actions'] = [
'#type' => 'actions',
];
$form['actions']['submit'] = [
'#type' => 'submit',
'#value' => $this
->t('Submit'),
];
return $form;
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$loadBootstrap = $form_state
->getValue('load_bootstrap');
$verifyLoadBootstrapAutomatically = $form_state
->getValue('verify_load_bootstrap_automatically');
$config = $this
->config('modal_page.settings');
$config
->set('load_bootstrap', $loadBootstrap);
$config
->set('verify_load_bootstrap_automatically', $verifyLoadBootstrapAutomatically);
$config
->set('allowed_tags', $form_state
->getValue('allowed_tags'));
$config
->set('clear_caches_on_modal_save', $form_state
->getValue('clear_caches_on_modal_save'));
$config
->save();
if (!empty($config
->get('clear_caches_on_modal_save'))) {
PhpStorageFactory::get('twig')
->deleteAll();
}
parent::submitForm($form, $form_state);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ConfigFormBase:: |
public | function | Constructs a \Drupal\system\ConfigFormBase object. | 16 |
ConfigFormBaseTrait:: |
protected | function | Retrieves a configuration object. | |
DependencySerializationTrait:: |
protected | property | ||
DependencySerializationTrait:: |
protected | property | ||
DependencySerializationTrait:: |
public | function | 2 | |
DependencySerializationTrait:: |
public | function | 2 | |
FormBase:: |
protected | property | The config factory. | 3 |
FormBase:: |
protected | property | The request stack. | 1 |
FormBase:: |
protected | property | The route match. | |
FormBase:: |
protected | function | Gets the config factory for this form. | 3 |
FormBase:: |
private | function | Returns the service container. | |
FormBase:: |
protected | function | Gets the current user. | |
FormBase:: |
protected | function | Gets the request object. | |
FormBase:: |
protected | function | Gets the route match. | |
FormBase:: |
protected | function | Gets the logger for a specific channel. | |
FormBase:: |
protected | function | Returns a redirect response object for the specified route. | |
FormBase:: |
public | function | Resets the configuration factory. | |
FormBase:: |
public | function | Sets the config factory for this form. | |
FormBase:: |
public | function | Sets the request stack object to use. | |
FormBase:: |
public | function |
Form validation handler. Overrides FormInterface:: |
72 |
LoggerChannelTrait:: |
protected | property | The logger channel factory service. | |
LoggerChannelTrait:: |
protected | function | Gets the logger for a specific channel. | |
LoggerChannelTrait:: |
public | function | Injects the logger channel factory. | |
MessengerTrait:: |
protected | property | The messenger. | 27 |
MessengerTrait:: |
public | function | Gets the messenger. | 27 |
MessengerTrait:: |
public | function | Sets the messenger. | |
ModalPageSettersTraitHelper:: |
protected | property | The language manager. | |
ModalPageSettersTraitHelper:: |
protected | property | Module handler. | |
ModalPageSettersTraitHelper:: |
public | function | Set Language Manager. | |
ModalPageSettersTraitHelper:: |
public | function | Set Module Handler. | |
ModalPageSettingsForm:: |
public | function |
Form constructor. Overrides ConfigFormBase:: |
|
ModalPageSettingsForm:: |
public static | function |
Instantiates a new instance of this class. Overrides ConfigFormBase:: |
|
ModalPageSettingsForm:: |
protected | function |
Gets the configuration names that will be editable. Overrides ConfigFormBaseTrait:: |
|
ModalPageSettingsForm:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
ModalPageSettingsForm:: |
public | function | Set Message info. | |
ModalPageSettingsForm:: |
public | function |
Form submission handler. Overrides ConfigFormBase:: |
|
RedirectDestinationTrait:: |
protected | property | The redirect destination service. | 1 |
RedirectDestinationTrait:: |
protected | function | Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url. | |
RedirectDestinationTrait:: |
protected | function | Returns the redirect destination service. | |
RedirectDestinationTrait:: |
public | function | Sets the redirect destination service. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 4 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |