JqueryCarousel.php in jQuery carousel 8
File
src/Plugin/views/style/JqueryCarousel.php
View source
<?php
namespace Drupal\jquery_carousel\Plugin\views\style;
use Drupal\Core\Form\FormStateInterface;
use Drupal\views\Plugin\views\style\StylePluginBase;
class JqueryCarousel extends StylePluginBase {
protected $usesRowPlugin = TRUE;
protected $usesRowClass = TRUE;
protected $usesGrouping = FALSE;
public function buildOptionsForm(&$form, FormStateInterface $form_state) {
parent::buildOptionsForm($form, $form_state);
$carousel_config_form = jquery_carousel_config_form();
$form = array_merge($form, $carousel_config_form);
foreach (array_keys($form) as $key) {
if (isset($form[$key]) && is_array($form[$key]) && isset($this->options[$key])) {
$form[$key]['#default_value'] = $this->options[$key];
}
}
}
public function validateOptionsForm(&$form, FormStateInterface $form_state) {
$selector = $form_state
->getValue([
'style_options',
'selector',
]);
$error = _jquery_carousel_config_validate($selector);
if ($error) {
$form_state
->setErrorByName('selector', t("Selector should not contain any special characters or spaces. Only special character allowed is '-'"));
}
}
protected function defineOptions() {
$options = parent::defineOptions();
$options['selector'] = [
'default' => 'rs-carousel',
];
return $options;
}
}