Skip to content

Instantly share code, notes, and snippets.

@cyberlex404
Created March 24, 2018 12:10
Show Gist options
  • Save cyberlex404/dddf3fda1b2941acb825fec65dd27f28 to your computer and use it in GitHub Desktop.
Save cyberlex404/dddf3fda1b2941acb825fec65dd27f28 to your computer and use it in GitHub Desktop.
<?php
/**
* Created by PhpStorm.
* User: Lex
* Date: 20.02.2018
* Time: 15:32
*/
namespace Drupal\ifmo\Plugin\views\style;
use Drupal\core\form\FormStateInterface;
use Drupal\views\Plugin\views\style\DefaultStyle;
use Drupal\views\Plugin\views\style\StylePluginBase;
/**
* Style plugin to render a list of years and months
* in reverse chronological order linked to content.
*
* @ingroup views_style_plugins
*
* @ViewsStyle(
* id = "ifmo_swiper",
* title = @Translation("Swiper"),
* help = @Translation("Render a swiper slider."),
* theme = "views_view_swiper",
* display_types = { "normal" }
* )
*/
class Swiper extends DefaultStyle {
/**
* @inheritDoc
*/
protected function defineOptions() {
$options = parent::defineOptions();
$options['swiper_name'] = ['default' => 'swiper-default'];
$options['library'] = ['default'=> 'ifmo/swiper-views'];
$options['swiper'] = ['default' => [
'overflow' => FALSE,
'pagination' => FALSE,
'scrollbar' => FALSE,
'navigation' => FALSE,
'slides_per_view' => 1,
]];
return $options;
}
/**
* @inheritDoc
*/
public function buildOptionsForm(&$form, FormStateInterface $form_state) {
parent::buildOptionsForm($form, $form_state);
// Extra CSS classes.
$form['swiper_name'] = [
'#type' => 'textfield',
'#title' => t('CSS classes'),
'#default_value' => (isset($this->options['swiper_name'])) ? $this->options['swiper_name'] : 'view-swip',
'#description' => t('CSS classes for customization slider.'),
];
$form['library'] = [
'#type' => 'textfield',
'#title' => t('Library'),
'#default_value' => (isset($this->options['library'])) ? $this->options['library'] : 'ifmo/swiper-views',
'#description' => t('Attach library.'),
];
$form['swiper'] = [
'#type' => 'fieldset',
'#tree' => TRUE,
'#title' => $this->t('Swiper settings')
];
$form['swiper']['overflow'] = [
'#type' => 'checkbox',
'#title' => 'Overflow',
'#default_value' => (isset($this->options['swiper']['overflow'])) ? $this->options['swiper']['overflow'] : FALSE,
];
$form['swiper']['pagination'] = [
'#type' => 'checkbox',
'#title' => 'Pagination',
'#default_value' => (isset($this->options['swiper']['pagination'])) ? $this->options['swiper']['pagination'] : FALSE,
];
$form['swiper']['scrollbar'] = [
'#type' => 'checkbox',
'#title' => 'Scrollbar',
'#default_value' => (isset($this->options['swiper']['scrollbar'])) ? $this->options['swiper']['scrollbar'] : FALSE,
];
$form['swiper']['navigation'] = [
'#type' => 'checkbox',
'#title' => 'Navigation',
'#default_value' => (isset($this->options['swiper']['navigation'])) ? $this->options['swiper']['navigation'] : FALSE,
];
$form['swiper']['slides_per_view'] = [
'#type' => 'number',
'#title' => $this->t('Slides per view'),
'#min' => 1,
'#step' => 1,
'#default_value' => (isset($this->options['swiper']['slides_per_view'])) ? $this->options['swiper']['slides_per_view'] : 1,
];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment