View source
<?php
namespace Drupal\amp\Plugin\views\style;
use Drupal\views\Plugin\views\style\StylePluginBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\amp\AmpFormTrait;
class AmpViewsCarouselStyle extends StylePluginBase {
use AmpFormTrait;
protected $usesRowPlugin = TRUE;
protected $usesRowClass = FALSE;
protected $usesGrouping = FALSE;
protected $usesFields = TRUE;
public function getSetting($setting) {
return $this->options[$setting];
}
private function getLayouts() {
$options = $this
->allLayouts();
unset($options['container']);
unset($options['intrinsic']);
return $options;
}
public function getLibraries() {
return [
'amp/amp.carousel',
];
}
protected function defineOptions() {
$options = parent::defineOptions();
$options['wrapper_class'] = [
'default' => '',
];
$options['type'] = array(
'default' => 'slides',
);
$options['layout'] = array(
'default' => 'responsive',
);
$options['width'] = array(
'default' => '',
);
$options['height'] = array(
'default' => '',
);
$options['autoplay'] = array(
'default' => FALSE,
);
$options['controls'] = array(
'default' => FALSE,
);
$options['loop'] = array(
'default' => FALSE,
);
return $options;
}
public function buildOptionsForm(&$form, FormStateInterface $form_state) {
parent::buildOptionsForm($form, $form_state);
$form['wrapper_class'] = [
'#title' => $this
->t('Wrapper class'),
'#description' => $this
->t('The class to provide on the wrapper, outside the carousel.'),
'#type' => 'textfield',
'#size' => '30',
'#default_value' => $this->options['wrapper_class'],
];
$form['type'] = [
'#type' => 'select',
'#title' => t('Carousel type'),
'#default_value' => $this
->getSetting('type'),
'#options' => [
'carousel' => 'carousel',
'slides' => 'slides',
],
];
$form['layout'] = $this
->layoutElement();
$form['layout']['#description'] .= ' ' . $this
->t('The "carousel" type only supports the fixed, fixed-height, and nodisplay layouts. The "slides" type supports the fill, fixed, fixed-height, flex-item, nodisplay, and responsive layouts.');
$form['width'] = $this
->widthElement();
$form['height'] = $this
->heightElement();
$form['autoplay'] = $this
->autoplayElement();
$form['controls'] = $this
->controlsElement();
$form['loop'] = $this
->loopElement();
$form['#prefix'] = '<div class="description">' . $this
->libraryDescription() . '</div>';
}
}