Commit 8dce5882 by Manzar Hussain

view slide show

parent 98dbbff2
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="" xml:lang="">
<head>
<meta charset="utf-8" />
<meta name="generator" content="pandoc" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" />
<title>Views Slideshow</title>
<style type="text/css">
code{white-space: pre-wrap;}
span.smallcaps{font-variant: small-caps;}
span.underline{text-decoration: underline;}
div.column{display: inline-block; vertical-align: top; width: 50%;}
</style>
<!--[if lt IE 9]>
<script src="//cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.3/html5shiv-printshiv.min.js"></script>
<![endif]-->
</head>
<body>
<h1 id="views-slideshow">Views Slideshow</h1>
<h2 id="introduction">INTRODUCTION</h2>
<p>Views Slideshow can create slideshows out any content on your Drupal site - whether that is images, images on content or full rendered entities. The <code>views_slideshow</code> module provides a base/plugin system/api for building full featured slideshows within the Views UI. This project also includes a module implementing that base; <code>views_slideshow_cycle</code>. For most users, you’ll just want to enable both of them and install pre-reqs. For advanced users you can create your own implementation - and there are other implementations for Drupal 7 available (see below).</p>
<p>Built in and most/all of the implementations are powered by jQuery, and are highly customizable: you may choose slideshow settings for each View display you create.</p>
<h3 id="potential-uses">Potential Uses</h3>
<ul>
<li>News item slideshow (such as the title, image and teaser of the last 5 news articles submitted)</li>
<li>The Last X number of X submitted (images, videos, blog entries, forum posts, comments, testimonials, etc.).</li>
<li>Rotate any image, based on any filters you can apply in views.</li>
<li>Hottest new products for any ecommerce drupal site.</li>
<li>Rotate contact links, share links, etc.</li>
<li>You can even rotate entire nodes, categories, image galleries, etc.</li>
<li>It’s also a great space saver. Places where you had multiple images or items such as RSS feeds or category listings can now be presented in a slideshow.</li>
</ul>
<h2 id="requirements">REQUIREMENTS</h2>
<ul>
<li>Views Slideshow 8.x-4.x requires Drupal 8 &amp; the core Views module enabled.</li>
<li>There is no upgrade path from Views Slideshow for Drupal 7.</li>
<li>Views Slideshow Cycle (Which most users should use) requires some JavaScript libraries:
<ul>
<li><a href="https://github.com/malsup/cycle">jQuery Cycle 3.x</a></li>
<li><a href="https://github.com/douglascrockford/JSON-js">JSON2</a></li>
<li><a href="https://github.com/briancherne/jquery-hoverIntent">jQuery HoverIntent</a></li>
<li><a href="https://github.com/tobia/Pause">jQuery Pause</a></li>
</ul></li>
</ul>
<h2 id="installation">INSTALLATION</h2>
<p>Install as you would normally install a contributed Drupal module. See the <a href="https://drupal.org/documentation/install/modules-themes/modules-8">Drupal 8 Instructions</a> if required in the Drupal documentation for further information. Note there are two modules included in this project; Views Slideshow &amp; Views Slideshow Cycle. In most cases you will need/want to enable both of them.</p>
<p>If you are using the Views Slideshow Cycle sub-module, you will also need to install some JavaScript libraries. The required libraries are:</p>
<ul>
<li><a href="https://github.com/malsup/cycle">jQuery Cycle 3.x</a> in <code>/libraries/jquery.cycle</code></li>
<li><a href="https://github.com/douglascrockford/JSON-js">JSON2</a> in <code>/libraries/json2</code></li>
<li><a href="https://github.com/briancherne/jquery-hoverIntent">jQuery HoverIntent</a> in <code>/libraries/jquery.hoverIntent</code></li>
<li><a href="https://github.com/tobia/Pause">jQuery Pause</a> in <code>/libraries/jquery.pause</code></li>
</ul>
<p>It is recommended to use <a href="https://drush.org">Drush</a> to automatically install the requirements to the right spot. To install all of the libraries to the right places, run <code>drush dl-cycle-lib</code>.</p>
<p>If you don’t have Drush available, or would prefer to install manually, you can do so. An example of code you could run in your Drupal root dir to download to the right place:</p>
<pre><code> mkdir -p libraries/jquery.cycle &amp;&amp; cd $_ &amp;&amp; wget https://malsup.github.io/jquery.cycle.all.js \
&amp;&amp; mkdir -p ../../libraries/jquery.hoverIntent &amp;&amp; cd $_ &amp;&amp; wget https://raw.githubusercontent.com/briancherne/jquery-hoverIntent/master/jquery.hoverIntent.js \
&amp;&amp; mkdir -p ../../libraries/json2 &amp;&amp; cd $_ &amp;&amp; wget https://raw.githubusercontent.com/douglascrockford/JSON-js/master/json2.js \
&amp;&amp; mkdir -p ../../libraries/jquery.pause &amp;&amp; cd $_ &amp;&amp; wget https://raw.githubusercontent.com/tobia/Pause/master/jquery.pause.js</code></pre>
<h2 id="configuration">CONFIGURATION</h2>
<p>Configuration is on a per view/display basis.</p>
<p>Most standard views settings will work fine in conjunction with Views Slideshow. However, grouping may or may not work. Under most use cases the pager should be set to either <code>Display a specified number of items</code> or <code>Display all</code>.</p>
<p>To get started configuring your slideshow, set <code>Slideshow</code> as the display format and configure the slideshow as desired under Format Settings. Next select the <em>Skin</em> - usually <code>Default</code> (only one provided with the module). Then select the <em>Slideshow Type</em>; for most users, this will just be <code>cycle</code> with the <code>views_slideshow_cycle</code> module.</p>
<p>Below that, there is a lot of different options which should have better documentation.</p>
<h3 id="see-also">See also:</h3>
<ul>
<li><a href="https://www.ostraining.com/blog/drupal/drupal-8-slideshows">OS Training tutorial on Views Slideshow</a></li>
</ul>
<h2 id="contributors">CONTRIBUTORS</h2>
<p>Current maintainer:</p>
<ul>
<li><a href="https://www.drupal.org/u/neslee-canil-pinto">Neslee Canil Pinto</a></li>
</ul>
<p>Past maintainers:</p>
<ul>
<li><p><a href="https://www.drupal.org/u/vbouchet">vbouchet</a> Initial 8.x port</p></li>
<li><p><a href="https://www.drupal.org/u/redndahead">Adam Moore</a></p></li>
<li><a href="https://www.drupal.org/u/nickwilde">Nick Wilde</a></li>
</ul>
<p>Also, thanks to the many contributors via the issue queues.</p>
</body>
</html>
# Views Slideshow
## INTRODUCTION
Views Slideshow can create slideshows out any content on your Drupal site -
whether that is images, images on content or full rendered entities. The
`views_slideshow` module provides a base/plugin system/api for building full
featured slideshows within the Views UI. This project also includes a module
implementing that base; `views_slideshow_cycle`. For most users, you'll just
want to enable both of them and install pre-reqs. For advanced users you can
create your own implementation - and there are other implementations for Drupal
7 available (see below).
Built in and most/all of the implementations are powered by jQuery, and are
highly customizable: you may choose slideshow settings for each View display
you create.
### Potential Uses
* News item slideshow (such as the title, image and teaser of the last 5 news
articles submitted)
* The Last X number of X submitted (images, videos, blog entries, forum posts,
comments, testimonials, etc.).
* Rotate any image, based on any filters you can apply in views.
* Hottest new products for any ecommerce drupal site.
* Rotate contact links, share links, etc.
* You can even rotate entire nodes, categories, image galleries, etc.
* It's also a great space saver. Places where you had multiple images or items
such as RSS feeds or category listings can now be presented in a slideshow.
## REQUIREMENTS
* Views Slideshow 8.x-4.x requires Drupal 8 & the core Views module enabled.
* There is no upgrade path from Views Slideshow for Drupal 7.
* Views Slideshow Cycle (Which most users should use) requires some JavaScript
libraries:
* [jQuery Cycle 3.x](https://github.com/malsup/cycle)
* [JSON2](https://github.com/douglascrockford/JSON-js)
* [jQuery HoverIntent](https://github.com/briancherne/jquery-hoverIntent)
* [jQuery Pause](https://github.com/tobia/Pause)
## INSTALLATION
Install as you would normally install a contributed Drupal module. See the
[Drupal 8 Instructions](https://drupal.org/documentation/install/modules-themes/modules-8)
if required in the Drupal documentation for further information. Note there are
two modules included in this project; Views Slideshow & Views Slideshow Cycle.
In most cases you will need/want to enable both of them.
If you are using the Views Slideshow Cycle sub-module, you will also need to
install some JavaScript libraries. The required libraries are:
* [jQuery Cycle 3.x](https://github.com/malsup/cycle) in
`/libraries/jquery.cycle`
* [JSON2](https://github.com/douglascrockford/JSON-js) in `/libraries/json2`
* [jQuery HoverIntent](https://github.com/briancherne/jquery-hoverIntent)
in `/libraries/jquery.hoverIntent`
* [jQuery Pause](https://github.com/tobia/Pause) in `/libraries/jquery.pause`
It is recommended to use [Drush](https://drush.org) to automatically install
the requirements to the right spot. To install all of the libraries to the
right places, run `drush dl-cycle-lib`.
If you don't have Drush available, or would prefer to install manually, you can
do so. An example of code you could run in your Drupal root dir to download to
the right place:
```
mkdir -p libraries/jquery.cycle && cd $_ && wget https://malsup.github.io/jquery.cycle.all.js \
&& mkdir -p ../../libraries/jquery.hoverIntent && cd $_ && wget https://raw.githubusercontent.com/briancherne/jquery-hoverIntent/master/jquery.hoverIntent.js \
&& mkdir -p ../../libraries/json2 && cd $_ && wget https://raw.githubusercontent.com/douglascrockford/JSON-js/master/json2.js \
&& mkdir -p ../../libraries/jquery.pause && cd $_ && wget https://raw.githubusercontent.com/tobia/Pause/master/jquery.pause.js
```
## CONFIGURATION
Configuration is on a per view/display basis.
Most standard views settings will work fine in conjunction with Views Slideshow.
However, grouping may or may not work. Under most use cases the pager should be
set to either `Display a specified number of items` or `Display all`.
To get started configuring your slideshow, set `Slideshow` as the display
format and configure the slideshow as desired under Format Settings. Next
select the *Skin* - usually `Default` (only one provided with the module).
Then select the *Slideshow Type*; for most users, this will just be `cycle`
with the `views_slideshow_cycle` module.
Below that, there is a lot of different options which should have better
documentation.
### See also:
* [OS Training tutorial on Views Slideshow](https://www.ostraining.com/blog/drupal/drupal-8-slideshows)
## CONTRIBUTORS
Current maintainer:
* [Neslee Canil Pinto](https://www.drupal.org/u/neslee-canil-pinto)
Past maintainers:
* [vbouchet](https://www.drupal.org/u/vbouchet) Initial 8.x port
* [Adam Moore](https://www.drupal.org/u/redndahead)
* [Nick Wilde](https://www.drupal.org/u/nickwilde)
Also, thanks to the many contributors via the issue queues.
{
"name": "drupal/views_slideshow",
"description": "Describes relationships between entities.",
"type": "drupal-module",
"license": "GPL-2.0-or-later",
"homepage": "https://www.drupal.org/project/views_slideshow",
"authors": [
{
"name": "Neslee Canil Pinto",
"homepage": "https://www.drupal.org/u/neslee-canil-pinto",
"role": "Maintainer"
}
],
"support": {
"issues": "https://www.drupal.org/project/issues/views_slideshow",
"irc": "irc://irc.freenode.org/drupal-contribute",
"source": "https://git.drupalcode.org/project/views_slideshow"
},
"require": {
"drupal/core": "^8 || ^9"
}
}
views.style.slideshow:
type: views_style
label: 'Slideshow'
mapping:
slideshow_skin:
type: string
label: 'Skin to apply to the slideshow'
slideshow_type:
type: string
label: 'Main frame plugin to use to render the slideshow'
widgets:
type: mapping
label: 'Control widgets for the slideshow'
mapping:
top:
type: views_slideshow_control_group
label: 'Widget configuration for above the slideshow'
bottom:
type: views_slideshow_control_group
label: 'Widget configuration for below the slideshow'
# Basic data types for views slideshows.
views_slideshow_widget:
type: mapping
label: 'widget'
mapping:
enable:
type: boolean
label: 'Show widget'
weight:
type: string
label: 'Sort order'
hide_on_single_slide:
type: string
label: 'Hide if only one slide'
views_slideshow_control_group:
type: mapping
label: 'Group of widget settings for slideshow region'
mapping:
views_slideshow_controls:
type: views_slideshow_widget
label: 'Slideshow controls'
mapping:
enable:
type: boolean
label: 'Show widget'
weight:
type: string
label: 'Sort order'
hide_on_single_slide:
type: string
label: 'Hide if only one slide'
type:
type: string
label: 'The control type'
views_slideshow_slide_counter:
type: views_slideshow_widget
label: 'Slide Counter'
views_slideshow_pager:
type: views_slideshow_widget
label: 'Slideshow pager'
mapping:
enable:
type: boolean
label: 'Show widget'
weight:
type: string
label: 'Sort order'
hide_on_single_slide:
type: string
label: 'Hide if only one slide'
type:
type: string
label: 'The control type'
.views_slideshow_controls_text span:hover {
text-decoration: underline;
cursor: pointer;
}
.views-slideshow-controls-bottom .views-slideshow-pager-bullets {
text-align: center;
}
.views-slideshow-controls-bottom .views-slideshow-pager-bullets li {
text-indent: -9999px;
cursor: pointer;
display: inline-block;
border-radius: 6px;
padding: 0 6px;
background: #222;
margin: 0.4em;
line-height: 12px;
}
.views-slideshow-controls-bottom .views-slideshow-pager-bullets li.active {
background: #aaa;
cursor: default;
}
.views-slideshow-controls-bottom .views-slideshow-pager-bullets li:hover {
background: #555;
}
#views-slideshow-form-wrapper .form-item.dependent-options {
padding-left: 5px;
}
#views-slideshow-form-wrapper .vs-dependent {
padding-left: 30px;
}
{
"name": "drupal/views_slideshow_cycle",
"description": "Cycle plugin for Views Slideshow.",
"type": "drupal-module",
"license": "GPL-2.0+",
"homepage": "https://www.drupal.org/project/views_slideshow",
"authors": [
{
"name": "See contributors",
"homepage": "https://www.drupal.org/node/160350/committers"
}
],
"support": {
"issues": "https://www.drupal.org/project/issues/views_slideshow",
"irc": "irc://irc.freenode.org/drupal-contribute",
"source": "https://git.drupalcode.org/project/views_slideshow"
},
"require": {},
"extra": {
"drush": {
"services": {
"drush.services.yml": "^9"
}
}
}
}
.views_slideshow_cycle_no_display,
.views_slideshow_cycle_hidden,
.views_slideshow_cycle_controls,
.views_slideshow_cycle_image_count {
display: none;
}
/* Pager Settings */
.views_slideshow_cycle_pager div a img {
width: 75px;
height: 75px;
}
.views_slideshow_pager_numbered div,
.views_slideshow_pager_thumbnails div {
display: inline;
padding-left: 10px;
}
.views_slideshow_cycle_pager.thumbnails a.activeSlide img {
border: 3px solid #000;
}
.views_slideshow_cycle_pager.numbered a.activeSlide {
text-decoration: underline;
}
services:
views_slideshow_cycle.commands:
class: \Drupal\views_slideshow_cycle\Commands\ViewsSlideshowCycleCommands
tags:
- { name: drush.command }
/**
* @file
* Javascript to enhance the views slideshow cycle form options.
*/
/**
* This will set our initial behavior, by starting up each individual slideshow.
*/
(function ($) {
// Since Drupal 7 doesn't support having a field based on one of 3 values of
// a select box we need to add our own JavaScript handling.
Drupal.behaviors.viewsSlideshowCycleAmountAllowedVisible = {
attach: function (context) {
// If necessary at start hide the amount allowed visible box.
var type = $(":input[name='style_options[views_slideshow_cycle][pause_when_hidden_type]']").val();
if (type == 'full') {
$(":input[name='style_options[views_slideshow_cycle][amount_allowed_visible]']").parent().hide();
}
// Handle dependency on action advanced checkbox.
$(":input[name='style_options[views_slideshow_cycle][action_advanced]']").change(function () {
processValues('action_advanced');
});
// Handle dependency on pause when hidden checkbox.
$(':input[name="style_options[views_slideshow_cycle][pause_when_hidden]"]').change(function () {
processValues('pause_when_hidden');
});
// Handle dependency on pause when hidden type select box.
$(":input[name='style_options[views_slideshow_cycle][pause_when_hidden_type]']").change(function () {
processValues('pause_when_hidden_type');
});
// Process our dependencies.
function processValues(field) {
switch (field) {
case 'action_advanced':
if (!$(':input[name="style_options[views_slideshow_cycle][action_advanced]"]').is(':checked')) {
$(":input[name='style_options[views_slideshow_cycle][amount_allowed_visible]']").parent().hide();
break;
}
case 'pause_when_hidden':
if (!$(':input[name="style_options[views_slideshow_cycle][pause_when_hidden]"]').is(':checked')) {
$(":input[name='style_options[views_slideshow_cycle][amount_allowed_visible]']").parent().hide();
break;
}
case 'pause_when_hidden_type':
if ($(":input[name='style_options[views_slideshow_cycle][pause_when_hidden_type]']").val() == 'full') {
$(":input[name='style_options[views_slideshow_cycle][amount_allowed_visible]']").parent().hide();
}
else {
$(":input[name='style_options[views_slideshow_cycle][amount_allowed_visible]']").parent().show();
}
}
}
}
}
// Manage advanced options.
Drupal.behaviors.viewsSlideshowCycleOptions = {
attach: function (context) {
if ($(":input[name='style_options[views_slideshow_cycle][advanced_options]']").length) {
$(":input[name='style_options[views_slideshow_cycle][advanced_options]']").parent().hide();
$(":input[name='style_options[views_slideshow_cycle][advanced_options_entry]']").parent().after(
'<div style="margin-left: 10px; padding: 10px 0;">' +
'<a id="edit-style-options-views-slideshow-cycle-advanced-options-update-link" href="#">' + Drupal.t('Update Advanced Option') + '</a>' +
'</div>'
);
$("#edit-style-options-views-slideshow-cycle-advanced-options-table").append('<tr><th colspan="2">' + Drupal.t('Applied Options') + '</th><tr>')
var initialValue = $(":input[name='style_options[views_slideshow_cycle][advanced_options]']").val();
var advancedOptions = JSON.parse(initialValue);
for (var option in advancedOptions) {
viewsSlideshowCycleAdvancedOptionsAddRow(option);
}
// Add the remove event to the advanced items.
viewsSlideshowCycleAdvancedOptionsRemoveEvent();
$(":input[name='style_options[views_slideshow_cycle][advanced_options_choices]']").change(function () {
var selectedValue = $(":input[name='style_options[views_slideshow_cycle][advanced_options_choices]'] option:selected").val();
if (typeof advancedOptions[selectedValue] !== 'undefined') {
$(":input[name='style_options[views_slideshow_cycle][advanced_options_entry]']").val(advancedOptions[selectedValue]);
}
else {
$(":input[name='style_options[views_slideshow_cycle][advanced_options_entry]']").val('');
}
});
$('#edit-style-options-views-slideshow-cycle-advanced-options-update-link').click(function () {
var option = $(":input[name='style_options[views_slideshow_cycle][advanced_options_choices]']").val();
if (option) {
var value = $(":input[name='style_options[views_slideshow_cycle][advanced_options_entry]']").val();
if (typeof advancedOptions[option] == 'undefined') {
viewsSlideshowCycleAdvancedOptionsAddRow(option);
viewsSlideshowCycleAdvancedOptionsRemoveEvent()
}
advancedOptions[option] = value;
viewsSlideshowCycleAdvancedOptionsSave();
}
return false;
});
}
function viewsSlideshowCycleAdvancedOptionsAddRow(option) {
$("#edit-style-options-views-slideshow-cycle-advanced-options-table").append(
'<tr id="views-slideshow-cycle-advanced-options-table-row-' + option + '">' +
'<td>' + option + '</td>' +
'<td style="width: 20px;">' +
'<a style="margin-top: 6px" title="Remove ' + option + '" alt="Remove ' + option + '" class="views-hidden views-button-remove views-slideshow-cycle-advanced-options-table-remove" id="views-slideshow-cycle-advanced-options-table-remove-' + option + '" href="#"><span>Remove</span></a>' +
'</td>' +
'</tr>'
);
}
function viewsSlideshowCycleAdvancedOptionsRemoveEvent() {
$('.views-slideshow-cycle-advanced-options-table-remove').unbind().click(function () {
var itemID = $(this).attr('id');
var uniqueID = itemID.replace('views-slideshow-cycle-advanced-options-table-remove-', '');
delete advancedOptions[uniqueID];
$('#views-slideshow-cycle-advanced-options-table-row-' + uniqueID).remove();
viewsSlideshowCycleAdvancedOptionsSave();
return false;
});
}
function viewsSlideshowCycleAdvancedOptionsSave() {
var advancedOptionsString = JSON.stringify(advancedOptions);
$(":input[name='style_options[views_slideshow_cycle][advanced_options]']").val(advancedOptionsString);
}
}
}
})(jQuery, Drupal);
<?php
namespace Drupal\views_slideshow_cycle\Commands;
use Drush\Commands\DrushCommands;
use Drush\Drush;
/**
* Drush commands for Views Slideshow Cycle.
*/
class ViewsSlideshowCycleCommands extends DrushCommands {
/**
* Download and install the jQuery Cycle library.
*
* @command views:slideshow:cycle
* @aliases dl-cycle,views-slideshow-cycle-cycle
*/
public function downloadCycle() {
$this->installLibrary(
'jQuery Cycle',
'libraries/jquery.cycle',
'jquery.cycle.all.js',
'https://raw.githubusercontent.com/malsup/cycle/3.0.3/jquery.cycle.all.js'
);
}
/**
* Download and install the JSON2 library.
*
* @command views:slideshow:json2
* @aliases dl-json2,views-slideshow-cycle-json2
*/
public function downloadJson2() {
$this->installLibrary(
'JSON2',
'libraries/json2',
'json2.js',
'https://raw.githubusercontent.com/douglascrockford/JSON-js/master/json2.js'
);
}
/**
* Download and install the jquery.hoverIntent library.
*
* @command views:slideshow:hoverintent
* @aliases dl-hoverintent,views-slideshow-cycle-hoverintent
*/
public function downloadHoverIntent() {
$this->installLibrary(
'jQuery HoverIntent',
'libraries/jquery.hoverIntent',
'jquery.hoverIntent.js',
'https://raw.githubusercontent.com/briancherne/jquery-hoverIntent/master/jquery.hoverIntent.js'
);
}
/**
* Download and install the jQuery.pause library.
*
* @command views:slideshow:pause
* @aliases dl-pause,views-slideshow-cycle-pause
*/
public function downloadPause() {
$this->installLibrary(
'jQuery Pause',
'libraries/jquery.pause',
'jquery.pause.js',
'https://raw.githubusercontent.com/tobia/Pause/master/jquery.pause.js'
);
}
/**
* Download and install the jQuery Cycle.
*
* Download and install JQuery hoverIntent, JSON2 and Pause libraries.
*
* @command views:slideshow:lib
* @aliases dl-cycle-lib,views-slideshow-cycle-lib
*/
public function downloadLib() {
$this->downloadCycle();
$this->downloadHoverIntent();
$this->downloadJson2();
$this->downloadPause();
}
/**
* Helper function to download a library in the given directory.
*/
protected function installLibrary($name, $path, $filename, $url) {
// Create the path if it does not exist.
if (!is_dir($path)) {
drush_op('mkdir', $path, 0755, TRUE);
$this->logger()->info(dt('Directory @path was created', ['@path' => $path]));
}
// Be sure we can write in the directory.
$perms = substr(sprintf('%o', fileperms($path)), -4);
if ($perms !== '0755') {
Drush::process('chmod 755 ' . $path);
}
else {
$perms = NULL;
}
$dir = getcwd();
// Download the JavaScript file.
if (is_file($path . '/' . $filename)) {
$this->logger()->notice(dt('@name appears to be already installed.', [
'@name' => $name,
]));
}
elseif (drush_op('chdir', $path) && Drush::process('wget ' . $url)) {
$this->logger()->success(dt('The latest version of @name has been downloaded to @path', [
'@name' => $name,
'@path' => $path,
]));
}
else {
$this->logger()->warning(dt('Drush was unable to download the @name library to @path', [
'@name' => $name,
'@path' => $path,
]));
}
chdir($dir);
// Restore the previous permissions.
if ($perms) {
Drush::process('chmod ' . $perms . ' ' . $path);
}
}
}
{#
/**
* @file
* Default theme implementation for an item on a views slideshow cycle slide.
*
* Available variables:
* - classes: Classes to apply to the element.
* - count: The slide number.
* - item: Rendeder field(s) making up item.
* - item_count: nth item on slide.
* - length: Total number of slides.
* - view: The view.
*
* @see template_preprocess_views_slideshow_cycle_main_frame_row_item()
*
* @ingroup vss_templates
*/
#}
<div {{ attributes.addClass(classes) }}>
{{ item }}
</div>
{#
/**
* @file
* Default theme implementation for an individual views slideshow cycle slide.
*
* Available variables:
* - classes: Classes to apply to the element.
* - count: The slide number.
* - rendered_items: Rendered items for slide.
* - vss_id: The slideshow's id.
*
* @see template_preprocess_views_slideshow_()
*
* @ingroup vss_templates
*/
#}
<div id="views_slideshow_cycle_div_{{ vss_id }}_{{ count }}" {{ attributes.addClass(classes) }}>
{% for rendered_item in rendered_items %}
{{ rendered_item }}
{% endfor %}
</div>
{#
/**
* @file
* Default theme implementation for an views slideshow cycle main frame.
*
* Available variables:
* - classes: Classes to apply to the element.
* - rendered_rows: The slides.
* - vss_id: The slideshow id.
*
* @see template_preprocess_views_slideshow_cycle_main_frame()
*
* @ingroup vss_templates
*/
#}
<div id="views_slideshow_cycle_teaser_section_{{ vss_id }}" {{ attributes.addClass(classes) }}>
{% for rendered_row in rendered_rows %}
{{ rendered_row }}
{% endfor %}
</div>
{#
/**
* @file
* Default theme implementation for a views slideshow with cycle main plugin.
*
* Available variables:
* - bottom_widget_rendered: Widget under the slideshow with controls/data.
* - skin: The skin being applied to the slideshow.
* - slideshow: The slideshow.
* - top_widget_rendered: Widget above the slideshow with controls/data.
*
* @see _views_slideshow_preprocess_views_view_slideshow()
*
* @ingroup vss_templates
*/
#}
<div class="skin-{{ skin }}">
{% if top_widget_rendered %}
<div class="views-slideshow-controls-top clearfix">
{{ top_widget_rendered }}
</div>
{% endif %}
{{ slideshow }}
{% if bottom_widget_rendered %}
<div class="views-slideshow-controls-bottom clearfix">
{{ bottom_widget_rendered }}
</div>
{% endif %}
</div>
<?php
/**
* @file
* Drush integration for Views Slideshow.
*
* Specifically downloading of required and optional JavaScript libraries.
*/
use Drush\Drush;
/**
* Implements hook_drush_command().
*/
function views_slideshow_cycle_drush_command() {
$items = [];
// The key in the $items array is the name of the command.
$items['views-slideshow-cycle-cycle'] = [
'description' => dt('Download and install the jQuery Cycle library.'),
'bootstrap' => DRUSH_BOOTSTRAP_DRUSH,
'arguments' => [
'path' => dt('Optional. The path to install the jQuery Cycle library in. If omitted Drush will use the default location.'),
],
'aliases' => ['dl-cycle'],
];
$items['views-slideshow-cycle-json2'] = [
'description' => dt('Download and install the JSON2 library.'),
'bootstrap' => DRUSH_BOOTSTRAP_DRUSH,
'arguments' => [
'path' => dt('Optional. The path to install the JSON2 library in. If omitted Drush will use the default location.'),
],
'aliases' => ['dl-json2'],
];
$items['views-slideshow-cycle-hoverintent'] = [
'description' => dt('Download and install the jquery.hoverIntent library.'),
'bootstrap' => DRUSH_BOOTSTRAP_DRUSH,
'arguments' => [
'path' => dt('Optional. The path to install the jquery.hoverIntent library in. If omitted Drush will use the default location.'),
],
'aliases' => ['dl-hoverintent'],
];
$items['views-slideshow-cycle-pause'] = [
'description' => dt('Download and install the jQuery.pause library.'),
'bootstrap' => DRUSH_BOOTSTRAP_DRUSH,
'arguments' => [
'path' => dt('Optional. The path to install the jQuery.pause library in. If omitted Drush will use the default location.'),
],
'aliases' => ['dl-pause'],
];
$items['views-slideshow-cycle-lib'] = [
'description' => dt('Download and install the jQuery Cycle, jQuery hoverIntent and JSON2 libraries.'),
'bootstrap' => DRUSH_BOOTSTRAP_DRUSH,
'aliases' => ['dl-cycle-lib'],
];
return $items;
}
/**
* Implements hook_drush_help().
*/
function views_slideshow_cycle_drush_help($section) {
switch ($section) {
case 'drush:views-slideshow-cycle-cycle':
return dt('Download and install the jQuery Cycle library from http://malsup.github.com/jquery.cycle.all.js, default location is libraries/jquery.cycle.');
case 'drush:views-slideshow-cycle-hoverintent':
return dt('Download and install the jQuery hoverIntent library from https://raw.githubusercontent.com/briancherne/jquery-hoverIntent/master/jquery.hoverIntent.js, default location is libraries/jquery.cycle.');
case 'drush:views-slideshow-cycle-pause':
return dt('Download and install the jQuery pause library from https://raw.githubusercontent.com/tobia/Pause/master/jquery.pause.js, default location is libraries/jquery.pause.');
case 'drush:views-slideshow-cycle-json2':
return dt('Download and install the JSON2 library from https://github.com/douglascrockford/JSON-js/, default location is libraries/json2.');
case 'drush:views-slideshow-cycle-lib':
return dt('Download and install the jQuery Cycle, jQuery hoverIntent and JSON2 libraries.');
}
}
/**
* Command to download the jQuery Cycle library.
*/
function drush_views_slideshow_cycle_cycle() {
_drush_views_slideshow_cycle_install_library(
'jQuery Cycle',
'libraries/jquery.cycle',
'jquery.cycle.all.js',
'https://raw.githubusercontent.com/malsup/cycle/3.0.3/jquery.cycle.all.js',
func_get_args()
);
}
/**
* Command to download the JSON2 library.
*/
function drush_views_slideshow_cycle_json2() {
_drush_views_slideshow_cycle_install_library(
'JSON2',
'libraries/json2',
'json2.js',
'https://raw.githubusercontent.com/douglascrockford/JSON-js/master/json2.js',
func_get_args()
);
}
/**
* Command to download the jQuery.hoverIntent library.
*/
function drush_views_slideshow_cycle_hoverintent() {
_drush_views_slideshow_cycle_install_library(
'jQuery HoverIntent',
'libraries/jquery.hoverIntent',
'jquery.hoverIntent.js',
'https://raw.githubusercontent.com/briancherne/jquery-hoverIntent/master/jquery.hoverIntent.js',
func_get_args()
);
}
/**
* Command to download the jQuery.pause library.
*/
function drush_views_slideshow_cycle_pause() {
_drush_views_slideshow_cycle_install_library(
'jQuery Pause',
'libraries/jquery.pause',
'jquery.pause.js',
'https://raw.githubusercontent.com/tobia/Pause/master/jquery.pause.js',
func_get_args()
);
}
/**
* Command to download all libraries.
*/
function drush_views_slideshow_cycle_lib() {
drush_views_slideshow_cycle_cycle();
drush_views_slideshow_cycle_json2();
drush_views_slideshow_cycle_hoverintent();
drush_views_slideshow_cycle_pause();
}
/**
* Implements drush_MODULE_pre_pm_enable().
*/
function drush_views_slideshow_cycle_pre_pm_enable() {
$modules = drush_get_context('PM_ENABLE_MODULES');
if (in_array('views_slideshow_cycle', $modules) && !drush_get_option('skip')) {
drush_views_slideshow_cycle_lib();
}
}
/**
* Helper function to download a library in the given directory.
*/
function _drush_views_slideshow_cycle_install_library($name, $path, $filename, $url, $args) {
// Check if path provided as an arg and use that instead of default if so.
if (!empty($args[0])) {
$path = $args[0];
}
// Create the path if it does not exist.
if (!is_dir($path)) {
drush_op('mkdir', $path, 0755, TRUE);
\Drupal::logger(dt('Directory @path was created', ['@path' => $path]), 'success');
}
// Be sure we can write in the directory.
$perms = substr(sprintf('%o', fileperms($path)), -4);
if ($perms !== '0755') {
Drush::process('chmod 755 ' . $path);
}
$dir = getcwd();
// Download the JavaScript file.
if (is_file($path . '/' . $filename)) {
\Drupal::logger(dt('@name appears to be already installed.', [
'@name' => $name,
]), 'ok');
}
elseif (drush_op('chdir', $path) && Drush::process('wget --no-check-certificate ' . $url)) {
\Drupal::logger(dt('The latest version of @name has been downloaded to @path', [
'@name' => $name,
'@path' => $path,
]), 'success');
}
else {
\Drupal::logger(dt('Drush was unable to download the @name library to @path', [
'@name' => $name,
'@path' => $path,
]), 'error');
}
chdir($dir);
// Restore the previous permissions.
Drush::process('chmod ' . $perms . ' ' . $path);
}
name: Views Slideshow Cycle
type: module
description: 'Adds a Rotating slideshow mode to Views Slideshow.'
package: Views
core: 8.x
core_version_requirement: ^8 || ^9
dependencies:
- views_slideshow:views_slideshow
# Information added by Drupal.org packaging script on 2020-09-28
version: '8.x-4.8'
project: 'views_slideshow'
datestamp: 1601309227
formoptions:
js:
js/formoptions.js: {}
dependencies:
- core/jquery
- core/drupal
views_slideshow_cycle:
css:
component:
css/views_slideshow_cycle.css: {}
js:
js/views_slideshow_cycle.js: {}
dependencies:
- core/jquery
- core/drupal
- core/drupalSettings
jquery_cycle:
remote: http://malsup.github.io/jquery.cycle.all.js
version: 3.0.3
license:
name: MIT
url: http://jquery.malsup.com/license.html
gpl-compatible: true
js:
/libraries/jquery.cycle/jquery.cycle.all.js: {}
dependencies:
- core/jquery
json2:
remote: https://raw.githubusercontent.com/douglascrockford/JSON-js/master/json2.js
version: 2.0
license:
name: MIT
url: https://github.com/douglascrockford/JSON-js/blob/master/README
gpl-compatible: true
js:
/libraries/json2/json2.js: {}
jquery_pause:
remote: https://github.com/tobia/Pause
version: 3.0.3
license:
name: GNU
url: https://raw.githubusercontent.com/tobia/Pause/master/LICENSE.txt
gpl-compatible: true
js:
/libraries/jquery.pause/jquery.pause.js: {}
dependencies:
- core/jquery
<?php
/**
* @file
* Views Slideshow: cycle is typically used for field views.
*/
use Drupal\Core\Url;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Link;
/**
* Implements hook_help().
*/
function views_slideshow_cycle_help($route_name, RouteMatchInterface $route_match) {
switch ($route_name) {
case 'help.page.views_slideshow_cycle':
if (\Drupal::moduleHandler()->moduleExists('advanced_help')) {
$output = '<p>' . Link::fromTextAndUrl(t('Click here to view the documentation for Views Slideshow Cycle.'), Url::fromRoute('advanced_help.module_index', ['module' => 'views_slideshow_cycle'])->toString()) . '</p>';
}
else {
$output = '<p>' . t('Views Slideshow Cycle help can be found by installing and enabling the @advanced_help', ['@advanced_help' => Link::fromTextAndUrl(t('Advanced Help module'), Url::fromUri('http://drupal.org/project/advanced_help'))->toString()]) . '</p>';
}
return $output;
}
}
/**
* Implements hook_theme().
*/
function views_slideshow_cycle_theme($existing, $type, $theme, $path) {
return [
'views_slideshow_cycle' => [
'variables' => [
'view' => NULL,
'settings' => [],
'rows' => [],
'title' => '',
],
'template' => 'views-slideshow-cycle',
'file' => 'views_slideshow_cycle.theme.inc',
],
'views_slideshow_cycle_main_frame' => [
'variables' => [
'vss_id' => NULL,
'view' => NULL,
'settings' => NULL,
'rows' => NULL,
],
'template' => 'views-slideshow-cycle-main-frame',
'file' => 'views_slideshow_cycle.theme.inc',
],
'views_slideshow_cycle_main_frame_row' => [
'variables' => [
'vss_id' => NULL,
'items' => NULL,
'count' => NULL,
'view' => NULL,
],
'template' => 'views-slideshow-cycle-main-frame-row',
'file' => 'views_slideshow_cycle.theme.inc',
],
'views_slideshow_cycle_main_frame_row_item' => [
'variables' => [
'item' => NULL,
'item_count' => NULL,
'count' => NULL,
'view' => NULL,
'length' => NULL,
],
'template' => 'views-slideshow-cycle-main-frame-row-item',
'file' => 'views_slideshow_cycle.theme.inc',
],
];
}
/**
* Implements hook_preprocess_views_slideshow_pager_fields().
*
* As it is a preprocess function, store it with other functions in theme.inc.
*/
function views_slideshow_cycle_preprocess_views_slideshow_pager_fields(&$vars) {
\Drupal::moduleHandler()->loadInclude('views_slideshow_cycle', 'inc', 'views_slideshow_cycle.theme');
_views_slideshow_cycle_preprocess_views_slideshow_pager_fields($vars);
}
/**
* Implements hook_preprocess_views_slideshow_slide_counter().
*
* As it is a preprocess function, store it with other functions in theme.inc.
*/
function views_slideshow_cycle_preprocess_views_slideshow_slide_counter(&$vars) {
\Drupal::moduleHandler()->loadInclude('views_slideshow_cycle', 'inc', 'views_slideshow_cycle.theme');
_views_slideshow_cycle_preprocess_views_slideshow_slide_counter($vars);
}
<?php
/**
* @file
* Theme & preprocess functions for the Views Slideshow: cycle module.
*/
use Drupal\Component\Utility\Html;
/**
* Views Slideshow: Theme the main frame wrapper.
*
* @ingroup vss_theme
*/
function template_preprocess_views_slideshow_cycle_main_frame(&$vars) {
$settings = $vars['settings'];
$rows = $vars['rows'];
$vss_id = $vars['vss_id'];
// Cast the strings into int or bool as necessary.
$new_settings = [];
foreach ($settings as $key => $value) {
if (is_string($value)) {
$value = str_replace("\n", ' ', $value);
$value = trim($value);
if (is_numeric($value)) {
$value = (int) $value;
}
elseif (strtolower($value) == 'true') {
$value = TRUE;
}
elseif (strtolower($value) == 'false') {
$value = FALSE;
}
}
$new_settings[$key] = $value;
}
$num_divs = count($rows);
if ($settings['items_per_slide_first']) {
$num_divs -= $settings['items_per_slide_first_number'];
$num_divs = $num_divs / $settings['items_per_slide'];
$num_divs += 1;
}
else {
$num_divs = $num_divs / $settings['items_per_slide'];
}
$settings = array_merge(
[
'num_divs' => ceil($num_divs),
'id_prefix' => '#views_slideshow_cycle_main_',
'div_prefix' => '#views_slideshow_cycle_div_',
'vss_id' => $vss_id,
],
$new_settings
);
// We need to go through the current js setting values to make sure the one we
// want to add is not already there. If it is already there then append -[num]
// to the id to make it unique.
$slideshow_count = 1;
global $_views_slideshow_processedCycles;
if (is_array($_views_slideshow_processedCycles)) {
foreach ($_views_slideshow_processedCycles as $processedCycle) {
if (stristr($processedCycle, '#views_slideshow_cycle_main_' . $vss_id)) {
$slideshow_count++;
}
}
}
if ($slideshow_count > 1) {
$vss_id .= '-' . $slideshow_count;
$settings['vss_id'] = $vss_id;
}
// Load the json2 library.
if (!empty($settings['advanced_options'])) {
$vars['#attached']['library'][] = 'views_slideshow_cycle/json2';
}
// Load the pause library.
if (!empty($settings['pause_in_middle'])) {
$vars['#attached']['library'][] = 'views_slideshow_cycle/jquery_pause';
}
// Load jQuery Cycle library.
$vars['#attached']['library'][] = 'views_slideshow_cycle/jquery_cycle';
// Load our custom cycle library.
$vars['#attached']['library'][] = 'views_slideshow_cycle/views_slideshow_cycle';
$vars['#attached']['drupalSettings']['viewsSlideshowCycle']['#views_slideshow_cycle_main_' . $vss_id] = $settings;
$_views_slideshow_processedCycles['#views_slideshow_cycle_main_' . $vss_id] = '#views_slideshow_cycle_main_' . $vss_id;
// Add hover intent library.
if ($settings['pause']) {
$vars['#attached']['library'][] = 'views_slideshow/jquery_hoverIntent';
}
// Add the slideshow elements.
$vars['attributes']['class'][] = 'views_slideshow_cycle_teaser_section';
$vars['items_per_slide'] = $settings['items_per_slide'];
$items = [];
$index = 0;
$vars['rendered_rows'] = [];
foreach ($rows as $count => $item) {
$items[] = $item;
if ($settings['items_per_slide_first'] && empty($vars['rendered_rows'])) {
if (count($items) == $settings['items_per_slide_first_number'] || $count == (count($rows) - 1)) {
$vars['rendered_rows'][] = [
'#theme' => $vars['view']->buildThemeFunctions('views_slideshow_cycle_main_frame_row'),
'#vss_id' => $vss_id,
'#items' => $items,
'#count' => $index,
'#view' => $vars['view'],
];
$items = [];
$index++;
}
}
elseif (count($items) == $settings['items_per_slide'] || $count == (count($rows) - 1)) {
$vars['rendered_rows'][] = [
'#theme' => $vars['view']->buildThemeFunctions('views_slideshow_cycle_main_frame_row'),
'#vss_id' => $vss_id,
'#items' => $items,
'#count' => $index,
'#view' => $vars['view'],
];
$items = [];
$index++;
}
}
}
/**
* Views Slideshow slideshow rows.
*
* @ingroup vss_theme
*/
function template_preprocess_views_slideshow_cycle_main_frame_row(&$vars) {
$current = $vars['count'] + 1;
$vars['attributes']['class'][] = 'views_slideshow_cycle_slide';
$vars['attributes']['class'][] = 'views_slideshow_slide views-row-' . $current;
if ($vars['count']) {
$vars['attributes']['class'][] = 'views_slideshow_cycle_hidden';
}
$vars['attributes']['class'][] = ($vars['count'] % 2) ? 'views-row-even' : 'views-row-odd';
$vars['rendered_items'] = [];
foreach ($vars['items'] as $item_count => $item) {
$vars['rendered_items'][] = [
'#theme' => $vars['view']->buildThemeFunctions('views_slideshow_cycle_main_frame_row_item'),
'#item' => $item,
'#item_count' => $item_count,
'#count' => $vars['count'],
'#view' => $vars['view'],
'#length' => count($vars['view']->result),
];
}
}
/**
* Views Slideshow slideshow row items.
*
* @ingroup vss_theme
*/
function template_preprocess_views_slideshow_cycle_main_frame_row_item(&$vars) {
$vars['attributes']['class'][] = 'views-row views-row-' . $vars['count'];
$vars['attributes']['class'][] = ($vars['count'] % 2) ? 'views-row-even' : 'views-row-odd';
if ($vars['count'] == 0) {
$vars['attributes']['class'][] = 'views-row-first';
}
elseif ($vars['count'] == $vars['length'] - 1) {
$vars['attributes']['class'][] = 'views-row-last';
}
// Support custom row classes.
if ($row_class = $vars['view']->style_plugin->getRowClass($vars['count'])) {
$vars['attributes']['class'][] = $row_class;
}
}
/**
* Implements hook_preprocess_views_slideshow_pager_fields().
*
* @ingroup vss_theme
*/
function _views_slideshow_cycle_preprocess_views_slideshow_pager_fields(&$vars) {
$slide_count = count($vars['view']->result);
$options = $vars['view']->style_plugin->options['views_slideshow_cycle'];
$items_per_slide = $options['items_per_slide'];
if ($vars['settings']['hide_on_single_slide'] && $slide_count == 1) {
return;
}
$vars['rendered_field_items'] = [];
for ($slide = 0, $count = 0; $slide < $slide_count; $count++) {
$rendered_fields = [];
foreach ($vars['settings']['views_slideshow_pager_fields']['views_slideshow_pager_fields_fields'] as $field => $use) {
if ($use !== 0 && is_object($vars['view']->field[$field])) {
$rendered_fields[] = [
'#theme' => $vars['view']->buildThemeFunctions('views_slideshow_pager_field_field'),
'#view' => $vars['view'],
'#label' => $vars['view']->field[$field]->options['label'],
'#output' => $vars['view']->style_plugin->getField($slide, $field),
'#css_identifier' => Html::cleanCssIdentifier($vars['view']->field[$field]->field),
];
}
}
if (empty($vars['rendered_field_items']) && $options['items_per_slide_first']) {
$slide += $options['items_per_slide_first_number'];
}
elseif ($options['items_per_slide']) {
$slide += $options['items_per_slide'];
}
else {
$slide += 1;
}
$vars['rendered_field_items'][] = [
'#theme' => $vars['view']->buildThemeFunctions('views_slideshow_pager_field_item'),
'#vss_id' => $vars['vss_id'],
'#item' => $rendered_fields,
'#count' => $count,
'#location' => $vars['location'],
];
}
}
/**
* Implements hook_preprocess_views_slideshow_slide_counter().
*
* @ingroup vss_theme
*/
function _views_slideshow_cycle_preprocess_views_slideshow_slide_counter(&$vars) {
$options = $vars['view']->style_plugin->options['views_slideshow_cycle'];
if ($options['items_per_slide_first']) {
$slide_count = $vars['slide_count'] - $options['items_per_slide_first_number'];
$slide_count = $slide_count / $options['items_per_slide'];
$slide_count += 1;
}
else {
$slide_count = $vars['slide_count'] / $options['items_per_slide'];
}
$vars['slide_count'] = ceil($slide_count);
}
<?php
namespace Drupal\views_slideshow\Annotation;
use Drupal\Component\Annotation\Plugin;
/**
* Defines a slideshow skin annotation object.
*
* @Annotation
*/
class ViewsSlideshowSkin extends Plugin {
/**
* The plugin ID.
*
* @var string
*/
public $id;
/**
* The human-readable name of the slideshow skin.
*
* @var \Drupal\Core\Annotation\Translation
*
* @ingroup plugin_translatable
*/
public $label;
/**
* A list of libraries this slideshow skin needs to attach.
*
* @var string[]
*/
public $libraries;
}
<?php
namespace Drupal\views_slideshow\Annotation;
use Drupal\Component\Annotation\Plugin;
/**
* Defines a slideshow type annotation object.
*
* @Annotation
*/
class ViewsSlideshowType extends Plugin {
/**
* The plugin ID.
*
* @var string
*/
public $id;
/**
* The human-readable name of the slideshow type.
*
* @var \Drupal\Core\Annotation\Translation
*
* @ingroup plugin_translatable
*/
public $label;
/**
* A list of actions this slideshow type accepts.
*
* @var string[]
*/
public $accepts;
/**
* A list of actions this slideshow type implements.
*
* @var string[]
*/
public $calls;
}
<?php
namespace Drupal\views_slideshow\Annotation;
use Drupal\Component\Annotation\Plugin;
/**
* Defines a widget annotation object.
*
* @Annotation
*/
class ViewsSlideshowWidget extends Plugin {
/**
* The plugin ID.
*
* @var string
*/
public $id;
/**
* The human-readable name of the widget.
*
* @var \Drupal\Core\Annotation\Translation
*
* @ingroup plugin_translatable
*/
public $label;
/**
* The widget type used by the widget.
*
* @var string
*/
public $type;
}
<?php
namespace Drupal\views_slideshow\Annotation;
use Drupal\Component\Annotation\Plugin;
/**
* Defines a widget type annotation object.
*
* @Annotation
*/
class ViewsSlideshowWidgetType extends Plugin {
/**
* The plugin ID.
*
* @var string
*/
public $id;
/**
* The human-readable name of the widget type.
*
* @var \Drupal\Core\Annotation\Translation
*
* @ingroup plugin_translatable
*/
public $label;
/**
* A list of actions this widget type accepts.
*
* @var array
*/
public $accepts;
/**
* A list of actions this widget type implements.
*
* @var array
*/
public $calls;
}
<?php
namespace Drupal\views_slideshow;
/**
* Provides a class to manipulate addons names.
*/
class FormatAddonsName implements FormatAddonsNameInterface {
/**
* Format callback to move from underscore separated words to camelCase.
*/
public function format($subject) {
return preg_replace_callback('/_(.?)/', function ($matches) {
if (isset($matches[1])) {
return strtoupper($matches[1]);
}
}, $subject);
}
}
<?php
namespace Drupal\views_slideshow;
/**
* Provides a class for CRUD operations on path aliases.
*/
interface FormatAddonsNameInterface {
/**
* Format callback manipulate addons names.
*/
public function format($subject);
}
<?php
namespace Drupal\views_slideshow\Plugin\ViewsSlideshowSkin;
use Drupal\views_slideshow\ViewsSlideshowSkinBase;
/**
* Provides a default basic skin.
*
* @ViewsSlideshowSkin(
* id = "default",
* label = @Translation("Default"),
* libraries = {}
* )
*/
class DefaultSkin extends ViewsSlideshowSkinBase {}
<?php
namespace Drupal\views_slideshow\Plugin\ViewsSlideshowWidget;
use Drupal\views_slideshow\ViewsSlideshowWidgetBase;
/**
* Provides some controls in text format.
*
* @ViewsSlideshowWidget(
* id = "views_slideshow_controls_text",
* type = "views_slideshow_controls",
* label = @Translation("Text"),
* )
*/
class ControlsText extends ViewsSlideshowWidgetBase {
}
<?php
namespace Drupal\views_slideshow\Plugin\ViewsSlideshowWidget;
use Drupal\Core\Form\FormStateInterface;
use Drupal\views_slideshow\ViewsSlideshowWidgetBase;
/**
* Provides a pager using bullets.
*
* @ViewsSlideshowWidget(
* id = "views_slideshow_pager_bullets",
* type = "views_slideshow_pager",
* label = @Translation("Bullets"),
* )
*/
class PagerBullets extends ViewsSlideshowWidgetBase {
/**
* {@inheritdoc}
*/
public function defaultConfiguration() {
return [
'views_slideshow_pager_bullets_hover' => ['default' => 0],
];
}
/**
* {@inheritdoc}
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
// Add field to see if they would like to activate slide and pause on pager
// hover.
$form['views_slideshow_pager_bullets_hover'] = [
'#type' => 'checkbox',
'#title' => $this->t('Activate Slide and Pause on Pager Hover'),
'#default_value' => $this->getConfiguration()['views_slideshow_pager_bullets_hover'],
'#description' => $this->t('Should the slide be activated and paused when hovering over a pager item.'),
'#states' => [
'visible' => [
':input[name="' . $this->getConfiguration()['dependency'] . '[enable]"]' => ['checked' => TRUE],
':input[name="' . $this->getConfiguration()['dependency'] . '[type]"]' => ['value' => 'views_slideshow_pager_bullets'],
],
],
];
return $form;
}
}
<?php
namespace Drupal\views_slideshow\Plugin\ViewsSlideshowWidget;
use Drupal\Core\Form\FormStateInterface;
use Drupal\views_slideshow\ViewsSlideshowWidgetBase;
/**
* Provides a pager using fields.
*
* @ViewsSlideshowWidget(
* id = "views_slideshow_pager_fields",
* type = "views_slideshow_pager",
* label = @Translation("Fields"),
* )
*/
class PagerFields extends ViewsSlideshowWidgetBase {
/**
* {@inheritdoc}
*/
public function defaultConfiguration() {
return [
'views_slideshow_pager_fields_fields' => ['default' => []],
'views_slideshow_pager_fields_hover' => ['default' => 0],
];
}
/**
* {@inheritdoc}
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
// Settings for fields pager.
$options = [];
// Get each field and it's name.
foreach ($this->getConfiguration()['view']->display_handler->getHandlers('field') as $field_name => $field) {
$options[$field_name] = $field->adminLabel();
}
// Need to wrap this so it indents correctly.
$form['views_slideshow_pager_fields_wrapper'] = [
'#markup' => '<div class="vs-dependent">',
];
// Add ability to choose which fields to show in the pager.
$form['views_slideshow_pager_fields_fields'] = [
'#type' => 'checkboxes',
'#title' => $this->t('Pager fields'),
'#options' => $options,
'#default_value' => $this->getConfiguration()['views_slideshow_pager_fields_fields'],
'#description' => $this->t('Choose the fields that will appear in the pager.'),
'#states' => [
'visible' => [
':input[name="' . $this->getConfiguration()['dependency'] . '[enable]"]' => ['checked' => TRUE],
':input[name="' . $this->getConfiguration()['dependency'] . '[type]"]' => ['value' => 'views_slideshow_pager_fields'],
],
],
];
// Add field to see if they would like to activate slide and pause on pager
// hover.
$form['views_slideshow_pager_fields_hover'] = [
'#type' => 'checkbox',
'#title' => $this->t('Activate Slide and Pause on Pager Hover'),
'#default_value' => $this->getConfiguration()['views_slideshow_pager_fields_hover'],
'#description' => $this->t('Should the slide be activated and paused when hovering over a pager item.'),
'#states' => [
'visible' => [
':input[name="' . $this->getConfiguration()['dependency'] . '[enable]"]' => ['checked' => TRUE],
':input[name="' . $this->getConfiguration()['dependency'] . '[type]"]' => ['value' => 'views_slideshow_pager_fields'],
],
],
];
$form['views_slideshow_pager_fields_wrapper_close'] = [
'#markup' => '</div>',
];
return $form;
}
/**
* {@inheritdoc}
*/
public function checkCompatiblity($view) {
return $view->getStyle()->usesFields();
}
}
<?php
namespace Drupal\views_slideshow\Plugin\ViewsSlideshowWidgetType;
use Drupal\Core\Form\FormStateInterface;
use Drupal\views_slideshow\ViewsSlideshowWidgetTypeBase;
/**
* Provides a control widget type.
*
* @ViewsSlideshowWidgetType(
* id = "views_slideshow_controls",
* label = @Translation("Controls"),
* accepts = {"pause" = {"required" = TRUE}, "play" = {"required" = TRUE}},
* calls = {"nextSlide", "pause", "play", "previousSlide"}
* )
*/
class Controls extends ViewsSlideshowWidgetTypeBase {
/**
* {@inheritdoc}
*/
public function defaultConfiguration() {
return parent::defaultConfiguration() + [
'type' => ['default' => 0],
];
}
/**
* {@inheritdoc}
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$form = parent::buildConfigurationForm($form, $form_state);
/* @var \Drupal\Component\Plugin\PluginManagerInterface */
$widgetManager = \Drupal::service('plugin.manager.views_slideshow.widget');
$widgets = $widgetManager->getDefinitions($this->getPluginId());
if (!empty($widgets)) {
$options = [];
foreach ($widgets as $widgetId => $widgetInfo) {
$options[$widgetId] = $widgetInfo['label'];
}
// Need to wrap this so it indents correctly.
$form['views_slideshow_controls_wrapper'] = [
'#markup' => '<div class="vs-dependent">',
];
// Create the widget type field.
$form['type'] = [
'#type' => 'select',
'#title' => $this->t('Controls Type'),
'#description' => $this->t('Style of the controls'),
'#default_value' => $this->getConfiguration()['type'],
'#options' => $options,
'#states' => [
'visible' => [
':input[name="' . $this->getConfiguration()['dependency'] . '[enable]"]' => ['checked' => TRUE],
],
],
];
foreach ($widgets as $widget_id => $widget_info) {
// Get the current configuration of this widget.
$configuration = [];
if (!empty($this->getConfiguration()[$widget_id])) {
$configuration = $this->getConfiguration()[$widget_id];
}
$configuration['dependency'] = $this->getConfiguration()['dependency'];
$instance = $widgetManager->createInstance($widget_id, $configuration);
// Get the configuration form of this widget type.
$form[$widget_id] = isset($form[$widget_id]) ? $form[$widget_id] : [];
$form[$widget_id] = $instance->buildConfigurationForm($form[$widget_id], $form_state);
}
$form['controls_wrapper_close'] = [
'#markup' => '</div>',
];
}
else {
$form['enable_controls'] = [
'#markup' => 'There are no controls available.',
];
}
return $form;
}
}
<?php
namespace Drupal\views_slideshow\Plugin\ViewsSlideshowWidgetType;
use Drupal\views_slideshow\ViewsSlideshowWidgetTypeBase;
/**
* Provides a counter widget type.
*
* @ViewsSlideshowWidgetType(
* id = "views_slideshow_slide_counter",
* label = @Translation("Slide counter"),
* accepts = {
* "transitionBegin" = {"required" = TRUE},
* "goToSlide",
* "previousSlide",
* "nextSlide"
* },
* calls = {}
* )
*/
class Counter extends ViewsSlideshowWidgetTypeBase {
}
<?php
namespace Drupal\views_slideshow\Plugin\ViewsSlideshowWidgetType;
use Drupal\Core\Form\FormStateInterface;
use Drupal\views_slideshow\ViewsSlideshowWidgetTypeBase;
/**
* Provides a pager widget type.
*
* @ViewsSlideshowWidgetType(
* id = "views_slideshow_pager",
* label = @Translation("Pager"),
* accepts = {
* "transitionBegin" = {"required" = TRUE},
* "goToSlide",
* "previousSlide",
* "nextSlide"
* },
* calls = {"goToSlide", "pause", "play"}
* )
*/
class Pager extends ViewsSlideshowWidgetTypeBase {
/**
* {@inheritdoc}
*/
public function defaultConfiguration() {
$options = parent::defaultConfiguration() + [
'type' => ['default' => 0],
'views_slideshow_pager_numbered_hover' => ['default' => 0],
'views_slideshow_pager_numbered_click_to_page' => ['default' => 0],
'views_slideshow_pager_thumbnails_hover' => ['default' => 0],
'views_slideshow_pager_thumbnails_click_to_page' => ['default' => 0],
];
/* @var \Drupal\Component\Plugin\PluginManagerInterface */
$widgetManager = \Drupal::service('plugin.manager.views_slideshow.widget');
// Get default configuration of all Pager plugins.
foreach ($widgetManager->getDefinitions($this->getPluginId()) as $widget_id => $widget_info) {
$options += $widgetManager->createInstance($widget_id, [])->defaultConfiguration();
}
return $options;
}
/**
* {@inheritdoc}
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$form = parent::buildConfigurationForm($form, $form_state);
$view = $form_state->get('view')->get('executable');
/* @var \Drupal\Component\Plugin\PluginManagerInterface */
$widgetManager = \Drupal::service('plugin.manager.views_slideshow.widget');
// Determine if this widget type is compatible with any slideshow type.
$widgets = [];
foreach ($widgetManager->getDefinitions($this->getPluginId()) as $widget_id => $widget_info) {
if ($widgetManager->createInstance($widget_id, [])->checkCompatiblity($view)) {
$widgets[$widget_id] = $widget_info['label'];
}
}
if (!empty($widgets)) {
// Need to wrap this so it indents correctly.
$form['views_slideshow_pager_wrapper'] = [
'#markup' => '<div class="vs-dependent">',
];
// Create the widget type field.
$form['type'] = [
'#type' => 'select',
'#title' => $this->t('Pager Type'),
'#description' => $this->t('Style of the pager'),
'#default_value' => $this->getConfiguration()['type'],
'#options' => $widgets,
'#states' => [
'visible' => [
':input[name="' . $this->getConfiguration()['dependency'] . '[enable]"]' => ['checked' => TRUE],
],
],
];
foreach ($widgetManager->getDefinitions() as $widget_id => $widget_info) {
// Get the current configuration of this widget.
$configuration = [];
if (!empty($this->getConfiguration()[$widget_id])) {
$configuration = $this->getConfiguration()[$widget_id];
}
$configuration['dependency'] = $this->getConfiguration()['dependency'];
$configuration['view'] = $view;
$instance = $widgetManager->createInstance($widget_id, $configuration);
// Get the configuration form of this widget type.
$form[$widget_id] = isset($form[$widget_id]) ? $form[$widget_id] : [];
$form[$widget_id] = $instance->buildConfigurationForm($form[$widget_id], $form_state);
}
$form['views_slideshow_pager_wrapper_close'] = [
'#markup' => '</div>',
];
}
else {
$form['enable_pager'] = [
'#markup' => 'There are no pagers available.',
];
}
return $form;
}
}
<?php
namespace Drupal\views_slideshow\Tests\Plugin;
use Drupal\views\Entity\View;
use Drupal\Tests\views\Functional\ViewTestBase;
use Drupal\views\Tests\ViewTestData;
/**
* Tests the slideshow style views plugin.
*
* @group views
*/
class StyleSlideshowTest extends ViewTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = [
'views',
'views_slideshow',
'views_slideshow_cycle',
'views_test_config',
'views_slideshow_test',
];
/**
* Views used by this test.
*
* @var array
*/
public static $testViews = ['test_style_slideshow'];
/**
* {@inheritdoc}
*/
protected function setUp($import_test_views = TRUE) {
parent::setUp();
$this->enableViewsTestModule();
if ($import_test_views) {
ViewTestData::createTestViews(get_class($this), ['views_slideshow_test']);
}
}
/**
* Test slideshow display.
*/
public function testSlideshow() {
$this->drupalGet('test-style-slideshow');
$result = $this->cssSelect('.views_slideshow_main');
$this->assertEqual(count($result), 1, 'Slideshow displayed on page');
}
/**
* Test slideshow control widgets.
*/
public function testSlideshowWidgets() {
$this->drupalGet('test-style-slideshow');
// Ensure no controls are displayed.
$this->assertFalse(count($this->cssSelect('.views-slideshow-controls-top')));
$this->assertFalse(count($this->cssSelect('.views-slideshow-controls-bottom')));
// Test top widget position.
$view = View::load('test_style_slideshow');
$display = &$view->getDisplay('default');
$display['display_options']['style']['options']['widgets'] = [
'top' => [
'views_slideshow_controls' => [
'enable' => TRUE,
'weight' => 1,
'hide_on_single_slide' => 0,
'type' => 'views_slideshow_controls_text',
],
],
];
$view->save();
$this->drupalGet('test-style-slideshow');
$this->assertTrue(count($this->cssSelect('.views-slideshow-controls-top')));
$this->assertFalse(count($this->cssSelect('.views-slideshow-controls-bottom')));
// Test bottom widget position.
$view = View::load('test_style_slideshow');
$display = &$view->getDisplay('default');
$display['display_options']['style']['options']['widgets'] = [
'bottom' => [
'views_slideshow_controls' => [
'enable' => TRUE,
'weight' => 1,
'hide_on_single_slide' => 0,
'type' => 'views_slideshow_controls_text',
],
],
'top' => [],
];
$view->save();
$this->drupalGet('test-style-slideshow');
$this->assertFalse(count($this->cssSelect('.views-slideshow-controls-top')));
$this->assertTrue(count($this->cssSelect('.views-slideshow-controls-bottom')));
}
}
<?php
namespace Drupal\views_slideshow;
use Drupal\Component\Plugin\PluginBase;
/**
* Provides basic functionality for Views slideshow skins.
*/
abstract class ViewsSlideshowSkinBase extends PluginBase implements ViewsSlideshowSkinInterface {
/**
* {@inheritdoc}
*/
public function getLabel() {
return $this->pluginDefinition['label'];
}
/**
* {@inheritdoc}
*/
public function getClass() {
return $this->pluginDefinition['id'];
}
/**
* {@inheritdoc}
*/
public function getLibraries() {
return $this->pluginDefinition['libraries'];
}
}
<?php
namespace Drupal\views_slideshow;
/**
* Provides an interface for Views slideshow skins.
*/
interface ViewsSlideshowSkinInterface {
/**
* Returns a array of libraries to attach when the skin is used.
*
* @return array
* The libraries to be attached.
*/
public function getLibraries();
/**
* Returns a class to be added to templates.
*
* @return string
* The class name.
*/
public function getClass();
}
<?php
namespace Drupal\views_slideshow;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Plugin\DefaultPluginManager;
/**
* Manager for Views Slideshow Skin plugins.
*/
class ViewsSlideshowSkinPluginManager extends DefaultPluginManager {
/**
* Constructs a new ViewsSlideshowSkinPluginManager.
*
* @param \Traversable $namespaces
* An object that implements \Traversable which contains the root paths
* keyed by the corresponding namespace to look for plugin implementations.
* @param \Drupal\Core\Cache\CacheBackendInterface $cache_backend
* Cache backend instance to use.
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* The module handler.
*/
public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) {
parent::__construct('Plugin/ViewsSlideshowSkin', $namespaces, $module_handler, 'Drupal\views_slideshow\ViewsSlideshowSkinInterface', 'Drupal\views_slideshow\Annotation\ViewsSlideshowSkin');
$this->alterInfo('views_slideshow_skin_info');
$this->setCacheBackend($cache_backend, 'views_slideshow_skin');
}
}
<?php
namespace Drupal\views_slideshow;
use Drupal\Component\Plugin\PluginBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
/**
* Provides basic functionality for Views slideshow types.
*/
abstract class ViewsSlideshowTypeBase extends PluginBase implements ViewsSlideshowTypeInterface {
use StringTranslationTrait;
/**
* {@inheritdoc}
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->setConfiguration($configuration);
}
/**
* {@inheritdoc}
*/
public function getTitle() {
return $this->pluginDefinition['title'];
}
/**
* {@inheritdoc}
*/
public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {
}
/**
* {@inheritdoc}
*/
public function defaultConfiguration() {
return [];
}
/**
* {@inheritdoc}
*/
public function getConfiguration() {
return [
'id' => $this->getPluginId(),
] + $this->configuration;
}
/**
* {@inheritdoc}
*/
public function setConfiguration(array $configuration) {
$this->configuration = $configuration + $this->defaultConfiguration();
return $this;
}
/**
* {@inheritdoc}
*/
public function calculateDependencies() {
return [];
}
/**
* {@inheritdoc}
*/
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
}
}
<?php
namespace Drupal\views_slideshow;
use Drupal\Component\Plugin\ConfigurableInterface;
use Drupal\Component\Plugin\DependentPluginInterface;
use Drupal\Component\Plugin\PluginInspectionInterface;
use Drupal\Core\Plugin\PluginFormInterface;
/**
* Provides an interface for Views slideshow types.
*/
interface ViewsSlideshowTypeInterface extends PluginInspectionInterface, ConfigurableInterface, PluginFormInterface, DependentPluginInterface {}
<?php
namespace Drupal\views_slideshow;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Plugin\DefaultPluginManager;
/**
* Manager for Views Slideshow Type plugins.
*/
class ViewsSlideshowTypePluginManager extends DefaultPluginManager {
/**
* Constructs a new ViewsSlideshowTypePluginManager.
*
* @param \Traversable $namespaces
* An object that implements \Traversable which contains the root paths
* keyed by the corresponding namespace to look for plugin implementations.
* @param \Drupal\Core\Cache\CacheBackendInterface $cache_backend
* Cache backend instance to use.
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* The module handler.
*/
public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) {
parent::__construct('Plugin/ViewsSlideshowType', $namespaces, $module_handler, 'Drupal\views_slideshow\ViewsSlideshowTypeInterface', 'Drupal\views_slideshow\Annotation\ViewsSlideshowType');
$this->alterInfo('views_slideshow_type_info');
$this->setCacheBackend($cache_backend, 'views_slideshow_type');
}
}
<?php
namespace Drupal\views_slideshow;
use Drupal\Component\Plugin\PluginBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
/**
* Provides basic functionality for Views slideshow widgets.
*/
abstract class ViewsSlideshowWidgetBase extends PluginBase implements ViewsSlideshowWidgetInterface {
use StringTranslationTrait;
/**
* {@inheritdoc}
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->setConfiguration($configuration);
}
/**
* {@inheritdoc}
*/
public function getTitle() {
return $this->pluginDefinition['title'];
}
/**
* {@inheritdoc}
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
return [];
}
/**
* {@inheritdoc}
*/
public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {
}
/**
* {@inheritdoc}
*/
public function defaultConfiguration() {
return [];
}
/**
* {@inheritdoc}
*/
public function getConfiguration() {
return [
'id' => $this->getPluginId(),
] + $this->configuration;
}
/**
* {@inheritdoc}
*/
public function setConfiguration(array $configuration) {
$this->configuration = $configuration + $this->defaultConfiguration();
return $this;
}
/**
* {@inheritdoc}
*/
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
}
/**
* {@inheritdoc}
*/
public function calculateDependencies() {
return [];
}
/**
* {@inheritdoc}
*/
public function checkCompatiblity($view) {
return TRUE;
}
}
<?php
namespace Drupal\views_slideshow;
use Drupal\Component\Plugin\ConfigurableInterface;
use Drupal\Component\Plugin\DependentPluginInterface;
use Drupal\Component\Plugin\PluginInspectionInterface;
use Drupal\Core\Plugin\PluginFormInterface;
/**
* Provides an interface for a Views slideshow widget.
*/
interface ViewsSlideshowWidgetInterface extends PluginInspectionInterface, ConfigurableInterface, PluginFormInterface, DependentPluginInterface {
/**
* Check if the widget is compatible with the current view configuration.
*
* @return bool
* TRUE if the widget is compatible with the view.
*/
public function checkCompatiblity($view);
}
<?php
namespace Drupal\views_slideshow;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Plugin\DefaultPluginManager;
/**
* Manager for Views Slideshow Widget plugins.
*/
class ViewsSlideshowWidgetPluginManager extends DefaultPluginManager {
/**
* Constructs a new ViewsSlideshowWidgetPluginManager.
*
* @param \Traversable $namespaces
* An object that implements \Traversable which contains the root paths
* keyed by the corresponding namespace to look for plugin implementations.
* @param \Drupal\Core\Cache\CacheBackendInterface $cache_backend
* Cache backend instance to use.
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* The module handler.
*/
public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) {
parent::__construct('Plugin/ViewsSlideshowWidget', $namespaces, $module_handler, 'Drupal\views_slideshow\ViewsSlideshowWidgetInterface', 'Drupal\views_slideshow\Annotation\ViewsSlideshowWidget');
$this->alterInfo('views_slideshow_widget_info');
$this->setCacheBackend($cache_backend, 'views_slideshow_widget');
}
/**
* Gets the definition of all or filtered plugins for this type.
*
* @param mixed $type
* A string or an array of types to filter on.
*
* @return mixed
* An array of plugin definitions. Keys are plugin IDs.
*/
public function getDefinitions($type = NULL) {
$definitions = parent::getDefinitions();
// Filter widgets to keep only required types.
if (!empty($type)) {
foreach ($definitions as $widgetId => $widgetInfo) {
if ((is_array($type) && !in_array($widgetInfo['type'], $type)) || (is_string($type) && $widgetInfo['type'] !== $type)) {
unset($definitions[$widgetId]);
}
}
}
return $definitions;
}
}
<?php
namespace Drupal\views_slideshow;
use Drupal\Component\Plugin\PluginBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
/**
* Base class for a Views slideshow widget type.
*/
abstract class ViewsSlideshowWidgetTypeBase extends PluginBase implements ViewsSlideshowWidgetTypeInterface {
use StringTranslationTrait;
/**
* {@inheritdoc}
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->setConfiguration($configuration);
}
/**
* {@inheritdoc}
*/
public function getTitle() {
return $this->pluginDefinition['title'];
}
/**
* {@inheritdoc}
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
// Add field to see if they would like to hide controls if there is only
// one slide.
$form['hide_on_single_slide'] = [
'#type' => 'checkbox',
'#title' => $this->t('Hide controls if there is only one slide'),
'#default_value' => $this->getConfiguration()['hide_on_single_slide'],
'#description' => $this->t('Should the controls be hidden if there is only one slide.'),
'#states' => [
'visible' => [
':input[name="' . $this->getConfiguration()['dependency'] . '[enable]"]' => ['checked' => TRUE],
],
],
];
return $form;
}
/**
* {@inheritdoc}
*/
public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {
}
/**
* {@inheritdoc}
*/
public function defaultConfiguration() {
return [
'enable' => ['default' => 0],
'weight' => ['default' => 1],
'hide_on_single_slide' => ['default' => 0],
];
}
/**
* {@inheritdoc}
*/
public function getConfiguration() {
return [
'id' => $this->getPluginId(),
] + $this->configuration;
}
/**
* {@inheritdoc}
*/
public function setConfiguration(array $configuration) {
$this->configuration = $configuration + $this->defaultConfiguration();
return $this;
}
/**
* {@inheritdoc}
*/
public function calculateDependencies() {
return [];
}
/**
* {@inheritdoc}
*/
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
}
/**
* {@inheritdoc}
*/
public function checkCompatiblity($slideshow) {
$is_compatible = 1;
// Check if every required accept value in the widget has a
// corresponding calls value in the slideshow.
foreach ($this->pluginDefinition['accepts'] as $accept_key => $accept_value) {
if (is_array($accept_value) && !empty($accept_value['required']) && !in_array($accept_key, $slideshow['calls'])) {
$is_compatible = 0;
break;
}
}
// No need to go through this if it's not compatible.
if ($is_compatible) {
// Check if every required calls value in the widget has a
// corresponding accepts call.
foreach ($this->pluginDefinition['calls'] as $calls_key => $calls_value) {
if (is_array($calls_value) && !empty($calls_value['required']) && !in_array($calls_key, $slideshow['accepts'])) {
$is_compatible = 0;
break;
}
}
}
return $is_compatible;
}
}
<?php
namespace Drupal\views_slideshow;
use Drupal\Component\Plugin\ConfigurableInterface;
use Drupal\Component\Plugin\DependentPluginInterface;
use Drupal\Component\Plugin\PluginInspectionInterface;
use Drupal\Core\Plugin\PluginFormInterface;
/**
* Provides an interface for a Views slideshow widget type.
*/
interface ViewsSlideshowWidgetTypeInterface extends PluginInspectionInterface, ConfigurableInterface, PluginFormInterface, DependentPluginInterface {
/**
* Check if the widget type is compatible with the selected slideshow.
*
* @return bool
* TRUE if the widget type is compatible with the slideshow.
*/
public function checkCompatiblity($slideshow);
}
<?php
namespace Drupal\views_slideshow;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Plugin\DefaultPluginManager;
/**
* Manager for Views Slideshow widget type plugins.
*/
class ViewsSlideshowWidgetTypePluginManager extends DefaultPluginManager {
/**
* Constructs a new ViewsSlideshowWidgetTypePluginManager.
*
* @param \Traversable $namespaces
* An object that implements \Traversable which contains the root paths
* keyed by the corresponding namespace to look for plugin implementations.
* @param \Drupal\Core\Cache\CacheBackendInterface $cache_backend
* Cache backend instance to use.
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* The module handler.
*/
public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) {
parent::__construct('Plugin/ViewsSlideshowWidgetType', $namespaces, $module_handler, 'Drupal\views_slideshow\ViewsSlideshowWidgetTypeInterface', 'Drupal\views_slideshow\Annotation\ViewsSlideshowWidgetType');
$this->alterInfo('views_slideshow_widget_type_info');
$this->setCacheBackend($cache_backend, 'views_slideshow_widget_type');
}
}
{#
/**
* @file
* Default theme implementation for a views slideshow text next control.
*
* Available variables:
* - classes: Classes to apply to the control.
* - vss_id: The slideshow's id.
*
* @see template_preprocess_views_slideshow_controls_text_next()
*
* @ingroup vss_templates
*/
#}
<span id="views_slideshow_controls_text_next_{{ vss_id }}" {{ attributes.addClass(classes) }}>
<a href="#">{{ 'Next'|t }}</a>
</span>
{#
/**
* @file
* Default theme implementation for a views slideshow text pause control.
*
* Available variables:
* - classes: Classes to apply to the control.
* - start_text: Text to display while playing.
* - vss_id: The slideshow's id.
*
* @see template_preprocess_views_slideshow_controls_text_pause()
*
* @ingroup vss_templates
*/
#}
<span id="views_slideshow_controls_text_pause_{{ vss_id }}" {{ attributes.addClass(classes) }}>
<a href="#">{{ start_text }}</a>
</span>
{#
/**
* @file
* Default theme implementation for a views slideshow text previous control.
*
* Available variables:
* - classes: Classes to apply to the control.
* - vss_id: The slideshow's id.
*
* @see template_preprocess_views_slideshow_controls_text_previous()
*
* @ingroup vss_templates
*/
#}
<span id="views_slideshow_controls_text_previous_{{ vss_id }}" {{ attributes.addClass(classes) }}>
<a href="#">{{ 'Previous'|t }}</a>
</span>
{#
/**
* @file
* Default theme implementation for a views slideshow text controls.
*
* Available variables:
* - classes: Classes to apply to the control.
* - rendered_control_next: Text next control.
* - rendered_control_pause: Text pause control.
* - rendered_control_previous: Text previous control.
* - vss_id: The slideshow's id.
*
* @see template_preprocess_views_slideshow_controls_text()
*
* @ingroup vss_templates
*/
#}
<div id="views_slideshow_controls_text_{{ vss_id }}" {{ attributes.addClass(classes) }}>
{{ rendered_control_previous }}
{{ rendered_control_pause }}
{{ rendered_control_next }}
</div>
{#
/**
* @file
* Default theme implementation for a views slideshow controls.
*
* Available variables:
* - widget: The rendered widget.
*
* @see template_preprocess_views_slideshow_controls_widget()
*
* @ingroup vss_templates
*/
#}
{{ widget }}
{#
/**
* @file
* Default theme implementation for a views slideshow pager item.
*
* Available variables:
* - plugin: The main frame slideshow plugin.
* - slides: The slides.
* - vss_id: The slideshow's id.
*
* @ingroup vss_templates
*/
#}
<div id="{{ plugin }}_main_{{ vss_id }}" class="{{ plugin }}_main views_slideshow_main">
{{ slides }}
</div>
{#
/**
* @file
* Default theme implementation for a views slideshow bullets pager.
*
* Available variables:
* - bullet_items: Renderable array of pager items
*
* @ingroup vss_templates
*/
#}
{{ bullet_items }}
{#
/**
* @file
* Default theme implementation for a views slideshow pager field field data.
*
* Available variables:
* - css_identifier: css identified for the field..
* - label: Label for the field.
* - output: The field data.
*
* @see template_preprocess_views_slideshow_pager_field_field()
*
* @ingroup vss_templates
*/
#}
<div class="views-field-{{ css_identifier }}">
{% if label %}
<label class="view-label-{{ css_identifier }}">
{{ label }}:
</label>
{% endif %}
<div class="views-content-{{ css_identifier }}">
{{ output }}
</div>
</div>
{#
/**
* @file
* Default theme implementation for a views slideshow pager item.
*
* Available variables:
* - classes: Classes to apply to the element.
* - count: The page number.
* - location: Location of pager.
* - item: Rendered field(s) making up item.
* - vss_id: The slideshow's id.
*
* @see template_preprocess_views_slideshow_pager_field_item()
*
* @ingroup vss_templates
*/
#}
<div id="views_slideshow_pager_field_item_{{ location }}_{{ vss_id }}_{{ count }}" {{ attributes.addClass(classes) }}>
{{ item }}
</div>
{#
/**
* @file
* Default theme implementation for a views slideshow pager item.
*
* Available variables:
* - classes: Classes to apply to the element.
* - rendered_field_items: The individual pager elements.
* - widget_id: The pager id.
*
* @see template_preprocess_views_slideshow_pager_field_item()
*
* @ingroup vss_templates
*/
#}
<div id="{{ widget_id }}" {{ attributes.addClass(classes) }}>
{{ rendered_field_items }}
</div>
{#
/**
* @file
* Default theme implementation for a views slideshow pager.
*
* Available variables:
* - widget: The rendered widget.
*
* @see template_preprocess_views_slideshow_pager_widget()
*
* @ingroup vss_templates
*/
#}
{{ widget }}
{#
/**
* @file
* Default theme implementation for a views slideshow counter.
*
* Available variables:
* - widget: The rendered widget.
*
* @see template_preprocess_views_slideshow_slide_counter_widget()
*
* @ingroup vss_templates
*/
#}
{{ widget }}
{#
/**
* @file
* Default theme implementation for a views slideshow slide counter.
*
* Available variables:
* - classes: Classes to apply to the counter's div element.
* - slide_count: Total number of slides.
* - vss_id: The slideshow's id.
*
* @see template_preprocess_views_slideshow_slide_counter()
*
* @ingroup vss_templates
*/
#}
<div id="views_slideshow_slide_counter_{{ vss_id }}" {{ attributes.addClass(classes) }}>
<span class="num">1</span> {{ 'of'|t }} <span class="total">{{ slide_count }}</span>
</div>
{#
/**
* @file
* Default theme implementation for a views slideshow.
*
* Available variables:
* - bottom_widget_rendered: Widget under the slideshow with controls/data.
* - skin: The skin being applied to the slideshow.
* - slideshow: The slideshow.
* - top_widget_rendered: Widget above the slideshow with controls/data.
*
* @see _views_slideshow_preprocess_views_view_slideshow()
*
* @ingroup vss_templates
*/
#}
{% if slideshow %}
<div class="skin-{{ skin }}">
{% if top_widget_rendered %}
<div class="views-slideshow-controls-top clearfix">
{{ top_widget_rendered }}
</div>
{% endif %}
{{ slideshow }}
{% if bottom_widget_rendered %}
<div class="views-slideshow-controls-bottom clearfix">
{{ bottom_widget_rendered }}
</div>
{% endif %}
</div>
{% endif %}
langcode: en
status: true
dependencies:
module:
- views_slideshow
- views_slideshow_cycle
id: test_style_slideshow
label: ''
module: views
description: ''
tag: ''
base_table: views_test_data
base_field: id
core: 8.x
display:
default:
display_plugin: page
id: default
display_title: Master
position: null
display_options:
path: test-style-slideshow
access:
type: none
options: { }
cache:
type: tag
options: { }
query:
type: views_query
options: { }
exposed_form:
type: basic
options: { }
pager:
type: full
options: { }
style:
type: slideshow
options:
row_class: ''
default_row_class: true
slideshow_skin: default
slideshow_type: views_slideshow_cycle
row:
type: fields
options: { }
fields:
name:
id: name
table: views_test_data
field: name
name: 'Views Slideshow Test Config'
type: module
description: 'Provides default views for tests.'
package: Testing
core: 8.x
core_version_requirement: ^8 || ^9
dependencies:
- drupal:views
- views_slideshow:views_slideshow
- views_slideshow:views_slideshow_cycle
# Information added by Drupal.org packaging script on 2020-09-28
version: '8.x-4.8'
project: 'views_slideshow'
datestamp: 1601309227
<?php
/**
* @file
* Provides API homepage for Views Slideshow.
*/
/**
* Views slide show.
*
* @mainpage Views Slideshow API & Developer Documentation
* Welcome to the Views Slideshow developer's documentation.
*
* Newcomers to Drupal development should read the conceptual information
* in @link https://www.drupal.org/docs/8/api/ Drupal API Introduction @endlink
* or @link https://api.drupal.org/api/drupal/8.2.x Drupal API Docs @endlink.
* The heavily documented
* @link https://api.drupal.org/api/examples/8.x-1.x Example modules @endlink
* may also be helpful.
*
* For tutorials and examples for acheiving specific tasks, also see the
* @link https://drupal.org/docs/8/modules/views-slideshow/developer-tutorials Developer Guide @endlink.
*
* For any comments, support or questions see the
* @link https://drupal.org/project/views_slideshow module page @endlink.
* Also, feel free to comment here if it is specific to one function/file.
*
* - Primary components of Views Slideshow
* - @link vss_theme Theme Functions @endlink
* - @link vss_templates Templates @endlink
* - @link modules/views_slideshow_cycle/views_slideshow_cycle.module Cycle Module @endlink
*/
name: 'Views Slideshow'
type: module
description: 'Provides a View style that displays rows as a jQuery slideshow. This is an API and requires Views Slideshow Cycle or another module that supports the API.'
package: Views
core: 8.x
core_version_requirement: ^8 || ^9
dependencies:
- drupal:views
# Information added by Drupal.org packaging script on 2020-09-28
version: '8.x-4.8'
project: 'views_slideshow'
datestamp: 1601309227
form:
version: VERSION
css:
theme:
css/views_slideshow.css: {}
widget_info:
version: VERSION
js:
js/views_slideshow.js: {}
dependencies:
- core/jquery
- core/drupal
- core/drupalSettings
controls_text:
version: VERSION
css:
theme:
css/controls_text.css: {}
pager_bullets:
version: VERSION
css:
component:
css/views-slideshow-pager-bullets.css: {}
jquery_hoverIntent:
remote: https://github.com/briancherne/jquery-hoverIntent
version: 1.9
license:
name: MIT
gpl-compatible: true
js:
/libraries/jquery.hoverIntent/jquery.hoverIntent.js: {}
dependencies:
- core/jquery
<?php
/**
* @file
* Provides Slideshow style options for Views.
*/
use Drupal\Core\Routing\RouteMatchInterface;
/**
* Implements hook_help().
*/
function views_slideshow_help($route_name, RouteMatchInterface $route_match) {
switch ($route_name) {
// Main module help for the gss module.
case 'help.page.views_slideshow':
$output = '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t('Views Slideshow can be used to create a slideshow of any content (not just images) that can appear in a View. Powered by jQuery, it is heavily customizable: you may choose slideshow settings for each View you create.') . '</p>';
$output .= '<h3>' . t('More Information') . '</h3>';
$output .= '<p>' . t('For more information about this module visit the <a href="@link">Views Slideshow</a> module page.', ['@link' => 'https://www.drupal.org/project/views_slideshow']) . '</p>';
return $output;
}
}
/**
* Implements hook_theme().
*/
function views_slideshow_theme() {
return [
'views_slideshow_main_section' => [
'variables' => [
'vss_id' => NULL,
'slides' => NULL,
'plugin' => NULL,
],
'file' => 'views_slideshow.theme.inc',
],
'views_slideshow_pager_widget' => [
'variables' => [
'vss_id' => NULL,
'view' => NULL,
'settings' => [],
'location' => NULL,
'rows' => [],
],
'file' => 'views_slideshow.theme.inc',
],
'views_slideshow_pager_fields' => [
'variables' => [
'vss_id' => NULL,
'view' => NULL,
'settings' => [],
'location' => NULL,
'attributes' => [],
],
'file' => 'views_slideshow.theme.inc',
],
'views_slideshow_pager_field_field' => [
'variables' => [
'view' => NULL,
'css_identifier' => NULL,
'label' => NULL,
'output' => NULL,
],
'file' => 'views_slideshow.theme.inc',
],
'views_slideshow_pager_field_item' => [
'variables' => [
'vss_id' => NULL,
'item' => NULL,
'count' => NULL,
'location' => NULL,
'length' => NULL,
],
'file' => 'views_slideshow.theme.inc',
],
'views_slideshow_pager_bullets' => [
'variables' => [
'vss_id' => NULL,
'view' => NULL,
'settings' => [],
'location' => NULL,
'attributes' => [],
],
'file' => 'views_slideshow.theme.inc',
],
'views_slideshow_controls_widget' => [
'variables' => [
'vss_id' => NULL,
'view' => NULL,
'settings' => [],
'location' => NULL,
'rows' => [],
],
'file' => 'views_slideshow.theme.inc',
],
'views_slideshow_controls_text' => [
'variables' => [
'vss_id' => NULL,
'view' => NULL,
'settings' => [],
'location' => NULL,
'rows' => [],
],
'file' => 'views_slideshow.theme.inc',
],
'views_slideshow_controls_text_previous' => [
'variables' => [
'vss_id' => NULL,
'view' => NULL,
'settings' => [],
],
'file' => 'views_slideshow.theme.inc',
],
'views_slideshow_controls_text_pause' => [
'variables' => [
'vss_id' => NULL,
'view' => NULL,
'settings' => [],
],
'file' => 'views_slideshow.theme.inc',
],
'views_slideshow_controls_text_next' => [
'variables' => [
'vss_id' => NULL,
'view' => NULL,
'settings' => [],
],
'file' => 'views_slideshow.theme.inc',
],
'views_slideshow_slide_counter_widget' => [
'variables' => [
'vss_id' => NULL,
'view' => NULL,
'settings' => [],
'location' => NULL,
'rows' => [],
],
'file' => 'views_slideshow.theme.inc',
],
'views_slideshow_slide_counter' => [
'variables' => [
'vss_id' => NULL,
'view' => NULL,
'settings' => [],
'location' => NULL,
'rows' => [],
],
'file' => 'views_slideshow.theme.inc',
],
];
}
/**
* Views Slideshow: Slideshow.
*
* As it is a preprocess function, store it with other functions in theme.inc.
*/
function template_preprocess_views_view_slideshow(&$vars) {
\Drupal::moduleHandler()->loadInclude('views_slideshow', 'inc', 'views_slideshow.theme');
_views_slideshow_preprocess_views_view_slideshow($vars);
}
services:
plugin.manager.views_slideshow.slideshow_skin:
class: Drupal\views_slideshow\ViewsSlideshowSkinPluginManager
parent: default_plugin_manager
plugin.manager.views_slideshow.slideshow_type:
class: Drupal\views_slideshow\ViewsSlideshowTypePluginManager
parent: default_plugin_manager
plugin.manager.views_slideshow.widget_type:
class: Drupal\views_slideshow\ViewsSlideshowWidgetTypePluginManager
parent: default_plugin_manager
plugin.manager.views_slideshow.widget:
class: Drupal\views_slideshow\ViewsSlideshowWidgetPluginManager
parent: default_plugin_manager
views_slideshow.format_addons_name:
class: Drupal\views_slideshow\FormatAddonsName
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment