Skip to content
Snippets Groups Projects
Commit 53abfa22 authored by Cedric Hillion's avatar Cedric Hillion Committed by Nicolas Borda
Browse files

Issue #3367454 by cedrichillion, bohemier, ipwa, endrukk: Add SlideBy option

parent 2651b966
No related branches found
No related tags found
1 merge request!9Adds validation for the new 'slideBy' option.
......@@ -323,6 +323,17 @@ class TinySliderFieldFormatter extends EntityReferenceFormatterBase implements C
],
];
// Slide by.
$element['slideBy'] = [
'#type' => 'textfield',
'#title' => $this->t('Slide by'),
'#default_value' => $this->getSetting('slideBy'),
'#description' => $this->t('Number of slides going on one "click". Enter a positive number or "page" to slide one page at a time.'),
'#element_validate' => [
[$this, 'settingsFormSlideByValidate'],
],
];
// arrowKeys.
$element['arrowKeys'] = [
'#type' => 'checkbox',
......@@ -420,6 +431,7 @@ class TinySliderFieldFormatter extends EntityReferenceFormatterBase implements C
$controlsplayposition = $this->getSetting('controlsPosition') ? $this->getSetting('controlsPosition') : 'top';
$controlstextprev = $this->getSetting('controlsTextPrev') ? $this->getSetting('controlsTextPrev') : 'prev';
$controlstextnext = $this->getSetting('controlsTextNext') ? $this->getSetting('controlsTextNext') : 'next';
$slideby = $this->getSetting('slideBy') ? $this->getSetting('slideBy') : 'page';
$arrowkeys = $this->getSetting('arrowKeys') ? 'TRUE' : 'FALSE';
$mousedrag = $this->getSetting('mouseDrag') ? 'TRUE' : 'FALSE';
$loop = $this->getSetting('loop') ? 'TRUE' : 'FALSE';
......@@ -442,6 +454,7 @@ class TinySliderFieldFormatter extends EntityReferenceFormatterBase implements C
$summary[] = $this->t('Show controls: ') . $controls;
$summary[] = $this->t('Prev text: ') . $controlstextprev;
$summary[] = $this->t('Next text: ') . $controlstextnext;
$summary[] = $this->t('Slide by: ') . $slideby;
$summary[] = $this->t('Arrow keys: ') . $arrowkeys;
$summary[] = $this->t('Mouse drag: ') . $mousedrag;
$summary[] = $this->t('Loop: ') . $loop;
......@@ -467,6 +480,14 @@ class TinySliderFieldFormatter extends EntityReferenceFormatterBase implements C
return $summary;
}
public function settingsFormSlideByValidate($element, FormStateInterface $form_state)
{
$submitted_value = $form_state->getValue($element['#parents']);
if (!preg_match('~[0-9]+~', $submitted_value) && ($submitted_value !== 'page')) {
$form_state->setError($element, $this->t('@value is not right. The "Slide by" value should either be an Integer or equal to the term "page".', ['@value' => $submitted_value]));
}
}
/**
* {@inheritdoc}
*/
......
......@@ -219,6 +219,13 @@ class TinySlider extends StylePluginBase {
],
],
];
// Slide by.
$form['slideBy'] = [
'#type' => 'textfield',
'#title' => $this->t('Slide by'),
'#default_value' => $this->options['slideBy'],
'#description' => $this->t('Number of slides going on one "click". Enter a positive number or "page" to slide one page at a time.'),
];
// arrowKeys.
$form['arrowKeys'] = [
'#type' => 'checkbox',
......@@ -286,4 +293,11 @@ class TinySlider extends StylePluginBase {
];
}
public function validateOptionsForm(&$form, FormStateInterface $form_state) {
parent::validateOptionsForm($form, $form_state);
$styleOptions = $form_state->getValue('style_options')['slideBy'];
if (!preg_match('~[0-9]+~', $styleOptions) && ($styleOptions !== 'page')) {
$form_state->setError($form['slideBy'], $this->t('@value is not right. The "Slide by" value should either be an Integer or equal to the term "page".', ['@value' => $styleOptions]));
}
}
}
......@@ -15,6 +15,7 @@ class TinySliderGlobal {
'image_style' => '',
'image_link' => '',
'items' => 1,
'slideBy' => 'page',
'gutter' => '0',
'nav' => TRUE,
'navPosition' => 'top',
......@@ -48,6 +49,7 @@ class TinySliderGlobal {
*/
public static function formatSettings($settings) {
$settings['items'] = (int) $settings['items'];
$settings['slideBy'] = (string) $settings['slideBy'];
$settings['gutter'] = (int) $settings['gutter'];
$settings['nav'] = (bool) $settings['nav'];
......
......@@ -129,9 +129,10 @@ function _tiny_slider_default_settings($key = NULL) {
'autoplayHoverPause' => FALSE,
'autoplayPosition' => 'top',
'controls' => TRUE,
'controlsPosition' => 'top',
'controlsTextPrev' => 'prev',
'controlsTextNext' => 'next',
'controlsPosition' => 'top',
'slideBy' => '1',
'arrowKeys' => FALSE,
'mouseDrag' => FALSE,
'loop' => TRUE,
......@@ -166,6 +167,7 @@ function _tiny_slider_format_settings($settings) {
(string) $settings['controlsTextPrev'],
(string) $settings['controlsTextNext'],
];
$settings['slideBy'] = (string) $settings['slideBy'];
$settings['arrowKeys'] = (bool) $settings['arrowKeys'];
$settings['mouseDrag'] = (bool) $settings['mouseDrag'];
$settings['loop'] = (bool) $settings['loop'];
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment