class BxsliderThs in BxSlider 8
BxSlider thumbnail pager.
Plugin annotation
@FieldFormatter(
id = "bxslider_ths",
label = @Translation("BxSlider - Thumbnail slider"),
field_types = {"image", "media"}
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
- class \Drupal\Core\Field\PluginSettingsBase implements DependentPluginInterface, PluginSettingsInterface
- class \Drupal\Core\Field\FormatterBase implements FormatterInterface, ContainerFactoryPluginInterface
- class \Drupal\Core\Field\Plugin\Field\FieldFormatter\EntityReferenceFormatterBase
- class \Drupal\file\Plugin\Field\FieldFormatter\FileFormatterBase
- class \Drupal\image\Plugin\Field\FieldFormatter\ImageFormatterBase
- class \Drupal\bxslider\Plugin\Field\FieldFormatter\Bxslider implements ContainerFactoryPluginInterface
- class \Drupal\bxslider\Plugin\Field\FieldFormatter\BxsliderThs implements ContainerFactoryPluginInterface
- class \Drupal\bxslider\Plugin\Field\FieldFormatter\Bxslider implements ContainerFactoryPluginInterface
- class \Drupal\image\Plugin\Field\FieldFormatter\ImageFormatterBase
- class \Drupal\file\Plugin\Field\FieldFormatter\FileFormatterBase
- class \Drupal\Core\Field\Plugin\Field\FieldFormatter\EntityReferenceFormatterBase
- class \Drupal\Core\Field\FormatterBase implements FormatterInterface, ContainerFactoryPluginInterface
- class \Drupal\Core\Field\PluginSettingsBase implements DependentPluginInterface, PluginSettingsInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of BxsliderThs
File
- src/
Plugin/ Field/ FieldFormatter/ BxsliderThs.php, line 19
Namespace
Drupal\bxslider\Plugin\Field\FieldFormatterView source
class BxsliderThs extends Bxslider implements ContainerFactoryPluginInterface {
/**
* {@inheritdoc}
*/
public static function defaultSettings() {
$bxslider_settings = parent::defaultSettings();
$bxslider_settings['slider']['pager']['pager'] = FALSE;
return [
'thumbnail_slider' => [
'thumbnail_style' => 'thumbnail',
'general' => [
'mode' => 'horizontal',
'speed' => 500,
'slideMargin' => 0,
'startSlide' => 0,
'randomStart' => FALSE,
'infiniteLoop' => FALSE,
'hideControlOnEnd' => TRUE,
'easing' => '',
'captions' => FALSE,
'ticker' => FALSE,
'tickerHover' => FALSE,
'adaptiveHeight' => FALSE,
'adaptiveHeightSpeed' => 500,
'video' => FALSE,
'responsive' => TRUE,
'useCSS' => TRUE,
'preloadImages' => 'visible',
'touchEnabled' => TRUE,
'swipeThreshold' => 50,
'oneToOneTouch' => TRUE,
'preventDefaultSwipeX' => TRUE,
'preventDefaultSwipeY' => FALSE,
'wrapperClass' => 'bx-wrapper',
],
'pager' => [
'pager' => FALSE,
'pagerType' => 'full',
'pagerShortSeparator' => ' / ',
'pagerSelector' => '',
],
'controls' => [
'controls' => TRUE,
'nextText' => 'Next',
'prevText' => 'Prev',
'nextSelector' => '',
'prevSelector' => '',
'autoControls' => FALSE,
'startText' => 'Start',
'stopText' => 'Stop',
'autoControlsCombine' => FALSE,
'autoControlsSelector' => '',
],
'auto' => [
'auto' => FALSE,
'pause' => 4000,
'autoStart' => TRUE,
'autoDirection' => 'next',
'autoHover' => FALSE,
'autoDelay' => 0,
],
'carousel' => [
'minSlides' => 4,
'maxSlides' => 4,
'moveSlides' => 1,
'slideWidth' => 0,
],
],
] + $bxslider_settings;
}
/**
* {@inheritdoc}
*/
public function settingsForm(array $form, FormStateInterface $form_state) {
$elements = parent::settingsForm($form, $form_state);
// Hide Pager options, because here is used Thumbnail image slider.
$elements['slider']['pager']['#access'] = FALSE;
$settings = $this
->getSettings();
$image_styles = image_style_options(FALSE);
$elements['thumbnail_slider'] = [
'#type' => 'fieldset',
'#title' => $this
->t('Thumbnail slider'),
'#weight' => 10,
];
$elements['thumbnail_slider']['thumbnail_style'] = [
'#title' => $this
->t('Image style'),
'#type' => 'select',
'#default_value' => $settings['thumbnail_slider']['thumbnail_style'],
'#empty_option' => $this
->t('None (original image)'),
'#options' => $image_styles,
];
$elements['thumbnail_slider']['general'] = [
'#type' => 'details',
'#title' => $this
->t('General'),
'#weight' => 1,
'#open' => FALSE,
];
$elements['thumbnail_slider']['general']['mode'] = [
'#title' => $this
->t('Mode'),
'#type' => 'select',
'#default_value' => $settings['thumbnail_slider']['general']['mode'],
'#options' => [
'horizontal' => 'horizontal',
'fade' => 'fade',
],
];
$elements['thumbnail_slider']['general']['speed'] = [
'#title' => $this
->t('Speed'),
'#type' => 'textfield',
'#size' => 60,
'#default_value' => $settings['thumbnail_slider']['general']['speed'],
];
$elements['thumbnail_slider']['general']['slideMargin'] = [
'#title' => $this
->t('slideMargin'),
'#type' => 'textfield',
'#size' => 60,
'#default_value' => $settings['thumbnail_slider']['general']['slideMargin'],
];
$elements['thumbnail_slider']['general']['startSlide'] = [
'#title' => $this
->t('startSlide'),
'#type' => 'textfield',
'#size' => 60,
'#default_value' => $settings['thumbnail_slider']['general']['startSlide'],
];
$elements['thumbnail_slider']['general']['randomStart'] = [
'#type' => 'checkbox',
'#title' => $this
->t('randomStart'),
'#default_value' => $settings['thumbnail_slider']['general']['randomStart'],
];
$elements['thumbnail_slider']['general']['infiniteLoop'] = [
'#type' => 'checkbox',
'#title' => $this
->t('infiniteLoop'),
'#default_value' => $settings['thumbnail_slider']['general']['infiniteLoop'],
];
$elements['thumbnail_slider']['general']['hideControlOnEnd'] = [
'#type' => 'checkbox',
'#title' => $this
->t('hideControlOnEnd'),
'#default_value' => $settings['thumbnail_slider']['general']['hideControlOnEnd'],
];
$elements['thumbnail_slider']['general']['easing'] = [
'#title' => $this
->t('easing'),
'#type' => 'textfield',
'#size' => 60,
'#default_value' => $settings['thumbnail_slider']['general']['easing'],
];
$elements['thumbnail_slider']['general']['captions'] = [
'#type' => 'checkbox',
'#title' => $this
->t('captions'),
'#default_value' => $settings['thumbnail_slider']['general']['captions'],
];
$elements['thumbnail_slider']['general']['ticker'] = [
'#type' => 'checkbox',
'#title' => $this
->t('ticker'),
'#default_value' => $settings['thumbnail_slider']['general']['ticker'],
];
$elements['thumbnail_slider']['general']['tickerHover'] = [
'#type' => 'checkbox',
'#title' => $this
->t('tickerHover'),
'#default_value' => $settings['thumbnail_slider']['general']['tickerHover'],
];
$elements['thumbnail_slider']['general']['adaptiveHeight'] = [
'#type' => 'checkbox',
'#title' => $this
->t('adaptiveHeight'),
'#default_value' => $settings['thumbnail_slider']['general']['adaptiveHeight'],
];
$elements['thumbnail_slider']['general']['adaptiveHeightSpeed'] = [
'#title' => $this
->t('adaptiveHeightSpeed'),
'#type' => 'textfield',
'#size' => 60,
'#default_value' => $settings['thumbnail_slider']['general']['adaptiveHeightSpeed'],
];
$elements['thumbnail_slider']['general']['responsive'] = [
'#type' => 'checkbox',
'#title' => $this
->t('responsive'),
'#default_value' => $settings['thumbnail_slider']['general']['responsive'],
];
$elements['thumbnail_slider']['general']['useCSS'] = [
'#type' => 'checkbox',
'#title' => $this
->t('useCSS'),
'#default_value' => $settings['thumbnail_slider']['general']['useCSS'],
];
$elements['thumbnail_slider']['general']['preloadImages'] = [
'#title' => $this
->t('preloadImages'),
'#type' => 'select',
'#default_value' => $settings['thumbnail_slider']['general']['preloadImages'],
'#options' => [
'all' => 'all',
'visible' => 'visible',
],
];
$elements['slider']['general']['touchEnabled'] = [
'#type' => 'checkbox',
'#title' => $this
->t('touchEnabled'),
'#default_value' => $settings['slider']['general']['touchEnabled'],
];
$elements['thumbnail_slider']['general']['swipeThreshold'] = [
'#title' => $this
->t('swipeThreshold'),
'#type' => 'textfield',
'#size' => 60,
'#default_value' => $settings['thumbnail_slider']['general']['swipeThreshold'],
];
$elements['thumbnail_slider']['general']['oneToOneTouch'] = [
'#type' => 'checkbox',
'#title' => $this
->t('oneToOneTouch'),
'#default_value' => $settings['thumbnail_slider']['general']['oneToOneTouch'],
];
$elements['thumbnail_slider']['general']['preventDefaultSwipeX'] = [
'#type' => 'checkbox',
'#title' => $this
->t('preventDefaultSwipeX'),
'#default_value' => $settings['thumbnail_slider']['general']['preventDefaultSwipeX'],
];
$elements['thumbnail_slider']['general']['preventDefaultSwipeY'] = [
'#type' => 'checkbox',
'#title' => $this
->t('preventDefaultSwipeY'),
'#default_value' => $settings['thumbnail_slider']['general']['preventDefaultSwipeY'],
];
$elements['thumbnail_slider']['general']['wrapperClass'] = [
'#title' => $this
->t('wrapperClass'),
'#type' => 'textfield',
'#size' => 60,
'#default_value' => $settings['thumbnail_slider']['general']['wrapperClass'],
];
$elements['thumbnail_slider']['pager']['pager'] = [
'#type' => 'hidden',
'#default_value' => $settings['thumbnail_slider']['pager']['pager'],
];
$elements['thumbnail_slider']['controls'] = [
'#type' => 'details',
'#title' => $this
->t('Controls'),
'#weight' => 3,
'#open' => FALSE,
];
$elements['thumbnail_slider']['controls']['controls'] = [
'#type' => 'checkbox',
'#title' => $this
->t('controls'),
'#default_value' => $settings['thumbnail_slider']['controls']['controls'],
];
$elements['thumbnail_slider']['controls']['nextText'] = [
'#title' => $this
->t('nextText'),
'#type' => 'textfield',
'#size' => 60,
'#default_value' => $settings['thumbnail_slider']['controls']['nextText'],
];
$elements['thumbnail_slider']['controls']['prevText'] = [
'#title' => $this
->t('prevText'),
'#type' => 'textfield',
'#size' => 60,
'#default_value' => $settings['thumbnail_slider']['controls']['prevText'],
];
$elements['thumbnail_slider']['controls']['autoControls'] = [
'#type' => 'checkbox',
'#title' => $this
->t('autoControls'),
'#default_value' => $settings['thumbnail_slider']['controls']['autoControls'],
];
$elements['thumbnail_slider']['controls']['startText'] = [
'#title' => $this
->t('startText'),
'#type' => 'textfield',
'#size' => 60,
'#default_value' => $settings['thumbnail_slider']['controls']['startText'],
];
$elements['thumbnail_slider']['controls']['stopText'] = [
'#title' => $this
->t('stopText'),
'#type' => 'textfield',
'#size' => 60,
'#default_value' => $settings['thumbnail_slider']['controls']['stopText'],
];
$elements['thumbnail_slider']['controls']['autoControlsCombine'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Auto'),
'#default_value' => $settings['thumbnail_slider']['controls']['autoControlsCombine'],
];
$elements['thumbnail_slider']['auto'] = [
'#type' => 'details',
'#title' => $this
->t('Auto'),
'#weight' => 4,
'#open' => FALSE,
];
$elements['thumbnail_slider']['auto']['auto'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Auto'),
'#default_value' => $settings['thumbnail_slider']['auto']['auto'],
];
$elements['thumbnail_slider']['auto']['pause'] = [
'#title' => $this
->t('pause'),
'#type' => 'textfield',
'#size' => 60,
'#default_value' => $settings['thumbnail_slider']['auto']['pause'],
];
$elements['thumbnail_slider']['auto']['autoStart'] = [
'#type' => 'checkbox',
'#title' => $this
->t('autoStart'),
'#default_value' => $settings['thumbnail_slider']['auto']['autoStart'],
];
$elements['thumbnail_slider']['auto']['autoDirection'] = [
'#title' => $this
->t('autoDirection'),
'#type' => 'select',
'#default_value' => $settings['thumbnail_slider']['auto']['autoDirection'],
'#options' => [
'next' => 'next',
'prev' => 'prev',
],
];
$elements['thumbnail_slider']['auto']['autoHover'] = [
'#type' => 'checkbox',
'#title' => $this
->t('autoHover'),
'#default_value' => $settings['thumbnail_slider']['auto']['autoHover'],
];
$elements['thumbnail_slider']['auto']['autoDelay'] = [
'#title' => $this
->t('autoDelay'),
'#type' => 'textfield',
'#size' => 60,
'#default_value' => $settings['thumbnail_slider']['auto']['autoDelay'],
];
$elements['thumbnail_slider']['carousel'] = [
'#type' => 'details',
'#title' => $this
->t('Carousel'),
'#weight' => 5,
'#open' => FALSE,
];
$elements['thumbnail_slider']['carousel']['minSlides'] = [
'#title' => $this
->t('minSlides'),
'#type' => 'number',
'#size' => 60,
'#default_value' => $settings['thumbnail_slider']['carousel']['minSlides'],
];
$elements['thumbnail_slider']['carousel']['maxSlides'] = [
'#title' => $this
->t('maxSlides'),
'#type' => 'number',
'#size' => 60,
'#default_value' => $settings['thumbnail_slider']['carousel']['maxSlides'],
];
$elements['thumbnail_slider']['carousel']['moveSlides'] = [
'#title' => $this
->t('moveSlides'),
'#type' => 'number',
'#size' => 60,
'#default_value' => $settings['thumbnail_slider']['carousel']['moveSlides'],
];
return $elements;
}
/**
* {@inheritdoc}
*/
public function settingsSummary() {
$summary = [];
$summary[] = t('BxSlider (with thumbnail slider) configuration');
return $summary;
}
/**
* {@inheritdoc}
*/
public function viewElements(FieldItemListInterface $items, $langcode) {
$parent_elements = parent::viewElements($items, $langcode);
$elements = [];
$settings = $this->settings;
$files = $this
->getEntitiesToView($items, $langcode);
// Early opt-out if the field is empty.
if (empty($files)) {
return $elements;
}
$image_style_setting = $settings['thumbnail_slider']['thumbnail_style'];
// Collect cache tags to be added for each item in the field.
$base_cache_tags = [];
if (!empty($image_style_setting)) {
$image_style = $this->imageStyleStorage
->load($image_style_setting);
$base_cache_tags = $image_style
->getCacheTags();
}
$rendering_ths_items = [];
foreach ($files as $delta => $file) {
$cache_contexts = [];
if (isset($link_file)) {
$image_uri = $file
->getFileUri();
$url = Url::fromUri(file_create_url($image_uri));
$cache_contexts[] = 'url.site';
}
$cache_tags = Cache::mergeTags($base_cache_tags, $file
->getCacheTags());
$rendering_ths_items[] = $file->_referringItem;
}
// A slider's own pager must be disabled, because for pager is used
// another bxslider.
$settings['slider']['pager']['pager'] = FALSE;
$bxslider_settings['bxslider'] = array_merge($settings['slider']['general'], $settings['slider']['pager'], $settings['slider']['controls'], $settings['slider']['auto'], $settings['slider']['carousel']);
$bxslider_settings['image_style'] = $settings['slider']['image_style'];
$bxslider_settings['slider_id'] = 'bxslider-ths-' . str_replace('_', '-', $items
->getName());
$bxslider_settings['colorbox'] = $settings['colorbox'];
$bxslider_settings['thumbnail_slider'] = array_merge($settings['thumbnail_slider']['general'], $settings['thumbnail_slider']['pager'], $settings['thumbnail_slider']['controls'], $settings['thumbnail_slider']['auto'], $settings['thumbnail_slider']['carousel']);
$bxslider_settings['thumbnail_slider']['thumbnail_style'] = $settings['thumbnail_slider']['thumbnail_style'];
// Get thumbnail's width.
$image_style_ths = $this->imageStyleStorage
->load($settings['thumbnail_slider']['thumbnail_style']);
foreach ($image_style_ths
->getEffects() as $effect) {
$thumbnail_width = $effect->configuration['width'];
}
$bxslider_settings['thumbnail_slider']['slideWidth'] = $thumbnail_width;
$element = [
'#theme' => 'bxslider_ths',
'#items' => $parent_elements['#items'],
'#thumbnail_items' => $rendering_ths_items,
'#settings' => $bxslider_settings,
'#cache' => [
'tags' => $cache_tags,
'contexts' => $cache_contexts,
],
];
// Attach library.
$element['#attached']['library'][] = 'bxslider/jquery.bxslider_ths';
// Attach settings.
$this
->sliderSettingsFixIntegerValues($bxslider_settings);
$element['#attached']['drupalSettings']['bxslider_ths'][$bxslider_settings['slider_id']] = $bxslider_settings;
return $element;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
Bxslider:: |
protected | property | The image style entity storage. | |
Bxslider:: |
public static | function |
Creates an instance of the plugin. Overrides FormatterBase:: |
|
Bxslider:: |
protected | function | Replace strings with digits to int. | |
Bxslider:: |
public | function |
Constructs an ImageFormatter object. Overrides FormatterBase:: |
|
BxsliderThs:: |
public static | function |
Defines the default settings for this plugin. Overrides Bxslider:: |
|
BxsliderThs:: |
public | function |
Returns a form to configure settings for the formatter. Overrides Bxslider:: |
|
BxsliderThs:: |
public | function |
Returns a short summary for the current formatter settings. Overrides Bxslider:: |
|
BxsliderThs:: |
public | function |
Builds a renderable array for a field value. Overrides Bxslider:: |
|
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 | |
EntityReferenceFormatterBase:: |
public | function |
Loads the entities referenced in that field across all the entities being
viewed. Overrides FormatterBase:: |
|
EntityReferenceFormatterBase:: |
public | function |
Overrides FormatterBase:: |
|
FileFormatterBase:: |
protected | function |
Checks access to the given entity. Overrides EntityReferenceFormatterBase:: |
|
FileFormatterBase:: |
protected | function |
Returns whether the entity referenced by an item needs to be loaded. Overrides EntityReferenceFormatterBase:: |
1 |
FormatterBase:: |
protected | property | The field definition. | |
FormatterBase:: |
protected | property | The label display setting. | |
FormatterBase:: |
protected | property |
The formatter settings. Overrides PluginSettingsBase:: |
|
FormatterBase:: |
protected | property | The view mode. | |
FormatterBase:: |
protected | function | Returns the value of a field setting. | |
FormatterBase:: |
protected | function | Returns the array of field settings. | |
FormatterBase:: |
public static | function |
Returns if the formatter can be used for the provided field. Overrides FormatterInterface:: |
14 |
ImageFormatterBase:: |
protected | function |
Returns the referenced entities for display. Overrides EntityReferenceFormatterBase:: |
|
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
3 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
PluginSettingsBase:: |
protected | property | Whether default settings have been merged into the current $settings. | |
PluginSettingsBase:: |
protected | property | The plugin settings injected by third party modules. | |
PluginSettingsBase:: |
public | function |
Calculates dependencies for the configured plugin. Overrides DependentPluginInterface:: |
6 |
PluginSettingsBase:: |
public | function |
Returns the value of a setting, or its default value if absent. Overrides PluginSettingsInterface:: |
|
PluginSettingsBase:: |
public | function |
Returns the array of settings, including defaults for missing settings. Overrides PluginSettingsInterface:: |
|
PluginSettingsBase:: |
public | function |
Gets the list of third parties that store information. Overrides ThirdPartySettingsInterface:: |
|
PluginSettingsBase:: |
public | function |
Gets the value of a third-party setting. Overrides ThirdPartySettingsInterface:: |
|
PluginSettingsBase:: |
public | function |
Gets all third-party settings of a given module. Overrides ThirdPartySettingsInterface:: |
|
PluginSettingsBase:: |
protected | function | Merges default settings values into $settings. | |
PluginSettingsBase:: |
public | function |
Informs the plugin that some configuration it depends on will be deleted. Overrides PluginSettingsInterface:: |
3 |
PluginSettingsBase:: |
public | function |
Sets the value of a setting for the plugin. Overrides PluginSettingsInterface:: |
|
PluginSettingsBase:: |
public | function |
Sets the settings for the plugin. Overrides PluginSettingsInterface:: |
|
PluginSettingsBase:: |
public | function |
Sets the value of a third-party setting. Overrides ThirdPartySettingsInterface:: |
|
PluginSettingsBase:: |
public | function |
Unsets a third-party setting. Overrides ThirdPartySettingsInterface:: |
|
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. |