class BootstrapLibrarySettingsForm in Bootstrap Library 8
Configure bootstrap_library settings for this site.
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_library\BootstrapLibrarySettingsForm
- class \Drupal\Core\Form\ConfigFormBase uses ConfigFormBaseTrait
Expanded class hierarchy of BootstrapLibrarySettingsForm
1 string reference to 'BootstrapLibrarySettingsForm'
File
- src/
BootstrapLibrarySettingsForm.php, line 17 - Contains \Drupal\bootstrap_library\BootstrapLibrarySettingsForm
Namespace
Drupal\bootstrap_libraryView source
class BootstrapLibrarySettingsForm extends ConfigFormBase {
public function getFormId() {
return 'bootstrap_library_admin_settings';
}
/**
* {@inheritdoc}
*/
protected function getEditableConfigNames() {
return [
'bootstrap_library.settings',
];
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this
->config('bootstrap_library.settings');
$themes = \Drupal::service('theme_handler')
->listInfo();
$active_themes = array();
foreach ($themes as $key => $theme) {
if ($theme->status) {
$active_themes[$key] = $theme->info['name'];
}
}
// Load from CDN
$form['cdn'] = array(
'#type' => 'fieldset',
'#title' => t('Load Boostrap from CDN'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$data = _bootstrap_library_data();
$cdn_options = json_decode($data);
$versions = array_keys(_bootstrap_library_object_to_array($cdn_options->bootstrap));
$options = array_combine($versions, $versions);
array_unshift($options, 'Load locally');
$form['cdn']['bootstrap'] = array(
'#type' => 'select',
'#title' => t('Select Bootstrap version to load via CDN, non for local library'),
'#options' => $options,
'#default_value' => $config
->get('cdn.bootstrap'),
);
$form['cdn']['cdn_options'] = array(
'#type' => 'hidden',
'#value' => $data,
);
// Production or minimized version
$form['minimized'] = array(
'#type' => 'fieldset',
'#title' => t('Minimized, Non-minimized, or Composer version'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
);
$form['minimized']['minimized_options'] = array(
'#type' => 'radios',
'#title' => t('Choose minimized, non-minimized, or composer version.'),
'#options' => array(
0 => t('Use non minimized libraries (Development)'),
1 => t('Use minimized libraries (Production)'),
2 => t('Use composer installed libraries'),
),
'#default_value' => $config
->get('minimized.options'),
);
// Per-theme visibility.
$form['theme'] = array(
'#type' => 'fieldset',
'#title' => t('Themes Visibility'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
);
$form['theme']['theme_visibility'] = array(
'#type' => 'radios',
'#title' => t('Activate on specific themes'),
'#options' => array(
0 => t('All themes except those listed'),
1 => t('Only the listed themes'),
),
'#default_value' => $config
->get('theme.visibility'),
);
$form['theme']['theme_themes'] = array(
'#type' => 'select',
'#title' => 'List of themes where library will be loaded.',
'#options' => $active_themes,
'#multiple' => TRUE,
'#default_value' => $config
->get('theme.themes'),
'#description' => t("Specify in which themes you wish the library to load."),
);
// Per-path visibility.
$form['url'] = array(
'#type' => 'fieldset',
'#title' => t('Activate on specific URLs'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$form['url']['url_visibility'] = array(
'#type' => 'radios',
'#title' => t('Load bootstrap on specific pages'),
'#options' => array(
0 => t('All pages except those listed'),
1 => t('Only the listed pages'),
),
'#default_value' => $config
->get('url.visibility'),
);
$form['url']['url_pages'] = array(
'#type' => 'textarea',
'#title' => '<span class="element-invisible">' . t('Pages') . '</span>',
'#default_value' => _bootstrap_library_array_to_string($config
->get('url.pages')),
'#description' => t("Specify pages by using their paths. Enter one path per line. The '*' character is a wildcard. Example paths are %blog for the blog page and %blog-wildcard for every personal blog. %front is the front page.", array(
'%blog' => 'blog',
'%blog-wildcard' => 'blog/*',
'%front' => '<front>',
)),
);
// Files settings.
$form['files'] = array(
'#type' => 'fieldset',
'#title' => t('Files Settings'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$form['files']['types'] = array(
'#type' => 'checkboxes',
'#title' => t('Select which files to load from the library. By default you should check both, but in some cases you will need to load only CSS or JS Bootstrap files.'),
'#options' => array(
'css' => t('CSS files'),
'js' => t('Javascript files'),
),
'#default_value' => $config
->get('files.types'),
);
return parent::buildForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$this
->config('bootstrap_library.settings')
->set('theme.visibility', $form_state
->getValue('theme_visibility'))
->set('theme.themes', $form_state
->getValue('theme_themes'))
->set('url.visibility', $form_state
->getValue('url_visibility'))
->set('url.pages', _bootstrap_library_string_to_array($form_state
->getValue('url_pages')))
->set('minimized.options', $form_state
->getValue('minimized_options'))
->set('cdn.bootstrap', $form_state
->getValue('bootstrap'))
->set('cdn.options', $form_state
->getValue('cdn_options'))
->set('files.types', $form_state
->getValue('types'))
->save();
parent::submitForm($form, $form_state);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
BootstrapLibrarySettingsForm:: |
public | function |
Form constructor. Overrides ConfigFormBase:: |
|
BootstrapLibrarySettingsForm:: |
protected | function |
Gets the configuration names that will be editable. Overrides ConfigFormBaseTrait:: |
|
BootstrapLibrarySettingsForm:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
BootstrapLibrarySettingsForm:: |
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. |