class SlickSettingsForm in Slick Carousel 8.2
Same name and namespace in other branches
- 8 slick_ui/src/Form/SlickSettingsForm.php \Drupal\slick_ui\Form\SlickSettingsForm
- 7.3 slick_ui/src/Form/SlickSettingsForm.php \Drupal\slick_ui\Form\SlickSettingsForm
Defines the Slick admin settings 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\slick_ui\Form\SlickSettingsForm
- class \Drupal\Core\Form\ConfigFormBase uses ConfigFormBaseTrait
Expanded class hierarchy of SlickSettingsForm
1 file declares its use of SlickSettingsForm
- SlickSettingsFormTest.php in tests/
src/ Kernel/ Form/ SlickSettingsFormTest.php
1 string reference to 'SlickSettingsForm'
- slick_ui.routing.yml in slick_ui/
slick_ui.routing.yml - slick_ui/slick_ui.routing.yml
File
- slick_ui/
src/ Form/ SlickSettingsForm.php, line 12
Namespace
Drupal\slick_ui\FormView source
class SlickSettingsForm extends ConfigFormBase {
/**
* Drupal\Core\Asset\LibraryDiscoveryInterface definition.
*
* @var Drupal\Core\Asset\LibraryDiscoveryInterface
*/
protected $libraryDiscovery;
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
/**
* @var \Drupal\slick_ui\Form\SlickSettingsForm
*/
$instance = parent::create($container);
$instance->libraryDiscovery = $container
->get('library.discovery');
return $instance;
}
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'slick_settings_form';
}
/**
* {@inheritdoc}
*/
protected function getEditableConfigNames() {
return [
'slick.settings',
];
}
/**
* Implements \Drupal\Core\Form\FormInterface::buildForm().
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this
->config('slick.settings');
$form['library'] = [
'#type' => 'select',
'#title' => $this
->t('Library to use'),
'#description' => $this
->t('<a href=":url1">Slick</a> is the original library by Ken Wheeler. <a href=":url2">Accessible Slick</a> is a forked library with accessibility enhancements from Accessibility360. Be sure to clear cache if things broken when changing this. <b>Warning</b>! Accessible Slick has breaking changes, <a href=":url3">read more</a>.', [
':url1' => 'https://kenwheeler.github.io/slick/',
':url2' => 'https://accessible360.github.io/accessible-slick/',
':url3' => 'https://www.drupal.org/project/slick/issues/3196529',
]),
'#options' => [
'slick' => $this
->t('Slick'),
'accessible-slick' => $this
->t('Accessible Slick'),
],
'#default_value' => $config
->get('library'),
];
$form['module_css'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Enable Slick module slick.theme.css'),
'#description' => $this
->t('Uncheck to permanently disable the module slick.theme.css, normally included along with skins.'),
'#default_value' => $config
->get('module_css'),
'#prefix' => $this
->t("Note! Slick doesn't need Slick UI to run. It is always safe to uninstall Slick UI once done with optionsets."),
];
$form['slick_css'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Enable Slick library slick-theme.css'),
'#description' => $this
->t('Uncheck to permanently disable the optional slick-theme.css, normally included along with skins.'),
'#default_value' => $config
->get('slick_css'),
];
$form['disable_old_skins'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Disable deprecated skins'),
'#description' => $this
->t('Deprecated skins are registered via the <a href=":url">to-be-deprecated hook_hook_info</a>. Now Slick uses plugin system to store its skins. Leave it unchecked if things are broken, or (y/our) sub-modules are not updated with the new plugin system, yet. If you are sure things are not broken, or never register a skin nor using Slick examples, you can check this to reduce extra join. At any rate, skins are permanently cached once, so should not impact much.', [
':url' => 'https://www.drupal.org/node/2233261',
]),
'#default_value' => $config
->get('disable_old_skins'),
];
$form['sitewide'] = [
'#type' => 'select',
'#title' => $this
->t('Load slick globally'),
'#empty_option' => $this
->t('- None -'),
'#options' => [
1 => $this
->t('With default initializer'),
2 => $this
->t('With vanilla initializer'),
3 => $this
->t('Without initializer'),
],
'#description' => $this
->t('Warning! Not compatible with BigPipe module due to assets re-ordering issue, see https://drupal.org/node/3211873. Meaning may break any stylings provided by this module.<ol><li><b>With default initializer</b> will include the module slick.load.min.js as the initializer normally used by the module formatters or views identified by <code>.slick</code> selector. Only if you need consistent styling/ skins, classes, media player, lightboxes, and markups. Works immediately at body texts.</li><li><b>With vanilla initializer</b> will include the module slick.vanilla.min.js as the minimal initializer identified by <code>.slick-vanilla</code> selector. Default skins, media player, lightboxes are unusable. Be sure to add CSS class <code>.slick-vanilla</code> to your Slick. Recommended to not interfere or co-exist with module formatters/ views. Works immediately at body texts.</li><li><b>Without initializer</b> will load only the main libraries. No module skins, no module JS. It is all yours -- broken unless you initialize it.</li></ol> This will include Slick anywhere except admin pages. Only do this if you need Slick where PHP or Twig is not available such as at body texts. Otherwise use the provided API instead. Implements <code>hook_slick_attach_alter</code> to include additional libraries such as skins, mousewheel, colorbox, etc. At any rate, you can inject options via <code>data-slick</code> attribute, or custom JavaScript. You can also include them at your theme, it is just a convenient way to avoid hard-coding at every theme changes. Check out slick.html.twig for more markups.'),
'#default_value' => $config
->get('sitewide'),
];
$default = $config
->get('sitewide') == 0 || $config
->get('sitewide') == 1;
$form['preview'] = $default ? $this
->withInitializer() : $this
->withoutInitializer();
return parent::buildForm($form, $form_state);
}
/**
* Implements \Drupal\Core\Form\FormInterface::submitForm().
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$this->configFactory
->getEditable('slick.settings')
->set('library', $form_state
->getValue('library'))
->set('slick_css', $form_state
->getValue('slick_css'))
->set('module_css', $form_state
->getValue('module_css'))
->set('disable_old_skins', $form_state
->getValue('disable_old_skins'))
->set('sitewide', (int) $form_state
->getValue('sitewide'))
->save();
// Invalidate the library discovery cache to update new assets.
$this->libraryDiscovery
->clearCachedDefinitions();
$this->configFactory
->clearStaticCache();
parent::submitForm($form, $form_state);
}
/**
* Provides sample with default Slick markups.
*/
private function withInitializer() {
$items = [];
foreach ([
'One',
'Two',
'Three',
] as $key) {
$img = '<img src="https://drupal.org/files/' . $key . '.gif" />';
$items[] = [
'slide' => [
'#markup' => $img,
],
'caption' => [
'title' => $key,
],
];
}
$build = [
'items' => $items,
'settings' => [
'skin' => 'classic',
'layout' => 'bottom',
],
'options' => [
'arrows' => TRUE,
'dots' => TRUE,
],
];
$content = \slick()
->build($build);
return $this
->preview($content);
}
/**
* Provides sample without default Slick markups.
*/
private function withoutInitializer() {
$config = $this
->config('slick.settings');
$vanilla = $config
->get('sitewide') == 2;
$items = [];
foreach ([
'One',
'Two',
'Three',
] as $key) {
$items[] = [
'#type' => 'html_tag',
'#tag' => 'div',
'#value' => '<img src="https://drupal.org/files/' . $key . '.gif" />',
];
}
$class = $vanilla ? 'vanilla' : 'whatever';
$config = "{'arrows': true, 'dots': true}";
$prefix = 'class="slick-' . $class . '" data-slick="' . $config . '"';
$suffix = "<blockquote><pre><div class="slick-" . $class . "" data-slick="{'arrows': true, 'dots': true}">\n <div><img src="https://drupal.org/files/One.gif" /></div>\n <div><img src="https://drupal.org/files/Two.gif" /></div>\n <div><img src="https://drupal.org/files/Three.gif" /></div>\n</div></pre></blockquote>";
return $this
->preview($items, $prefix, $suffix);
}
/**
* Provides sample w/o default Slick markups.
*/
private function preview($content, $prefix = '', $suffix = '') {
$config = $this
->config('slick.settings');
$unload = $config
->get('sitewide') == 2 || $config
->get('sitewide') == 3;
$attach = \slick()
->attach([
'_unload' => $unload,
'_vanilla' => $config
->get('sitewide') == 2,
]);
if (empty($suffix)) {
$suffix = "<blockquote><pre><div class="slick" data-slick="{'arrows': true, 'dots': true}">\n <div class="slick__slider">\n <div class="slick__slide"><img src="https://drupal.org/files/One.gif" /></div>\n <div class="slick__slide"><img src="https://drupal.org/files/Two.gif" /></div>\n <div class="slick__slide"><img src="https://drupal.org/files/Three.gif" /></div>\n </div>\n <nav class="slick__arrow" > </nav>\n</div></pre></blockquote>";
}
return [
'#type' => 'inline_template',
'#template' => '{{ prefix | raw }}{{ stage }}{{ suffix | raw }}',
'#context' => [
'stage' => $content,
'prefix' => '<div style="background: rgb(52, 152, 219);"><div style="margin: 30px auto; max-width: 350px; min-height: 240px; text-align: center;" ' . $prefix . '>',
'suffix' => '</div></div>' . $suffix,
],
'#attached' => $attach,
];
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
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. | |
SlickSettingsForm:: |
protected | property | Drupal\Core\Asset\LibraryDiscoveryInterface definition. | |
SlickSettingsForm:: |
public | function |
Implements \Drupal\Core\Form\FormInterface::buildForm(). Overrides ConfigFormBase:: |
|
SlickSettingsForm:: |
public static | function |
Instantiates a new instance of this class. Overrides ConfigFormBase:: |
|
SlickSettingsForm:: |
protected | function |
Gets the configuration names that will be editable. Overrides ConfigFormBaseTrait:: |
|
SlickSettingsForm:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
SlickSettingsForm:: |
private | function | Provides sample w/o default Slick markups. | |
SlickSettingsForm:: |
public | function |
Implements \Drupal\Core\Form\FormInterface::submitForm(). Overrides ConfigFormBase:: |
|
SlickSettingsForm:: |
private | function | Provides sample with default Slick markups. | |
SlickSettingsForm:: |
private | function | Provides sample without default Slick markups. | |
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. |