class BootstrapModalMessagesAdminForm in Bootstrap Modal Messages 8
Class BootstrapModalMessagesAdminForm.
@package Drupal\bootstrap_modal_messages\Form
Hierarchy
- class \Drupal\Core\Form\FormBase implements ContainerInjectionInterface, FormInterface uses DependencySerializationTrait, LoggerChannelTrait, MessengerTrait, LinkGeneratorTrait, RedirectDestinationTrait, UrlGeneratorTrait, StringTranslationTrait
- class \Drupal\Core\Form\ConfigFormBase uses ConfigFormBaseTrait
- class \Drupal\bootstrap_modal_messages\Form\BootstrapModalMessagesAdminForm
- class \Drupal\Core\Form\ConfigFormBase uses ConfigFormBaseTrait
Expanded class hierarchy of BootstrapModalMessagesAdminForm
1 string reference to 'BootstrapModalMessagesAdminForm'
File
- src/
Form/ BootstrapModalMessagesAdminForm.php, line 13
Namespace
Drupal\bootstrap_modal_messages\FormView 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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
BootstrapModalMessagesAdminForm:: |
public | function |
Form constructor. Overrides ConfigFormBase:: |
|
BootstrapModalMessagesAdminForm:: |
protected | function |
Gets the configuration names that will be editable. Overrides ConfigFormBaseTrait:: |
|
BootstrapModalMessagesAdminForm:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
BootstrapModalMessagesAdminForm:: |
public | function |
Form submission handler. Overrides ConfigFormBase:: |
|
ConfigFormBase:: |
public static | function |
Instantiates a new instance of this class. Overrides FormBase:: |
13 |
ConfigFormBase:: |
public | function | Constructs a \Drupal\system\ConfigFormBase object. | 11 |
ConfigFormBaseTrait:: |
protected | function | Retrieves a configuration object. | |
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
FormBase:: |
protected | property | The config factory. | 1 |
FormBase:: |
protected | property | The request stack. | 1 |
FormBase:: |
protected | property | The route match. | |
FormBase:: |
protected | function | Gets the config factory for this form. | 1 |
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. Overrides UrlGeneratorTrait:: |
|
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:: |
62 |
LinkGeneratorTrait:: |
protected | property | The link generator. | 1 |
LinkGeneratorTrait:: |
protected | function | Returns the link generator. | |
LinkGeneratorTrait:: |
protected | function | Renders a link to a route given a route name and its parameters. | |
LinkGeneratorTrait:: |
public | function | Sets the link generator service. | |
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. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
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. | 1 |
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. | |
UrlGeneratorTrait:: |
protected | property | The url generator. | |
UrlGeneratorTrait:: |
protected | function | Returns the URL generator service. | |
UrlGeneratorTrait:: |
public | function | Sets the URL generator service. | |
UrlGeneratorTrait:: |
protected | function | Generates a URL or path for a specific route based on the given parameters. |