class AjaxLoaderSettingsForm in Ajax loader 8
Class AjaxLoaderSettingsForm.
@package Drupal\ajax_throbber\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\ajax_loader\Form\AjaxLoaderSettingsForm
- class \Drupal\Core\Form\ConfigFormBase uses ConfigFormBaseTrait
Expanded class hierarchy of AjaxLoaderSettingsForm
1 string reference to 'AjaxLoaderSettingsForm'
File
- src/
Form/ AjaxLoaderSettingsForm.php, line 16
Namespace
Drupal\ajax_loader\FormView source
class AjaxLoaderSettingsForm extends ConfigFormBase {
protected $throbberManager;
/**
* Function to construct.
*/
public function __construct(ConfigFactoryInterface $config_factory, ThrobberManagerInterface $throbber_manager) {
parent::__construct($config_factory);
$this->throbberManager = $throbber_manager;
}
/**
* Function to create.
*
* @param \Symfony\Component\DependencyInjection\ContainerInterface $container
* The container value.
*
* @return static
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('config.factory'), $container
->get('ajax_loader.throbber_manager'));
}
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'ajax_throbber_settings_form';
}
/**
* {@inheritdoc}
*/
protected function getEditableConfigNames() {
return [
'ajax_loader.settings',
];
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$settings = $this
->config('ajax_loader.settings');
$form['wrapper'] = [
'#prefix' => '<div id="throbber-wrapper">',
'#suffix' => '</div>',
];
$form['wrapper']['throbber'] = [
'#type' => 'select',
'#title' => t('Throbber'),
'#description' => t('Choose your throbber'),
'#required' => TRUE,
'#options' => $this->throbberManager
->getThrobberOptionList(),
'#default_value' => $settings
->get('throbber'),
'#ajax' => [
'wrapper' => 'throbber-wrapper',
'callback' => [
$this,
'ajaxThrobberChange',
],
],
];
if (!empty($form_state
->getValue('throbber')) || !empty($settings
->get('throbber'))) {
$plugin_id = !empty($form_state
->getValue('throbber')) ? $form_state
->getValue('throbber') : $settings
->get('throbber');
if ($this->throbberManager
->getDefinition($plugin_id, FALSE)) {
// Show preview of throbber.
if (!empty($form_state
->getValue('throbber'))) {
$throbber = $this->throbberManager
->loadThrobberInstance($form_state
->getValue('throbber'));
}
else {
$throbber = $this->throbberManager
->loadThrobberInstance($settings
->get('throbber'));
}
$form['wrapper']['throbber']['#attached']['library'] = [
'ajax_loader/ajax_loader.admin',
];
$form['wrapper']['throbber']['#suffix'] = '<span class="throbber-example">' . $throbber
->getMarkup() . '</span>';
}
}
$form['hide_ajax_message'] = [
'#type' => 'checkbox',
'#title' => t('Never show ajax loading message'),
'#description' => t('Choose whether you want to hide the loading ajax message even when it is set.'),
'#default_value' => $settings
->get('hide_ajax_message') ?: 0,
];
$form['always_fullscreen'] = [
'#type' => 'checkbox',
'#title' => t('Always show loader as overlay (fullscreen)'),
'#description' => t('Choose whether you want to show the loader as an overlay, no matter what the settings of the loader are.'),
'#default_value' => $settings
->get('always_fullscreen') ?: 0,
];
$form['show_admin_paths'] = [
'#type' => 'checkbox',
'#title' => t('Use ajax loader on admin pages'),
'#description' => t('Choose whether you also want to show the loader on admin pages or still like to use the default core loader.'),
'#default_value' => $settings
->get('show_admin_paths') ?: 0,
];
$form['throbber_position'] = [
'#type' => 'textfield',
'#title' => t('Throbber position'),
'#required' => TRUE,
'#description' => t('Allows you to change the position where the throbber is inserted. A valid css selector must be used here. The default value is: body'),
'#default_value' => $settings
->get('throbber_position') ?: 'body',
];
return parent::buildForm($form, $form_state);
}
/**
* Ajax callback when throbber is changed.
*
* @param array $form
* The form array.
* @param array $form_state
* The form state array.
*/
public function ajaxThrobberChange(array $form, array &$form_state) {
return $form['wrapper'];
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$this
->config('ajax_loader.settings')
->set('throbber', $form_state
->getValue('throbber'))
->set('hide_ajax_message', $form_state
->getValue('hide_ajax_message'))
->set('always_fullscreen', $form_state
->getValue('always_fullscreen'))
->set('show_admin_paths', $form_state
->getValue('show_admin_paths'))
->set('throbber_position', $form_state
->getValue('throbber_position'))
->save();
// Clear cache, so that library is picked up.
drupal_flush_all_caches();
parent::submitForm($form, $form_state);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AjaxLoaderSettingsForm:: |
protected | property | ||
AjaxLoaderSettingsForm:: |
public | function | Ajax callback when throbber is changed. | |
AjaxLoaderSettingsForm:: |
public | function |
Form constructor. Overrides ConfigFormBase:: |
|
AjaxLoaderSettingsForm:: |
public static | function |
Function to create. Overrides ConfigFormBase:: |
|
AjaxLoaderSettingsForm:: |
protected | function |
Gets the configuration names that will be editable. Overrides ConfigFormBaseTrait:: |
|
AjaxLoaderSettingsForm:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
AjaxLoaderSettingsForm:: |
public | function |
Form submission handler. Overrides ConfigFormBase:: |
|
AjaxLoaderSettingsForm:: |
public | function |
Function to construct. Overrides ConfigFormBase:: |
|
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. |