public function AjaxLoaderSettingsForm::buildForm in Ajax loader 8
Form constructor.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Return value
array The form structure.
Overrides ConfigFormBase::buildForm
File
- src/
Form/ AjaxLoaderSettingsForm.php, line 61
Class
- AjaxLoaderSettingsForm
- Class AjaxLoaderSettingsForm.
Namespace
Drupal\ajax_loader\FormCode
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);
}