addfolder

This commit is contained in:
2018-04-23 21:14:46 +02:00
parent cec9a0314b
commit a7cb972085
192 changed files with 16037 additions and 24 deletions
+339
View File
@@ -0,0 +1,339 @@
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it. (Some other Free Software Foundation software is covered by
the GNU Lesser General Public License instead.) You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. You must make sure that they, too, receive or can get the
source code. And you must show them these terms so they know their
rights.
We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary. To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.
The precise terms and conditions for copying, distribution and
modification follow.
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License applies to any program or other work which contains
a notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License. The "Program", below,
refers to any such program or work, and a "work based on the Program"
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language. (Hereinafter, translation is included without limitation in
the term "modification".) Each licensee is addressed as "you".
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the
Program (independent of having been made by running the Program).
Whether that is true depends on what the Program does.
1. You may copy and distribute verbatim copies of the Program's
source code as you receive it, in any medium, provided that you
conspicuously and appropriately publish on each copy an appropriate
copyright notice and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any warranty;
and give any other recipients of the Program a copy of this License
along with the Program.
You may charge a fee for the physical act of transferring a copy, and
you may at your option offer warranty protection in exchange for a fee.
2. You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) You must cause the modified files to carry prominent notices
stating that you changed the files and the date of any change.
b) You must cause any work that you distribute or publish, that in
whole or in part contains or is derived from the Program or any
part thereof, to be licensed as a whole at no charge to all third
parties under the terms of this License.
c) If the modified program normally reads commands interactively
when run, you must cause it, when started running for such
interactive use in the most ordinary way, to print or display an
announcement including an appropriate copyright notice and a
notice that there is no warranty (or else, saying that you provide
a warranty) and that users may redistribute the program under
these conditions, and telling the user how to view a copy of this
License. (Exception: if the Program itself is interactive but
does not normally print such an announcement, your work based on
the Program is not required to print an announcement.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Program.
In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may copy and distribute the Program (or a work based on it,
under Section 2) in object code or executable form under the terms of
Sections 1 and 2 above provided that you also do one of the following:
a) Accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of Sections
1 and 2 above on a medium customarily used for software interchange; or,
b) Accompany it with a written offer, valid for at least three
years, to give any third party, for a charge no more than your
cost of physically performing source distribution, a complete
machine-readable copy of the corresponding source code, to be
distributed under the terms of Sections 1 and 2 above on a medium
customarily used for software interchange; or,
c) Accompany it with the information you received as to the offer
to distribute corresponding source code. (This alternative is
allowed only for noncommercial distribution and only if you
received the program in object code or executable form with such
an offer, in accord with Subsection b above.)
The source code for a work means the preferred form of the work for
making modifications to it. For an executable work, complete source
code means all the source code for all modules it contains, plus any
associated interface definition files, plus the scripts used to
control compilation and installation of the executable. However, as a
special exception, the source code distributed need not include
anything that is normally distributed (in either source or binary
form) with the major components (compiler, kernel, and so on) of the
operating system on which the executable runs, unless that component
itself accompanies the executable.
If distribution of executable or object code is made by offering
access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.
4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
void, and will automatically terminate your rights under this License.
However, parties who have received copies, or rights, from you under
this License will not have their licenses terminated so long as such
parties remain in full compliance.
5. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Program or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Program (or any work based on the
Program), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Program or works based on it.
6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program subject to
these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.
7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Program at all. For example, if a patent
license would not permit royalty-free redistribution of the Program by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.
If any portion of this section is held invalid or unenforceable under
any particular circumstance, the balance of the section is intended to
apply and the section as a whole is intended to apply in other
circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
may add an explicit geographical distribution limitation excluding
those countries, so that distribution is permitted only in or among
countries not thus excluded. In such case, this License incorporates
the limitation as if written in the body of this License.
9. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the Program
specifies a version number of this License which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation. If the Program does not specify a version number of
this License, you may choose any version ever published by the Free Software
Foundation.
10. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission. For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.
NO WARRANTY
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Also add information on how to contact you by electronic and paper mail.
If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
Gnomovision version 69, Copyright (C) year name of author
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, the commands you use may
be called something other than `show w' and `show c'; they could even be
mouse-clicks or menu items--whatever suits your program.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
`Gnomovision' (which makes passes at compilers) written by James Hacker.
<signature of Ty Coon>, 1 April 1989
Ty Coon, President of Vice
This General Public License does not permit incorporating your program into
proprietary programs. If your program is a subroutine library, you may
consider it more useful to permit linking proprietary applications with the
library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License.
+117
View File
@@ -0,0 +1,117 @@
CONTENTS OF THIS FILE
---------------------
* Introduction
* Features
* Requirements
* Installation
* Configuration
* Maintainers
INTRODUCTION
------------
Colorbox is a light-weight, customizable lightbox plugin for jQuery 1.4.3+.
This module allows for integration of Colorbox into Drupal.
The jQuery library is a part of Drupal since version 5+.
* jQuery - http://jquery.com/
* Colorbox - http://www.jacklmoore.com/colorbox/
FEATURES:
---------
The Colorbox module:
* Works as a Formatter in entities and in views.
* Excellent integration with core image field and image styles and the Insert
module
* Choose between a default style and a number of other styles that are included.
* Style the Colorbox with a custom Colorbox style in your theme.
* Drush command, drush colorbox-plugin, to download and install the Colorbox
plugin in "libraries/".
The Colorbox plugin:
* Compatible with: jQuery 1.3.2+ in Firefox, Safari, Chrome, Opera, Internet
Explorer 7+
* Supports photos, grouping, slideshow, ajax, inline, and iframed content.
* Lightweight: 10KB of JavaScript (less than 5KBs gzipped).
* Appearance is controlled through CSS so it can be restyled.
* Can be extended with callbacks & event-hooks without altering the source
files.
* Completely unobtrusive, options are set in the JS and require no changes to
existing HTML.
* Preloads upcoming images in a photo group.
* Currently used on more than 2 million websites.
* Released under the MIT License.
REQUIREMENTS
------------
Just Colorbox plugin in "libraries".
INSTALLATION
------------
1. Install the module as normal, see link for instructions.
Link: https://www.drupal.org/documentation/install/modules-themes/modules-8
2. Download and unpack the Colorbox plugin in "libraries".
Make sure the path to the plugin file becomes:
"libraries/colorbox/jquery.colorbox-min.js"
Link: https://github.com/jackmoore/colorbox/archive/master.zip
Drush users can use the command "drush colorbox-plugin".
3. Go to "Administer" -> "Extend" and enable the Colorbox module.
CONFIGURATION
-------------
* Go to "Configuration" -> "Media" -> "Colorbox" to find all the configuration
options.
Add a custom Colorbox style to your theme:
----------------------------------------
The easiest way is to start with either the default style or one of the example
styles included in the Colorbox JS library download. Simply copy the entire
style folder to your theme and rename it to something logical like "mycolorbox".
Inside that folder are both a .css and .js file, rename both of those as well to
match your folder name: i.e. "colorbox_mycolorbox.css" and
"colorbox_mycolorbox.js"
Add entries in your theme's .info file for the Colorbox CSS/JS files:
stylesheets[all][] = mycolorbox/colorbox_mycolorbox.css
scripts[] = mycolorbox/colorbox_mycolorbox.js
Go to "Configuration" -> "Media" -> "Colorbox" and select "None" under
"Styles and Options". This will leave the styling of Colorbox up to your theme.
Make any CSS adjustments to your "colorbox_mycolorbox.css" file.
Drush:
------
A Drush command is provides for easy installation of the Colorbox plugin itself.
% drush colorbox-plugin
The command will download the plugin and unpack it in "libraries/".
It is possible to add another path as an option to the command, but not
recommended unless you know what you are doing.
MAINTAINERS
-----------
Current maintainers:
* Fredrik Jonsson (frjo) - https://www.drupal.org/user/5546
Requires - Drupal 8
License - GPL (see LICENSE)
+29
View File
@@ -0,0 +1,29 @@
<?php
/**
* @file
* API documentation for the colorbox module.
*/
/**
* Allows to override Colorbox settings and style.
*
* Implements hook_colorbox_settings_alter().
*
* @param array $settings
* An associative array of Colorbox settings. See the
* @link http://colorpowered.com/colorbox/ Colorbox documentation @endlink
* for the full list of supported parameters.
* @param string $style
* The name of the active style plugin. If $style is 'none', no Colorbox
* theme will be loaded.
*/
function hook_colorbox_settings_alter(&$settings, &$style) {
// Disable automatic downscaling of images to maxWidth/maxHeight size.
$settings['scalePhotos'] = FALSE;
// Use custom style plugin specifically for node/123.
if (current_path() == 'node/123') {
$style = 'mystyle';
}
}
+15
View File
@@ -0,0 +1,15 @@
name: 'Colorbox'
type: module
description: 'A light-weight, customizable lightbox plugin for jQuery.'
package: Media
# core: 8.x
configure: colorbox.admin_settings
dependencies:
- image
# Information added by Drupal.org packaging script on 2017-04-24
version: '8.x-1.4'
core: '8.x'
project: 'colorbox'
datestamp: 1493051361
+27
View File
@@ -0,0 +1,27 @@
<?php
/**
* @file
* Install, update and uninstall functions for the colorbox module.
*/
/**
* Implements hook_requirements().
*/
function colorbox_requirements($phase) {
if ($phase != 'runtime') {
return array();
}
$library = \Drupal::service('library.discovery')->getLibraryByName('colorbox', 'colorbox');
$library_exists = file_exists(DRUPAL_ROOT . '/' . $library['js'][0]['data']);
return [
'colorbox_library_downloaded' => [
'title' => t('Colorbox library'),
'value' => $library_exists ? t('Installed') : t('Not installed'),
'description' => $library_exists ? '' : t('The Colorbox library needs to be <a href="@url">downloaded</a> and extracted into the /libraries/colorbox folder in your Drupal installation directory.', ['@url' => 'https://github.com/jackmoore/colorbox/archive/master.zip']),
'severity' => $library_exists ? REQUIREMENT_OK : REQUIREMENT_ERROR,
],
];
}
+101
View File
@@ -0,0 +1,101 @@
colorbox:
remote: http://github.com/jackmoore/colorbox
version: VERSION
license:
name: MIT
gpl-compatible: false
js:
/libraries/colorbox/jquery.colorbox-min.js: { minified: true }
dependencies:
- core/jquery
- core/jquery.once
colorbox-dev:
remote: http://github.com/jackmoore/colorbox
version: VERSION
license:
name: MIT
gpl-compatible: false
js:
/libraries/colorbox/jquery.colorbox.js: { }
dependencies:
- core/jquery
- core/jquery.once
init:
version: VERSION
js:
js/colorbox.js: {}
dependencies:
- core/jquery
- core/drupal
plain:
version: VERSION
js:
styles/plain/colorbox_style.js: {}
css:
theme:
styles/plain/colorbox_style.css: {}
dependencies:
- colorbox/init
stockholmsyndrome:
version: VERSION
js:
styles/stockholmsyndrome/colorbox_style.js: {}
css:
theme:
styles/stockholmsyndrome/colorbox_style.css: {}
dependencies:
- colorbox/init
default:
version: VERSION
js:
styles/default/colorbox_style.js: {}
css:
theme:
styles/default/colorbox_style.css: {}
dependencies:
- colorbox/init
example1:
version: VERSION
css:
theme:
/libraries/colorbox/example1/colorbox.css: {}
dependencies:
- colorbox/init
example2:
version: VERSION
css:
theme:
/libraries/colorbox/example2/colorbox.css: {}
dependencies:
- colorbox/init
example3:
version: VERSION
css:
theme:
/libraries/colorbox/example3/colorbox.css: {}
dependencies:
- colorbox/init
example4:
version: VERSION
css:
theme:
/libraries/colorbox/example4/colorbox.css: {}
dependencies:
- colorbox/init
example4:
version: VERSION
css:
theme:
/libraries/colorbox/example5/colorbox.css: {}
dependencies:
- colorbox/init
+5
View File
@@ -0,0 +1,5 @@
colorbox.admin_settings:
title: 'Colorbox settings'
description: 'Configure the Colorbox settings.'
parent: system.admin_config_media
route_name: colorbox.admin_settings
+47
View File
@@ -0,0 +1,47 @@
<?php
/**
* @file
* A light-weight, customizable lightbox plugin.
*/
use Drupal\Core\Routing\RouteMatchInterface;
/**
* Implements hook_help().
*/
function colorbox_help($route_name, RouteMatchInterface $route_match) {
switch ($route_name) {
case 'help.page.colorbox':
$output = '';
$output .= '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t('Colorbox is a light-weight, customizable lightbox plugin for jQuery 1.4.3+. This module allows for integration of Colorbox into Drupal.</br>The jQuery library is a part of Drupal since version 5+.') . '</p>';
$output .= '<h3>' . t('Configuration') . '</h3>';
$output .= '<p>' . t('Go to "Configuration" -> "Media" -> "Colorbox" to find all the configuration options.') . '</p>';
$output .= '<h3>' . t('Add a custom Colorbox style to your theme') . '</h3>';
$output .= '<p>' . t('The easiest way is to start with either the default style or one of the example styles included in the Colorbox JS library download. Simply copy the entire style folder to your theme and rename it to something logical like "mycolorbox". Inside that folder are both a .css and .js file, rename both of those as well to match
your folder name: i.e. "colorbox_mycolorbox.css" and "colorbox_mycolorbox.js"') . '</p>';
$output .= '<p>' . t("Add entries in your theme's .info file for the Colorbox CSS/JS files:") . '</p>';
$output .= '<p>' . t('stylesheets[all][] = mycolorbox/colorbox_mycolorbox.css</br>scripts[] = mycolorbox/colorbox_mycolorbox.js') . '</p>';
$output .= '<p>' . t('Go to "Configuration" -> "Media" -> "Colorbox" and select "None" under "Styles and Options". This will leave the styling of Colorbox up to your theme.</br>Make any CSS adjustments to your "colorbox_mycolorbox.css" file.') . '</p>';
return $output;
}
}
/**
* Implements hook_theme().
*/
function colorbox_theme() {
return array(
'colorbox_formatter' => array(
'variables' => array(
'item' => NULL,
'item_attributes' => NULL,
'entity' => NULL,
'settings' => NULL,
),
'file' => 'colorbox.theme.inc',
),
);
}
+22
View File
@@ -0,0 +1,22 @@
<?php
/**
* @file
* Post-update functions for Colorbox.
*/
use Drupal\Core\Entity\Entity\EntityViewDisplay;
use Drupal\Core\Entity\Entity\EntityFormDisplay;
/**
* Saves the image style dependencies into form and view display entities.
*/
function colorbox_post_update_image_style_dependencies() {
// Merge view and form displays. Use array_values() to avoid key collisions.
$displays = array_merge(array_values(EntityViewDisplay::loadMultiple()), array_values(EntityFormDisplay::loadMultiple()));
/** @var \Drupal\Core\Entity\Display\EntityDisplayInterface[] $displays */
foreach ($displays as $display) {
// Re-save each config entity to add missed dependencies.
$display->save();
}
}
+7
View File
@@ -0,0 +1,7 @@
colorbox.admin_settings:
path: '/admin/config/media/colorbox'
defaults:
_form: '\Drupal\colorbox\Form\ColorboxSettingsForm'
_title: 'Colorbox settings'
requirements:
_permission: 'administer site configuration'
+7
View File
@@ -0,0 +1,7 @@
services:
colorbox.activation_check:
class: Drupal\colorbox\ActivationCheck
arguments: ['@config.factory', '@request_stack']
colorbox.attachment:
class: Drupal\colorbox\ColorboxAttachment
arguments: ['@colorbox.activation_check', '@module_handler', '@config.factory']
+199
View File
@@ -0,0 +1,199 @@
<?php
/**
* @file
* Colorbox theme functions.
*/
use Drupal\Component\Utility\Crypt;
use Drupal\Component\Utility\Unicode;
use Drupal\file\Entity\File;
use Drupal\image\Entity\ImageStyle;
/**
* Prepares variables for colorbox formatter templates.
*
* Default template: colorbox-formatter.html.twig.
*
* @param array $variables
* An associative array containing:
* - item: An ImageItem object.
* - item_attributes: An optional associative array of html attributes to be
* placed in the img tag.
* - entity: An entity object.
* - settings: Formatter settings array.
*/
function template_preprocess_colorbox_formatter(&$variables) {
static $gallery_token = NULL;
$item = $variables['item'];
$item_attributes = isset($variables['item_attributes']) ? $variables['item_attributes'] : [];
$entity = $variables['entity'];
$settings = $variables['settings'];
$image_uri = $item->entity->getFileUri();
$classes_array = ['colorbox'];
$data_cbox_img_attrs = [];
// Build the caption.
$entity_title = $entity->label();
$entity_type = $entity->getEntityTypeId();
$entity_bundle = $entity->bundle();
switch ($settings['colorbox_caption']) {
case 'auto':
// If the title is empty use alt or the entity title in that order.
if (!empty($item->title)) {
$caption = $item->title;
}
elseif (!empty($item->alt)) {
$caption = $item->alt;
}
elseif (!empty($entity_title)) {
$caption = $entity_title;
}
else {
$caption = '';
}
break;
case 'title':
$caption = $item->title;
break;
case 'alt':
$caption = $item->alt;
break;
case 'entity_title':
$caption = $entity_title;
break;
case 'custom':
$token_service = \Drupal::token();
$caption = $token_service->replace($settings['colorbox_caption_custom'], [$entity_type => $entity, 'file' => $item], ['clear' => TRUE]);
break;
default:
$caption = '';
}
// Shorten the caption for the example styles or when caption
// shortening is active.
$config = \Drupal::config('colorbox.settings');
$colorbox_style = $config->get('colorbox_style');
$trim_length = $config->get('colorbox_caption_trim_length');
if (((strpos($colorbox_style, 'colorbox/example') !== FALSE) || $config->get('colorbox_caption_trim')) && (Unicode::strlen($caption) > $trim_length)) {
$caption = Unicode::substr($caption, 0, $trim_length - 5) . '...';
}
// Build the gallery id.
$id = $entity->id();
$entity_id = !empty($id) ? $entity_bundle . '-' . $id : 'entity-id';
$field_name = $item->getParent()->getName();
switch ($settings['colorbox_gallery']) {
case 'post':
$gallery_id = 'gallery-' . $entity_id;
break;
case 'page':
$gallery_id = 'gallery-all';
break;
case 'field_post':
$gallery_id = 'gallery-' . $entity_id . '-' . $field_name;
break;
case 'field_page':
$gallery_id = 'gallery-' . $field_name;
break;
case 'custom':
$token_service = \Drupal::token();
$gallery_id = $token_service->replace($settings['colorbox_gallery_custom'], [$entity_type => $entity, 'file' => $item], ['clear' => TRUE]);
break;
default:
$gallery_id = '';
}
// If gallery id is not empty add unique per-request token to avoid
// images being added manually to galleries.
if (!empty($gallery_id) && $config->get('advanced.unique_token')) {
// Check if gallery token has already been set, we need to reuse
// the token for the whole request.
if (is_null($gallery_token)) {
// We use a short token since randomness is not critical.
$gallery_token = Crypt::randomBytesBase64(8);
}
$gallery_id = $gallery_id . '-' . $gallery_token;
}
// Set up the $variables['image'] parameter.
if ($settings['style_name'] == 'hide') {
$variables['image'] = [];
$classes_array[] = 'js-hide';
}
elseif (!empty($settings['style_name'])) {
$variables['image'] = [
'#theme' => 'image_style',
'#style_name' => $settings['style_name'],
];
}
else {
$variables['image'] = [
'#theme' => 'image',
];
}
if (!empty($variables['image'])) {
$variables['image']['#attributes'] = $item_attributes;
// Do not output an empty 'title' attribute.
if (Unicode::strlen($item->title) != 0) {
$variables['image']['#title'] = $item->title;
$data_cbox_img_attrs['title'] = '"title":"' . $item->title . '"';
}
foreach (['width', 'height', 'alt'] as $key) {
$variables['image']["#$key"] = $item->$key;
if ($key == 'alt') {
$data_cbox_img_attrs['alt'] = '"alt":"' . $item->alt . '"';
}
}
$variables['image']['#uri'] = empty($item->uri) ? $image_uri : $item->uri;
}
if (!empty($settings['colorbox_image_style'])) {
$style = ImageStyle::load($settings['colorbox_image_style']);
$variables['url'] = $style->buildUrl($image_uri);
}
else {
$variables['url'] = file_create_url($image_uri);
}
// If File Entity module is enabled, load attribute values from file entity.
if (\Drupal::moduleHandler()->moduleExists('file_entity')) {
// File id of the save file.
$fid = $item->target_id;
// Load file object.
$file_obj = File::load($fid);
$file_array = $file_obj->toArray();
// Populate the image title.
if (!empty($file_array['field_image_title_text'][0]['value']) && empty($item->title) && $settings['colorbox_caption'] == 'title') {
$caption = $file_array['field_image_title_text'][0]['value'];
}
// Populate the image alt text.
if (!empty($file_array['field_image_alt_text'][0]['value']) && empty($item->alt) && $settings['colorbox_caption'] == 'alt') {
$caption = $file_array['field_image_alt_text'][0]['value'];
}
}
$variables['attributes']['title'] = $caption;
$variables['attributes']['data-colorbox-gallery'] = $gallery_id;
$variables['attributes']['class'] = $classes_array;
if (!empty($data_cbox_img_attrs)) {
$variables['attributes']['data-cbox-img-attrs'] = '{' . implode(',', $data_cbox_img_attrs) . '}';
}
}
+12
View File
@@ -0,0 +1,12 @@
{
"name": "drupal/colorbox",
"description": "A light-weight, customizable lightbox plugin for jQuery.",
"type": "drupal-module",
"homepage": "https://www.drupal.org/project/colorbox",
"support": {
"issues": "https://www.drupal.org/project/colorbox",
"source": "https://cgit.drupalcode.org/colorbox"
},
"license": "GPL-2.0+",
"minimum-stability": "dev"
}
@@ -0,0 +1,31 @@
custom:
style: 'default'
activate: 0
transition_type: 'elastic'
transition_speed: 350
opacity: 0.85
text_current: '{current} of {total}'
text_previous: '« Prev'
text_next: 'Next »'
text_close: 'Close'
maxwidth: '98%'
maxheight: '98%'
initialwidth: '300'
initialheight: '250'
overlayclose: TRUE
returnfocus: TRUE
fixed: TRUE
scrolling: TRUE
slideshow:
slideshow: 0
auto: TRUE
speed: 2500
text_start: 'start slideshow'
text_stop: 'stop slideshow'
advanced:
unique_token: 1
mobile_detect: 1
mobile_device_width: '480px'
caption_trim: 0
caption_trim_length: 75
compression_type: 'minified'
@@ -0,0 +1,126 @@
field.formatter.settings.colorbox:
type: mapping
label: 'Entity reference field formatter settings.'
mapping:
colorbox_node_style:
type: string
label: 'Node Style'
colorbox_node_style_first:
type: string
label: 'Node style first'
colorbox_image_style:
type: string
label: 'Image style'
colorbox_gallery:
type: string
label: 'Gallery'
colorbox_gallery_custom:
type: string
label: 'Gallery custom'
colorbox_caption:
type: string
label: 'Caption'
colorbox_caption_custom:
type: string
label: 'Caption custom'
colorbox.settings:
type: config_object
label: 'Colorbox settings'
mapping:
custom:
type: mapping
label: Custom Settings
mapping:
style:
type: string
label: 'Style'
activate:
type: integer
label: 'Options'
transition_type:
type: string
label: 'Transition type'
transition_speed:
type: integer
label: 'Transition speed'
opacity:
type: float
label: 'Opacity'
text_current:
type: text
label: 'Current'
text_previous:
type: text
label: 'Previous'
text_next:
type: text
label: 'Next'
text_close:
type: text
label: 'Close'
maxwidth:
type: text
label: 'Max width'
maxheight:
type: text
label: 'Max height'
initialwidth:
type: text
label: 'Initial width'
initialheight:
type: text
label: 'Initial height'
overlayclose:
type: boolean
label: 'Overlay close'
returnfocus:
type: boolean
label: 'Return focus'
fixed:
type: boolean
label: 'Fixed'
scrolling:
type: boolean
label: 'Scrollbars'
slideshow:
type: mapping
label: 'Slideshow'
mapping:
slideshow:
type: integer
label: 'Slideshow'
auto:
type: boolean
label: 'Slideshow autostart'
speed:
type: integer
label: 'Slideshow speed'
text_start:
type: text
label: 'Start slideshow'
text_stop:
type: text
label: 'Stop slideshow'
advanced:
type: mapping
label: 'Advanced settings'
mapping:
unique_token:
type: integer
label: 'Unique per-request gallery token'
mobile_detect:
type: integer
label: 'Mobile detection'
mobile_device_width:
type: 'string'
label: 'Device width'
caption_trim:
type: integer
label: 'Caption shortening'
caption_trim_length:
type: integer
label: 'Caption max length'
compression_type:
type: string
label: 'Colorbox compression level'
+101
View File
@@ -0,0 +1,101 @@
<?php
/**
* @file
* Drush integration for colorbox.
*/
/**
* The Colorbox plugin URI.
*/
define('COLORBOX_DOWNLOAD_URI', 'https://github.com/jackmoore/colorbox/archive/master.zip');
define('COLORBOX_DOWNLOAD_PREFIX', 'colorbox-');
/**
* Implements hook_drush_command().
*/
function colorbox_drush_command() {
$items = array();
// The key in the $items array is the name of the command.
$items['colorbox-plugin'] = array(
'callback' => 'drush_colorbox_plugin',
'description' => dt('Download and install the Colorbox plugin.'),
// No bootstrap.
'bootstrap' => DRUSH_BOOTSTRAP_DRUSH,
'arguments' => array(
'path' => dt('Optional. A path where to install the Colorbox plugin. If omitted Drush will use the default location.'),
),
'aliases' => array('colorboxplugin'),
);
return $items;
}
/**
* Implements hook_drush_help().
*
* This function is called whenever a drush user calls
* 'drush help <name-of-your-command>'
*/
function colorbox_drush_help($section) {
switch ($section) {
case 'drush:colorbox-plugin':
return dt('Download and install the Colorbox plugin from jacklmoore.com/colorbox, default location is the libraries directory.');
}
}
/**
* Command to download the Colorbox plugin.
*/
function drush_colorbox_plugin() {
$args = func_get_args();
if (!empty($args[0])) {
$path = $args[0];
}
else {
$path = 'libraries';
}
// Create the path if it does not exist.
if (!is_dir($path)) {
drush_op('mkdir', $path);
drush_log(dt('Directory @path was created', array('@path' => $path)), 'notice');
}
// Set the directory to the download location.
$olddir = getcwd();
chdir($path);
// Download the zip archive.
if ($filepath = drush_download_file(COLORBOX_DOWNLOAD_URI)) {
$filename = basename($filepath);
$dirname = COLORBOX_DOWNLOAD_PREFIX . basename($filepath, '.zip');
// Remove any existing Colorbox plugin directory.
if (is_dir($dirname) || is_dir('colorbox')) {
drush_delete_dir($dirname, TRUE);
drush_delete_dir('colorbox', TRUE);
drush_log(dt('A existing Colorbox plugin was deleted from @path', array('@path' => $path)), 'notice');
}
// Decompress the zip archive.
drush_tarball_extract($filename);
// Change the directory name to "colorbox" if needed.
if ($dirname != 'colorbox') {
drush_move_dir($dirname, 'colorbox', TRUE);
$dirname = 'colorbox';
}
}
if (is_dir($dirname)) {
drush_log(dt('Colorbox plugin has been installed in @path', array('@path' => $path)), 'success');
}
else {
drush_log(dt('Drush was unable to install the Colorbox plugin to @path', array('@path' => $path)), 'error');
}
// Set working directory back to the previous working directory.
chdir($olddir);
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 166 B

+29
View File
@@ -0,0 +1,29 @@
(function ($, Drupal) {
'use strict';
Drupal.behaviors.initColorbox = {
attach: function (context, settings) {
if (!$.isFunction($.colorbox) || typeof settings.colorbox === 'undefined') {
return;
}
if (settings.colorbox.mobiledetect && window.matchMedia) {
// Disable Colorbox for small screens.
var mq = window.matchMedia('(max-device-width: ' + settings.colorbox.mobiledevicewidth + ')');
if (mq.matches) {
return;
}
}
settings.colorbox.rel = function () {
return $(this).data('colorbox-gallery')
};
$('.colorbox', context)
.once('init-colorbox')
.colorbox(settings.colorbox);
}
};
})(jQuery, Drupal);
+42
View File
@@ -0,0 +1,42 @@
<?php
namespace Drupal\colorbox;
use Drupal\Core\Config\ConfigFactoryInterface;
use Symfony\Component\HttpFoundation\RequestStack;
/**
* Implementation of ActivationCheckInterface.
*/
class ActivationCheck implements ActivationCheckInterface {
/**
* The colorbox settings.
*
* @var \Drupal\Core\Config\ImmutableConfig
*/
protected $settings;
/**
* The request stack.
*
* @var \Symfony\Component\HttpFoundation\RequestStack
*/
protected $request;
/**
* Create an instace of ActivationCheck.
*/
public function __construct(ConfigFactoryInterface $config, RequestStack $request) {
$this->settings = $config->get('colorbox.settings');
$this->request = $request->getCurrentRequest();
}
/**
* {@inheritdoc}
*/
public function isActive() {
return $this->request->get('colorbox') !== 'no';
}
}
@@ -0,0 +1,18 @@
<?php
namespace Drupal\colorbox;
/**
* An interface for checking if colorbox should be active.
*/
interface ActivationCheckInterface {
/**
* Check if colorbox should be activated for the current page.
*
* @return bool
* If colorbox should be active.
*/
public function isActive();
}
+121
View File
@@ -0,0 +1,121 @@
<?php
namespace Drupal\colorbox;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
/**
* An implementation of PageAttachmentInterface for the colorbox library.
*/
class ColorboxAttachment implements ElementAttachmentInterface {
use StringTranslationTrait;
/**
* The service to determin if colorbox should be activated.
*
* @var \Drupal\colorbox\ActivationCheckInterface
*/
protected $activation;
/**
* The module handler.
*
* @var \Drupal\Core\Extension\ModuleHandlerInterface
*/
protected $moduleHandler;
/**
* The colorbox settings.
*
* @var \Drupal\Core\Config\ImmutableConfig
*/
protected $settings;
/**
* Create an instance of ColorboxAttachment.
*/
public function __construct(ActivationCheckInterface $activation, ModuleHandlerInterface $module_handler, ConfigFactoryInterface $config) {
$this->activation = $activation;
$this->moduleHandler = $module_handler;
$this->settings = $config->get('colorbox.settings');
}
/**
* {@inheritdoc}
*/
public function isApplicable() {
return !drupal_installation_attempted() && $this->activation->isActive();
}
/**
* {@inheritdoc}
*/
public function attach(array &$page) {
if ($this->settings->get('custom.activate')) {
$js_settings = array(
'transition' => $this->settings->get('custom.transition_type'),
'speed' => $this->settings->get('custom.transition_speed'),
'opacity' => $this->settings->get('custom.opacity'),
'slideshow' => $this->settings->get('custom.slideshow.slideshow') ? TRUE : FALSE,
'slideshowAuto' => $this->settings->get('custom.slideshow.auto') ? TRUE : FALSE,
'slideshowSpeed' => $this->settings->get('custom.slideshow.speed'),
'slideshowStart' => $this->settings->get('custom.slideshow.text_start'),
'slideshowStop' => $this->settings->get('custom.slideshow.text_stop'),
'current' => $this->settings->get('custom.text_current'),
'previous' => $this->settings->get('custom.text_previous'),
'next' => $this->settings->get('custom.text_next'),
'close' => $this->settings->get('custom.text_close'),
'overlayClose' => $this->settings->get('custom.overlayclose') ? TRUE : FALSE,
'returnFocus' => $this->settings->get('custom.returnfocus') ? TRUE : FALSE,
'maxWidth' => $this->settings->get('custom.maxwidth'),
'maxHeight' => $this->settings->get('custom.maxheight'),
'initialWidth' => $this->settings->get('custom.initialwidth'),
'initialHeight' => $this->settings->get('custom.initialheight'),
'fixed' => $this->settings->get('custom.fixed') ? TRUE : FALSE,
'scrolling' => $this->settings->get('custom.scrolling') ? TRUE : FALSE,
'mobiledetect' => $this->settings->get('advanced.mobile_detect') ? TRUE : FALSE,
'mobiledevicewidth' => $this->settings->get('advanced.mobile_device_width'),
);
}
else {
$js_settings = array(
'opacity' => '0.85',
'current' => $this->t('{current} of {total}'),
'previous' => $this->t('« Prev'),
'next' => $this->t('Next »'),
'close' => $this->t('Close'),
'maxWidth' => '98%',
'maxHeight' => '98%',
'fixed' => TRUE,
'mobiledetect' => $this->settings->get('advanced.mobile_detect') ? TRUE : FALSE,
'mobiledevicewidth' => $this->settings->get('advanced.mobile_device_width'),
);
}
$style = $this->settings->get('custom.style');
// Give other modules the possibility to override Colorbox
// settings and style.
$this->moduleHandler->alter('colorbox_settings', $js_settings, $style);
// Add colorbox js settings.
$page['#attached']['drupalSettings']['colorbox'] = $js_settings;
// Add and initialise the Colorbox plugin.
if ($this->settings->get('advanced.compression_type') == 'minified') {
$page['#attached']['library'][] = 'colorbox/colorbox';
}
else {
$page['#attached']['library'][] = 'colorbox/colorbox-dev';
}
// Add JS and CSS based on selected style.
if ($style != 'none') {
$page['#attached']['library'][] = "colorbox/$style";
}
}
}
@@ -0,0 +1,26 @@
<?php
namespace Drupal\colorbox;
/**
* An interface for attaching things to the built page.
*/
interface ElementAttachmentInterface {
/**
* Attach information to the page array.
*
* @param array $element
* The page array.
*/
public function attach(array &$element);
/**
* Check if the attachment should be added to the current page.
*
* @return bool
* TRUE if the attachment should be added to the current page.
*/
public function isApplicable();
}
@@ -0,0 +1,395 @@
<?php
namespace Drupal\colorbox\Form;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
/**
* General configuration form for controlling the colorbox behaviour..
*/
class ColorboxSettingsForm extends ConfigFormBase {
/**
* A state that represents the custom settings being enabled.
*/
const STATE_CUSTOM_SETTINGS = 0;
/**
* A state that represents the slideshow being enabled.
*/
const STATE_SLIDESHOW_ENABLED = 1;
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'colorbox_admin_settings_form';
}
/**
* {@inheritdoc}
*/
protected function getEditableConfigNames() {
return ['colorbox.settings'];
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this->configFactory->get('colorbox.settings');
$form['colorbox_custom_settings'] = [
'#type' => 'details',
'#title' => $this->t('Styles and options'),
'#open' => TRUE,
];
$colorbox_styles = [
'default' => $this->t('Default'),
'plain' => $this->t('Plain (mainly for images)'),
'stockholmsyndrome' => $this->t('Stockholm Syndrome'),
'example1' => $this->t('Example 1'),
'example2' => $this->t('Example 2'),
'example3' => $this->t('Example 3'),
'example4' => $this->t('Example 4'),
'example5' => $this->t('Example 5'),
'none' => $this->t('None'),
];
$form['colorbox_custom_settings']['colorbox_style'] = [
'#type' => 'select',
'#title' => $this->t('Style'),
'#options' => $colorbox_styles,
'#default_value' => $config->get('custom.style'),
'#description' => $this->t('Select the style to use for the Colorbox. The example styles are the ones that come with the Colorbox plugin. Select "None" if you have added Colorbox styles to your theme.'),
];
$form['colorbox_custom_settings']['colorbox_custom_settings_activate'] = [
'#type' => 'radios',
'#title' => $this->t('Options'),
'#options' => [0 => $this->t('Default'), 1 => $this->t('Custom')],
'#default_value' => $config->get('custom.activate'),
'#description' => $this->t('Use the default or custom options for Colorbox.'),
];
$form['colorbox_custom_settings']['colorbox_transition_type'] = [
'#type' => 'radios',
'#title' => $this->t('Transition type'),
'#options' => [
'elastic' => $this->t('Elastic'),
'fade' => $this->t('Fade'),
'none' => $this->t('None'),
],
'#default_value' => $config->get('custom.transition_type'),
'#description' => $this->t('The transition type.'),
'#states' => $this->getState(static::STATE_CUSTOM_SETTINGS),
];
$form['colorbox_custom_settings']['colorbox_transition_speed'] = [
'#type' => 'select',
'#title' => $this->t('Transition speed'),
'#options' => $this->optionsRange(100, 600, 50),
'#default_value' => $config->get('custom.transition_speed'),
'#description' => $this->t('Sets the speed of the fade and elastic transitions, in milliseconds.'),
'#states' => $this->getState(static::STATE_CUSTOM_SETTINGS),
];
$form['colorbox_custom_settings']['colorbox_opacity'] = [
'#type' => 'select',
'#title' => $this->t('Opacity'),
'#options' => $this->optionsRange(0, 1, 0.05),
'#default_value' => $config->get('custom.opacity'),
'#description' => $this->t('The overlay opacity level. Range: 0 to 1.'),
'#states' => $this->getState(static::STATE_CUSTOM_SETTINGS),
];
$form['colorbox_custom_settings']['colorbox_text_current'] = [
'#type' => 'textfield',
'#title' => $this->t('Current'),
'#default_value' => $config->get('custom.text_current'),
'#size' => 30,
'#description' => $this->t('Text format for the content group / gallery count. {current} and {total} are detected and replaced with actual numbers while Colorbox runs.'),
'#states' => $this->getState(static::STATE_CUSTOM_SETTINGS),
];
$form['colorbox_custom_settings']['colorbox_text_previous'] = [
'#type' => 'textfield',
'#title' => $this->t('Previous'),
'#default_value' => $config->get('custom.text_previous'),
'#size' => 30,
'#description' => $this->t('Text for the previous button in a shared relation group.'),
'#states' => $this->getState(static::STATE_CUSTOM_SETTINGS),
];
$form['colorbox_custom_settings']['colorbox_text_next'] = [
'#type' => 'textfield',
'#title' => $this->t('Next'),
'#default_value' => $config->get('custom.text_next'),
'#size' => 30,
'#description' => $this->t('Text for the next button in a shared relation group.'),
'#states' => $this->getState(static::STATE_CUSTOM_SETTINGS),
];
$form['colorbox_custom_settings']['colorbox_text_close'] = [
'#type' => 'textfield',
'#title' => $this->t('Close'),
'#default_value' => $config->get('custom.text_close'),
'#size' => 30,
'#description' => $this->t('Text for the close button. The "Esc" key will also close Colorbox.'),
'#states' => $this->getState(static::STATE_CUSTOM_SETTINGS),
];
$form['colorbox_custom_settings']['colorbox_maxwidth'] = [
'#type' => 'textfield',
'#title' => $this->t('Max width'),
'#default_value' => $config->get('custom.maxwidth'),
'#size' => 30,
'#description' => $this->t('Set a maximum width for loaded content. Example: "100%", 500, "500px".'),
'#states' => $this->getState(static::STATE_CUSTOM_SETTINGS),
];
$form['colorbox_custom_settings']['colorbox_maxheight'] = [
'#type' => 'textfield',
'#title' => $this->t('Max height'),
'#default_value' => $config->get('custom.maxheight'),
'#size' => 30,
'#description' => $this->t('Set a maximum height for loaded content. Example: "100%", 500, "500px".'),
'#states' => $this->getState(static::STATE_CUSTOM_SETTINGS),
];
$form['colorbox_custom_settings']['colorbox_initialwidth'] = [
'#type' => 'textfield',
'#title' => $this->t('Initial width'),
'#default_value' => $config->get('custom.initialwidth'),
'#size' => 30,
'#description' => $this->t('Set the initial width, prior to any content being loaded. Example: "100%", 500, "500px".'),
'#states' => $this->getState(static::STATE_CUSTOM_SETTINGS),
];
$form['colorbox_custom_settings']['colorbox_initialheight'] = [
'#type' => 'textfield',
'#title' => $this->t('Initial height'),
'#default_value' => $config->get('custom.initialheight'),
'#size' => 30,
'#description' => $this->t('Set the initial height, prior to any content being loaded. Example: "100%", 500, "500px".'),
'#states' => $this->getState(static::STATE_CUSTOM_SETTINGS),
];
$form['colorbox_custom_settings']['colorbox_overlayclose'] = [
'#type' => 'checkbox',
'#title' => $this->t('Overlay close'),
'#default_value' => $config->get('custom.overlayclose'),
'#description' => $this->t('Enable closing Colorbox by clicking on the background overlay.'),
'#states' => $this->getState(static::STATE_CUSTOM_SETTINGS),
];
$form['colorbox_custom_settings']['colorbox_returnfocus'] = [
'#type' => 'checkbox',
'#title' => $this->t('Return focus'),
'#default_value' => $config->get('custom.returnfocus'),
'#description' => $this->t('Return focus when Colorbox exits to the element it was launched from.'),
'#states' => $this->getState(static::STATE_CUSTOM_SETTINGS),
];
$form['colorbox_custom_settings']['colorbox_fixed'] = [
'#type' => 'checkbox',
'#title' => $this->t('Fixed'),
'#default_value' => $config->get('custom.fixed'),
'#description' => $this->t("If the Colorbox should be displayed in a fixed position within the visitor's viewport or relative to the document."),
'#states' => $this->getState(static::STATE_CUSTOM_SETTINGS),
];
$form['colorbox_custom_settings']['colorbox_scrolling'] = [
'#type' => 'checkbox',
'#title' => $this->t('Scrollbars'),
'#default_value' => $config->get('custom.scrolling'),
'#description' => $this->t('If unchecked, Colorbox will hide scrollbars for overflowing content. This could be used on conjunction with the resize method for a smoother transition if you are appending content to an already open instance of Colorbox.'),
'#states' => $this->getState(static::STATE_CUSTOM_SETTINGS),
];
$form['colorbox_custom_settings']['colorbox_slideshow_settings'] = [
'#type' => 'details',
'#title' => $this->t('Slideshow settings'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#states' => $this->getState(static::STATE_CUSTOM_SETTINGS),
];
$form['colorbox_custom_settings']['colorbox_slideshow_settings']['colorbox_slideshow'] = [
'#type' => 'radios',
'#title' => $this->t('Slideshow'),
'#options' => [0 => $this->t('Off'), 1 => $this->t('On')],
'#default_value' => $config->get('custom.slideshow.slideshow'),
'#description' => $this->t('An automatic slideshow to a content group / gallery.'),
];
$form['colorbox_custom_settings']['colorbox_slideshow_settings']['colorbox_slideshowauto'] = [
'#type' => 'checkbox',
'#title' => $this->t('Slideshow autostart'),
'#default_value' => $config->get('custom.slideshow.auto'),
'#description' => $this->t('If the slideshow should automatically start to play.'),
'#states' => $this->getState(static::STATE_SLIDESHOW_ENABLED),
];
$form['colorbox_custom_settings']['colorbox_slideshow_settings']['colorbox_slideshowspeed'] = [
'#type' => 'select',
'#title' => $this->t('Slideshow speed'),
'#options' => $this->optionsRange(1000, 6000, 500),
'#default_value' => $config->get('custom.slideshow.speed'),
'#description' => $this->t('Sets the speed of the slideshow, in milliseconds.'),
'#states' => $this->getState(static::STATE_SLIDESHOW_ENABLED),
];
$form['colorbox_custom_settings']['colorbox_slideshow_settings']['colorbox_text_start'] = [
'#type' => 'textfield',
'#title' => $this->t('Start slideshow'),
'#default_value' => $config->get('custom.slideshow.text_start'),
'#size' => 30,
'#description' => $this->t('Text for the slideshow start button.'),
'#states' => $this->getState(static::STATE_SLIDESHOW_ENABLED),
];
$form['colorbox_custom_settings']['colorbox_slideshow_settings']['colorbox_text_stop'] = [
'#type' => 'textfield',
'#title' => $this->t('Stop slideshow'),
'#default_value' => $config->get('custom.slideshow.text_stop'),
'#size' => 30,
'#description' => $this->t('Text for the slideshow stop button.'),
'#states' => $this->getState(static::STATE_SLIDESHOW_ENABLED),
];
$form['colorbox_advanced_settings'] = [
'#type' => 'details',
'#title' => $this->t('Advanced settings'),
];
$form['colorbox_advanced_settings']['colorbox_unique_token'] = [
'#type' => 'radios',
'#title' => $this->t('Unique per-request gallery token'),
'#options' => [1 => $this->t('On'), 0 => $this->t('Off')],
'#default_value' => $config->get('advanced.unique_token'),
'#description' => $this->t('If On (default), Colorbox will add a unique per-request token to the gallery id to avoid images being added manually to galleries. The token was added as a security fix but some see the old behavoiur as an feature and this settings makes it possible to remove the token.'),
];
$form['colorbox_advanced_settings']['colorbox_mobile_detect'] = [
'#type' => 'radios',
'#title' => $this->t('Mobile detection'),
'#options' => [1 => $this->t('On'), 0 => $this->t('Off')],
'#default_value' => $config->get('advanced.mobile_detect'),
'#description' => $this->t('If on (default) Colorbox will not be active for devices with the max width set below.'),
];
$form['colorbox_advanced_settings']['colorbox_mobile_device_width'] = [
'#type' => 'textfield',
'#title' => $this->t('Device width'),
'#default_value' => $config->get('advanced.mobile_device_width'),
'#size' => 30,
'#description' => $this->t('Set the mobile device max width. Default: 480px.'),
'#states' => [
'visible' => [
':input[name="colorbox_mobile_detect"]' => ['value' => '1'],
],
],
];
$form['colorbox_advanced_settings']['colorbox_caption_trim'] = [
'#type' => 'radios',
'#title' => $this->t('Caption shortening'),
'#options' => [0 => $this->t('Default'), 1 => $this->t('Yes')],
'#default_value' => $config->get('advanced.caption_trim'),
'#description' => $this->t('If the caption should be made shorter in the Colorbox to avoid layout problems. The default is to shorten for the example styles, they need it, but not for other styles.'),
];
$form['colorbox_advanced_settings']['colorbox_caption_trim_length'] = [
'#type' => 'select',
'#title' => $this->t('Caption max length'),
'#options' => $this->optionsRange(40, 120, 5),
'#default_value' => $config->get('advanced.caption_trim_length'),
'#states' => [
'visible' => [
':input[name="colorbox_caption_trim"]' => ['value' => '1'],
],
],
];
$form['colorbox_advanced_settings']['colorbox_compression_type'] = [
'#type' => 'radios',
'#title' => $this->t('Choose Colorbox compression level'),
'#options' => [
'minified' => $this->t('Production (Minified)'),
'source' => $this->t('Development (Uncompressed Code)'),
],
'#default_value' => $config->get('advanced.compression_type'),
];
return parent::buildForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$config = $this->configFactory->getEditable('colorbox.settings');
$config
->set('custom.style', $form_state->getValue('colorbox_style'))
->set('custom.activate', $form_state->getValue('colorbox_custom_settings_activate'))
->set('custom.transition_type', $form_state->getValue('colorbox_transition_type'))
->set('custom.transition_speed', $form_state->getValue('colorbox_transition_speed'))
->set('custom.opacity', $form_state->getValue('colorbox_opacity'))
->set('custom.text_current', $form_state->getValue('colorbox_text_current'))
->set('custom.text_previous', $form_state->getValue('colorbox_text_previous'))
->set('custom.text_next', $form_state->getValue('colorbox_text_next'))
->set('custom.text_close', $form_state->getValue('colorbox_text_close'))
->set('custom.overlayclose', $form_state->getValue('colorbox_overlayclose'))
->set('custom.returnfocus', $form_state->getValue('colorbox_returnfocus'))
->set('custom.maxwidth', $form_state->getValue('colorbox_maxwidth'))
->set('custom.maxheight', $form_state->getValue('colorbox_maxheight'))
->set('custom.initialwidth', $form_state->getValue('colorbox_initialwidth'))
->set('custom.initialheight', $form_state->getValue('colorbox_initialheight'))
->set('custom.fixed', $form_state->getValue('colorbox_fixed'))
->set('custom.scrolling', $form_state->getValue('colorbox_scrolling'))
->set('custom.slideshow.slideshow', $form_state->getValue('colorbox_slideshow'))
->set('custom.slideshow.auto', $form_state->getValue('colorbox_slideshowauto'))
->set('custom.slideshow.speed', $form_state->getValue('colorbox_slideshowspeed'))
->set('custom.slideshow.text_start', $form_state->getValue('colorbox_text_start'))
->set('custom.slideshow.text_stop', $form_state->getValue('colorbox_text_stop'))
->set('advanced.unique_token', $form_state->getValue('colorbox_unique_token'))
->set('advanced.mobile_detect', $form_state->getValue('colorbox_mobile_detect'))
->set('advanced.mobile_device_width', $form_state->getValue('colorbox_mobile_device_width'))
->set('advanced.caption_trim', $form_state->getValue('colorbox_caption_trim'))
->set('advanced.caption_trim_length', $form_state->getValue('colorbox_caption_trim_length'))
->set('advanced.compression_type', $form_state->getValue('colorbox_compression_type'));
if ($form_state->getValue('colorbox_image_style')) {
$config->set('insert.image_style', $form_state->getValue('colorbox_image_style'));
}
if ($form_state->getValue('colorbox_insert_gallery')) {
$config->set('insert.insert_gallery', $form_state->getValue('colorbox_insert_gallery'));
}
$config->save();
parent::submitForm($form, $form_state);
}
/**
* Get one of the pre-defined states used in this form.
*
* @param string $state
* The state to get that matches one of the state class constants.
*
* @return array
* A corresponding form API state.
*/
protected function getState($state) {
$states = [
static::STATE_CUSTOM_SETTINGS => [
'visible' => [
':input[name="colorbox_custom_settings_activate"]' => ['value' => '1'],
],
],
static::STATE_SLIDESHOW_ENABLED => [
'visible' => [
':input[name="colorbox_slideshow"]' => ['value' => '1'],
],
],
];
return $states[$state];
}
/**
* Create a range for a series of options.
*
* @param int $start
* The start of the range.
* @param int $end
* The end of the range.
* @param int $step
* The interval between elements.
*
* @return array
* An options array for the given range.
*/
protected function optionsRange($start, $end, $step) {
$range = range($start, $end, $step);
return array_combine($range, $range);
}
}
@@ -0,0 +1,435 @@
<?php
namespace Drupal\colorbox\Plugin\Field\FieldFormatter;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Link;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Url;
use Drupal\image\Entity\ImageStyle;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Cache\Cache;
use Drupal\colorbox\ElementAttachmentInterface;
use Drupal\image\Plugin\Field\FieldFormatter\ImageFormatterBase;
/**
* Plugin implementation of the 'colorbox' formatter.
*
* @FieldFormatter(
* id = "colorbox",
* module = "colorbox",
* label = @Translation("Colorbox"),
* field_types = {
* "image"
* }
* )
*/
class ColorboxFormatter extends ImageFormatterBase implements ContainerFactoryPluginInterface {
/**
* The current user.
*
* @var \Drupal\Core\Session\AccountInterface
*/
protected $currentUser;
/**
* The image style entity storage.
*
* @var \Drupal\image\ImageStyleStorageInterface
*/
protected $imageStyleStorage;
/**
* Constructs an ImageFormatter object.
*
* @param string $plugin_id
* The plugin_id for the formatter.
* @param mixed $plugin_definition
* The plugin implementation definition.
* @param \Drupal\Core\Field\FieldDefinitionInterface $field_definition
* The definition of the field to which the formatter is associated.
* @param array $settings
* The formatter settings.
* @param string $label
* The formatter label display setting.
* @param string $view_mode
* The view mode.
* @param array $third_party_settings
* Any third party settings settings.
* @param \Drupal\Core\Session\AccountInterface $current_user
* The current user.
* @param \Drupal\colorbox\ElementAttachmentInterface $attachment
* Allow the library to be attached to the page.
*/
public function __construct($plugin_id, $plugin_definition, FieldDefinitionInterface $field_definition, array $settings, $label, $view_mode, array $third_party_settings, AccountInterface $current_user, EntityStorageInterface $image_style_storage, ElementAttachmentInterface $attachment) {
parent::__construct($plugin_id, $plugin_definition, $field_definition, $settings, $label, $view_mode, $third_party_settings);
$this->currentUser = $current_user;
$this->imageStyleStorage = $image_style_storage;
$this->attachment = $attachment;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static(
$plugin_id,
$plugin_definition,
$configuration['field_definition'],
$configuration['settings'],
$configuration['label'],
$configuration['view_mode'],
$configuration['third_party_settings'],
$container->get('current_user'),
$container->get('entity.manager')->getStorage('image_style'),
$container->get('colorbox.attachment')
);
}
/**
* {@inheritdoc}
*/
public static function defaultSettings() {
return [
'colorbox_node_style' => '',
'colorbox_node_style_first' => '',
'colorbox_image_style' => '',
'colorbox_gallery' => 'post',
'colorbox_gallery_custom' => '',
'colorbox_caption' => 'auto',
'colorbox_caption_custom' => '',
] + parent::defaultSettings();
}
/**
* {@inheritdoc}
*/
public function settingsForm(array $form, FormStateInterface $form_state) {
$image_styles = image_style_options(FALSE);
$image_styles_hide = $image_styles;
$image_styles_hide['hide'] = $this->t('Hide (do not display image)');
$description_link = Link::fromTextAndUrl(
$this->t('Configure Image Styles'),
Url::fromRoute('entity.image_style.collection')
);
$element['colorbox_node_style'] = [
'#title' => $this->t('Image style for content'),
'#type' => 'select',
'#default_value' => $this->getSetting('colorbox_node_style'),
'#empty_option' => $this->t('None (original image)'),
'#options' => $image_styles_hide,
'#description' => $description_link->toRenderable() + [
'#access' => $this->currentUser->hasPermission('administer image styles'),
],
];
$element['colorbox_node_style_first'] = [
'#title' => $this->t('Image style for first image in content'),
'#type' => 'select',
'#default_value' => $this->getSetting('colorbox_node_style_first'),
'#empty_option' => $this->t('No special style.'),
'#options' => $image_styles,
'#description' => $description_link->toRenderable() + [
'#access' => $this->currentUser->hasPermission('administer image styles'),
],
];
$element['colorbox_image_style'] = [
'#title' => $this->t('Image style for Colorbox'),
'#type' => 'select',
'#default_value' => $this->getSetting('colorbox_image_style'),
'#empty_option' => $this->t('None (original image)'),
'#options' => $image_styles,
'#description' => $description_link->toRenderable() + [
'#access' => $this->currentUser->hasPermission('administer image styles'),
],
];
$gallery = [
'post' => $this->t('Per post gallery'),
'page' => $this->t('Per page gallery'),
'field_post' => $this->t('Per field in post gallery'),
'field_page' => $this->t('Per field in page gallery'),
'custom' => $this->t('Custom (with tokens)'),
'none' => $this->t('No gallery'),
];
$element['colorbox_gallery'] = [
'#title' => $this->t('Gallery (image grouping)'),
'#type' => 'select',
'#default_value' => $this->getSetting('colorbox_gallery'),
'#options' => $gallery,
'#description' => $this->t('How Colorbox should group the image galleries.'),
];
$element['colorbox_gallery_custom'] = [
'#title' => $this->t('Custom gallery'),
'#type' => 'textfield',
'#default_value' => $this->getSetting('colorbox_gallery_custom'),
'#description' => $this->t('All images on a page with the same gallery value (rel attribute) will be grouped together. It must only contain lowercase letters, numbers, and underscores.'),
'#required' => FALSE,
'#states' => [
'visible' => [
':input[name$="[settings_edit_form][settings][colorbox_gallery]"]' => ['value' => 'custom'],
],
],
];
if (\Drupal::moduleHandler()->moduleExists('token')) {
$element['colorbox_token_gallery'] = [
'#type' => 'fieldset',
'#title' => t('Replacement patterns'),
'#theme' => 'token_tree_link',
'#token_types' => [$form['#entity_type'], 'file'],
'#states' => [
'visible' => [
':input[name$="[settings_edit_form][settings][colorbox_gallery]"]' => ['value' => 'custom'],
],
],
];
}
else {
$element['colorbox_token_gallery'] = [
'#type' => 'fieldset',
'#title' => $this->t('Replacement patterns'),
'#description' => '<strong class="error">' . $this->t('For token support the <a href="@token_url">token module</a> must be installed.', ['@token_url' => 'http://drupal.org/project/token']) . '</strong>',
'#states' => [
'visible' => [
':input[name$="[settings_edit_form][settings][colorbox_gallery]"]' => ['value' => 'custom'],
],
],
];
}
$caption = [
'auto' => $this->t('Automatic'),
'title' => $this->t('Title text'),
'alt' => $this->t('Alt text'),
'entity_title' => $this->t('Content title'),
'custom' => $this->t('Custom (with tokens)'),
'none' => $this->t('None'),
];
$element['colorbox_caption'] = [
'#title' => $this->t('Caption'),
'#type' => 'select',
'#default_value' => $this->getSetting('colorbox_caption'),
'#options' => $caption,
'#description' => $this->t('Automatic will use the first non-empty value out of the title, the alt text and the content title.'),
];
$element['colorbox_caption_custom'] = [
'#title' => $this->t('Custom caption'),
'#type' => 'textfield',
'#default_value' => $this->getSetting('colorbox_caption_custom'),
'#states' => [
'visible' => [
':input[name$="[settings_edit_form][settings][colorbox_caption]"]' => ['value' => 'custom'],
],
],
];
if (\Drupal::moduleHandler()->moduleExists('token')) {
$element['colorbox_token_caption'] = [
'#type' => 'fieldset',
'#title' => t('Replacement patterns'),
'#theme' => 'token_tree_link',
'#token_types' => [$form['#entity_type'], 'file'],
'#states' => [
'visible' => [
':input[name$="[settings_edit_form][settings][colorbox_caption]"]' => ['value' => 'custom'],
],
],
];
}
else {
$element['colorbox_token_caption'] = [
'#type' => 'fieldset',
'#title' => $this->t('Replacement patterns'),
'#description' => '<strong class="error">' . $this->t('For token support the <a href="@token_url">token module</a> must be installed.', ['@token_url' => 'http://drupal.org/project/token']) . '</strong>',
'#states' => [
'visible' => [
':input[name$="[settings_edit_form][settings][colorbox_caption]"]' => ['value' => 'custom'],
],
],
];
}
return $element;
}
/**
* {@inheritdoc}
*/
public function settingsSummary() {
$summary = [];
$image_styles = image_style_options(FALSE);
// Unset possible 'No defined styles' option.
unset($image_styles['']);
// Styles could be lost because of enabled/disabled modules that defines
// their styles in code.
if (isset($image_styles[$this->getSetting('colorbox_node_style')])) {
$summary[] = $this->t('Content image style: @style', ['@style' => $image_styles[$this->getSetting('colorbox_node_style')]]);
}
elseif ($this->getSetting('colorbox_node_style') == 'hide') {
$summary[] = $this->t('Content image style: Hide');
}
else {
$summary[] = $this->t('Content image style: Original image');
}
if (isset($image_styles[$this->getSetting('colorbox_node_style_first')])) {
$summary[] = $this->t('Content image style of first image: @style', ['@style' => $image_styles[$this->getSetting('colorbox_node_style_first')]]);
}
if (isset($image_styles[$this->getSetting('colorbox_image_style')])) {
$summary[] = $this->t('Colorbox image style: @style', ['@style' => $image_styles[$this->getSetting('colorbox_image_style')]]);
}
else {
$summary[] = $this->t('Colorbox image style: Original image');
}
$gallery = [
'post' => $this->t('Per post gallery'),
'page' => $this->t('Per page gallery'),
'field_post' => $this->t('Per field in post gallery'),
'field_page' => $this->t('Per field in page gallery'),
'custom' => $this->t('Custom (with tokens)'),
'none' => $this->t('No gallery'),
];
if ($this->getSetting('colorbox_gallery')) {
$summary[] = $this->t('Colorbox gallery type: @type', ['@type' => $gallery[$this->getSetting('colorbox_gallery')]]) . ($this->getSetting('colorbox_gallery') == 'custom' ? ' (' . $this->getSetting('colorbox_gallery_custom') . ')' : '');
}
$caption = [
'auto' => $this->t('Automatic'),
'title' => $this->t('Title text'),
'alt' => $this->t('Alt text'),
'entity_title' => $this->t('Content title'),
'custom' => $this->t('Custom (with tokens)'),
'none' => $this->t('None'),
];
if ($this->getSetting('colorbox_caption')) {
$summary[] = $this->t('Colorbox caption: @type', ['@type' => $caption[$this->getSetting('colorbox_caption')]]);
}
return $summary;
}
/**
* {@inheritdoc}
*/
public function viewElements(FieldItemListInterface $items, $langcode) {
$elements = [];
$settings = $this->getSettings();
$files = $this->getEntitiesToView($items, $langcode);
// Early opt-out if the field is empty.
if (empty($files)) {
return $elements;
}
// Collect cache tags to be added for each item in the field.
$cache_tags = [];
if (!empty($settings['colorbox_node_style']) && $settings['colorbox_node_style'] != 'hide') {
$image_style = $this->imageStyleStorage->load($settings['colorbox_node_style']);
$cache_tags = $image_style->getCacheTags();
}
$cache_tags_first = [];
if (!empty($settings['colorbox_node_style_first'])) {
$image_style_first = $this->imageStyleStorage->load($settings['colorbox_node_style_first']);
$cache_tags_first = $image_style_first->getCacheTags();
}
foreach ($files as $delta => $file) {
// Check if first image should have separate image style.
if ($delta == 0 && !empty($settings['colorbox_node_style_first'])) {
$settings['style_first'] = TRUE;
$settings['style_name'] = $settings['colorbox_node_style_first'];
$cache_tags = Cache::mergeTags($cache_tags_first, $file->getCacheTags());
}
else {
$settings['style_first'] = FALSE;
$settings['style_name'] = $settings['colorbox_node_style'];
$cache_tags = Cache::mergeTags($cache_tags, $file->getCacheTags());
}
// Extract field item attributes for the theme function, and unset them
// from the $item so that the field template does not re-render them.
$item = $file->_referringItem;
$item_attributes = $item->_attributes;
unset($item->_attributes);
$elements[$delta] = [
'#theme' => 'colorbox_formatter',
'#item' => $item,
'#item_attributes' => $item_attributes,
'#entity' => $items->getEntity(),
'#settings' => $settings,
'#cache' => [
'tags' => $cache_tags,
],
];
}
// Attach the Colorbox JS and CSS.
if ($this->attachment->isApplicable()) {
$this->attachment->attach($elements);
}
return $elements;
}
/**
* {@inheritdoc}
*/
public function calculateDependencies() {
$dependencies = parent::calculateDependencies();
$style_ids = [];
$style_ids[] = $this->getSetting('colorbox_node_style');
if (!empty($this->getSetting('colorbox_node_style_first'))) {
$style_ids[] = $this->getSetting('colorbox_node_style_first');
}
$style_ids[] = $this->getSetting('colorbox_image_style');
/** @var \Drupal\image\ImageStyleInterface $style */
foreach ($style_ids as $style_id) {
if ($style_id && $style = ImageStyle::load($style_id)) {
// If this formatter uses a valid image style to display the image, add
// the image style configuration entity as dependency of this formatter.
$dependencies[$style->getConfigDependencyKey()][] = $style->getConfigDependencyName();
}
}
return $dependencies;
}
/**
* {@inheritdoc}
*/
public function onDependencyRemoval(array $dependencies) {
$changed = parent::onDependencyRemoval($dependencies);
$style_ids = [];
$style_ids['colorbox_node_style'] = $this->getSetting('colorbox_node_style');
if (!empty($this->getSetting('colorbox_node_style_first'))) {
$style_ids['colorbox_node_style_first'] = $this->getSetting('colorbox_node_style_first');
}
$style_ids['colorbox_image_style'] = $this->getSetting('colorbox_image_style');
/** @var \Drupal\image\ImageStyleInterface $style */
foreach ($style_ids as $name => $style_id) {
if ($style_id && $style = ImageStyle::load($style_id)) {
if (!empty($dependencies[$style->getConfigDependencyKey()][$style->getConfigDependencyName()])) {
$replacement_id = $this->imageStyleStorage->getReplacementId($style_id);
// If a valid replacement has been provided in the storage,
// replace the image style with the replacement and signal
// that the formatter plugin.
// Settings were updated.
if ($replacement_id && ImageStyle::load($replacement_id)) {
$this->setSetting($name, $replacement_id);
$changed = TRUE;
}
}
}
}
return $changed;
}
}
@@ -0,0 +1,216 @@
/**
* Colorbox Core Style:
* The following CSS is consistent between example themes and should not be altered.
*/
#colorbox, #cboxOverlay, #cboxWrapper {
position: absolute;
top: 0;
left: 0;
z-index: 9999;
overflow: hidden;
}
#cboxOverlay {
position: fixed;
width: 100%;
height: 100%;
}
#cboxMiddleLeft, #cboxBottomLeft {
clear: left;
}
#cboxContent {
position: relative;
}
#cboxLoadedContent {
overflow: auto;
-webkit-overflow-scrolling: touch;
}
#cboxTitle {
margin: 0;
}
#cboxLoadingOverlay, #cboxLoadingGraphic {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
/**
* These elements are buttons, and may need to have additional
* styles reset to avoid unwanted base styles.
*/
#cboxPrevious, #cboxNext, #cboxClose, #cboxSlideshow {
border: 0;
padding: 0;
margin: 0;
overflow: visible;
width: auto;
background: none;
cursor: pointer;
}
/**
* Avoid outlines on :active (mouseclick),
* but preserve outlines on :focus (tabbed navigating)
*/
#cboxPrevious:active, #cboxNext:active, #cboxClose:active, #cboxSlideshow:active {
outline: 0;
}
.cboxPhoto {
float: left;
margin: auto;
border: 0;
display: block;
max-width: none;
}
.cboxIframe {
width: 100%;
height: 100%;
display: block;
border: 0;
}
/* Reset box sizing to content-box if theme is using border-box. */
#colorbox, #cboxContent, #cboxLoadedContent {
-moz-box-sizing: content-box;
-webkit-box-sizing: content-box;
box-sizing: content-box;
}
/**
* Colorbox module default style:
* The styles are ordered & tabbed in a way that represents
* the nesting of the generated HTML.
*/
#cboxOverlay {
background: #000;
}
#colorbox {
outline: 0;
}
#cboxWrapper {
background: #fff;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
border-radius: 5px;
}
#cboxTopLeft {
width: 15px;
height: 15px;
}
#cboxTopCenter {
height: 15px;
}
#cboxTopRight {
width: 15px;
height: 15px;
}
#cboxBottomLeft {
width: 15px;
height: 10px;
}
#cboxBottomCenter {
height: 10px;
}
#cboxBottomRight {
width: 15px;
height: 10px;
}
#cboxMiddleLeft {
width: 15px;
}
#cboxMiddleRight {
width: 15px;
}
#cboxContent {
background: #fff;
overflow: hidden;
}
#cboxError {
padding: 50px;
border: 1px solid #ccc;
}
#cboxLoadedContent {
margin-bottom: 28px;
}
#cboxTitle {
position: absolute;
background: rgba(255, 255, 255, 0.7);
bottom: 28px;
left: 0;
color: #535353;
width: 100%;
padding: 4px 6px;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
#cboxCurrent {
position: absolute;
bottom: 4px;
left: 60px;
color: #949494;
}
.cboxSlideshow_on #cboxSlideshow {
position: absolute;
bottom: 0px;
right: 30px;
background: url(images/controls.png) no-repeat -75px -50px;
width: 25px;
height: 25px;
text-indent: -9999px;
}
.cboxSlideshow_on #cboxSlideshow:hover {
background-position: -101px -50px;
}
.cboxSlideshow_off #cboxSlideshow {
position: absolute;
bottom: 0px;
right: 30px;
background: url(images/controls.png) no-repeat -25px -50px;
width: 25px;
height: 25px;
text-indent: -9999px;
}
.cboxSlideshow_off #cboxSlideshow:hover {
background-position: -49px -50px;
}
#cboxPrevious {
position: absolute;
bottom: 0;
left: 0;
background: url(images/controls.png) no-repeat -75px 0px;
width: 25px;
height: 25px;
text-indent: -9999px;
}
#cboxPrevious:hover {
background-position: -75px -25px;
}
#cboxNext {
position: absolute;
bottom: 0;
left: 27px;
background: url(images/controls.png) no-repeat -50px 0px;
width: 25px;
height: 25px;
text-indent: -9999px;
}
#cboxNext:hover {
background-position: -50px -25px;
}
#cboxLoadingOverlay {
background: #fff;
}
#cboxLoadingGraphic {
background: url(images/loading_animation.gif) no-repeat center center;
}
#cboxClose {
position: absolute;
bottom: 0;
right: 0;
background: url(images/controls.png) no-repeat -25px 0px;
width: 25px;
height: 25px;
text-indent: -9999px;
}
#cboxClose:hover {
background-position: -25px -25px;
}
@@ -0,0 +1,22 @@
(function ($) {
Drupal.behaviors.initColorboxDefaultStyle = {
attach: function (context, settings) {
$(context).bind('cbox_complete', function () {
// Only run if there is a title.
if ($('#cboxTitle:empty', context).length == false) {
$('#cboxLoadedContent img', context).bind('mouseover', function () {
$('#cboxTitle', context).slideDown();
});
$('#cboxOverlay', context).bind('mouseover', function () {
$('#cboxTitle', context).slideUp();
});
}
else {
$('#cboxTitle', context).hide();
}
});
}
};
})(jQuery);
Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 166 B

@@ -0,0 +1,144 @@
/**
* Colorbox Core Style:
* The following CSS is consistent between example themes and should not be altered.
*/
#colorbox, #cboxOverlay, #cboxWrapper {
position: absolute;
top: 0;
left: 0;
z-index: 9999;
overflow: hidden;
}
#cboxOverlay {
position: fixed;
width: 100%;
height: 100%;
}
#cboxMiddleLeft, #cboxBottomLeft {
clear: left;
}
#cboxContent {
position: relative;
}
#cboxLoadedContent {
overflow: auto;
-webkit-overflow-scrolling: touch;
}
#cboxTitle {
margin: 0;
}
#cboxLoadingOverlay, #cboxLoadingGraphic {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
/**
* These elements are buttons, and may need to have additional
* styles reset to avoid unwanted base styles.
*/
#cboxPrevious, #cboxNext, #cboxClose, #cboxSlideshow {
border: 0;
padding: 0;
margin: 0;
overflow: visible;
width: auto;
background: none;
cursor: pointer;
}
/**
* Avoid outlines on :active (mouseclick),
* but preserve outlines on :focus (tabbed navigating)
*/
#cboxPrevious:active, #cboxNext:active, #cboxClose:active, #cboxSlideshow:active {
outline: 0;
}
.cboxPhoto {
float: left;
margin: auto;
border: 0;
display: block;
max-width: none;
}
.cboxIframe {
width: 100%;
height: 100%;
display: block;
border: 0;
}
/* Reset box sizing to content-box if theme is using border-box. */
#colorbox, #cboxContent, #cboxLoadedContent {
-moz-box-sizing: content-box;
-webkit-box-sizing: content-box;
box-sizing: content-box;
}
/**
* Colorbox module plain style:
* The styles are ordered & tabbed in a way that represents
* the nesting of the generated HTML.
*/
#cboxOverlay {
background: #000;
}
#colorbox {
outline: 0;
}
#cboxWrapper {}
#cboxContent {
overflow: hidden;
}
#cboxContent, .cboxPhoto {
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
}
#cboxError {
padding: 50px;
border: 1px solid #ccc;
}
#cboxTitle {
position: absolute;
background: rgba(255, 255, 255, 0.7);
bottom: 0;
left: 0;
color: #535353;
width: 100%;
padding: 4px 6px;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
-webkit-border-bottom-right-radius: 5px;
-webkit-border-bottom-left-radius: 5px;
-moz-border-radius-bottomright: 5px;
-moz-border-radius-bottomleft: 5px;
border-bottom-right-radius: 5px;
border-bottom-left-radius: 5px;
}
#cboxLoadingOverlay {
background: #fff;
}
#cboxLoadingGraphic {
background: url(images/loading_animation.gif) no-repeat center center;
}
#cboxClose.cbox-close-plain {
position: absolute;
font-size: 20px;
line-height: 18px;
text-align: center;
color: rgba(255, 255, 255, 0.7);
background: rgba(0, 0, 0, 0.5);
top: 4px;
right: 4px;
width: 20px;
height: 20px;
-webkit-border-radius: 10px;
-moz-border-radius: 10px;
border-radius: 10px;
}
.cbox-close-plain:hover {
color: rgba(255, 255, 255, 0.9);
background: rgba(0, 0, 0, 0.8);
}
@@ -0,0 +1,35 @@
(function ($, Drupal) {
"use strict";
Drupal.behaviors.initColorboxPlainStyle = {
attach: function (context, settings) {
$(context).bind('cbox_complete', function () {
// Make all the controls invisible.
$('#cboxCurrent, #cboxSlideshow, #cboxPrevious, #cboxNext', context).addClass('element-invisible');
// Replace "Close" with "×" and show.
$('#cboxClose', context).html('\u00d7').addClass('cbox-close-plain');
// Hide empty title.
if ($('#cboxTitle:empty', context).length == true) {
$('#cboxTitle', context).hide();
}
$('#cboxLoadedContent', context).bind('mouseover', function () {
$('#cboxClose', context).animate({opacity: 1}, {queue: false, duration: "fast"});
if ($('#cboxTitle:empty', context).length == false) {
$('#cboxTitle', context).slideDown();
}
});
$('#cboxOverlay', context).bind('mouseover', function () {
$('#cboxClose', context).animate({opacity: 0}, {queue: false, duration: "fast"});
if ($('#cboxTitle:empty', context).length == false) {
$('#cboxTitle', context).slideUp();
}
});
});
$(context).bind('cbox_closed', function () {
$('#cboxClose', context).removeClass('cbox-close-plain');
});
}
};
})(jQuery, Drupal);
Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 166 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 121 KiB

@@ -0,0 +1,219 @@
/**
* Colorbox Core Style:
* The following CSS is consistent between example themes and should not be altered.
*/
#colorbox, #cboxOverlay, #cboxWrapper {
position: absolute;
top: 0;
left: 0;
z-index: 9999;
overflow: hidden;
}
#cboxOverlay {
position: fixed;
width: 100%;
height: 100%;
}
#cboxMiddleLeft, #cboxBottomLeft {
clear: left;
}
#cboxContent {
position: relative;
}
#cboxLoadedContent {
overflow: auto;
-webkit-overflow-scrolling: touch;
}
#cboxTitle {
margin: 0;
}
#cboxLoadingOverlay, #cboxLoadingGraphic {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
/**
* These elements are buttons, and may need to have additional
* styles reset to avoid unwanted base styles.
*/
#cboxPrevious, #cboxNext, #cboxClose, #cboxSlideshow {
border: 0;
padding: 0;
margin: 0;
overflow: visible;
width: auto;
background: none;
cursor: pointer;
}
/**
* Avoid outlines on :active (mouseclick),
* but preserve outlines on :focus (tabbed navigating)
*/
#cboxPrevious:active, #cboxNext:active, #cboxClose:active, #cboxSlideshow:active {
outline: 0;
}
.cboxPhoto {
float: left;
margin: auto;
border: 0;
display: block;
max-width: none;
}
.cboxIframe {
width: 100%;
height: 100%;
display: block;
border: 0;
}
/* Reset box sizing to content-box if theme is using border-box. */
#colorbox, #cboxContent, #cboxLoadedContent {
-moz-box-sizing: content-box;
-webkit-box-sizing: content-box;
box-sizing: content-box;
}
/**
* Colorbox module Stockholm syndrome style:
* The styles are ordered & tabbed in a way that represents
* the nesting of the generated HTML.
*/
#cboxOverlay {
background: #000;
}
#colorbox {
background: #fff url(images/bg_tab.png) center bottom repeat-x;
-moz-box-shadow: 3px 3px 16px #333;
-webkit-box-shadow: 3px 3px 16px #333;
box-shadow: 3px 3px 16px #333;
-moz-border-radius-bottomleft: 9px;
-moz-border-radius-bottomright: 9px;
-webkit-border-bottom-left-radius: 9px;
-webkit-border-bottom-right-radius: 9px;
border-bottom-left-radius: 9px;
border-bottom-right-radius: 9px;
outline: 0;
}
#colorbox, #colorbox div {
overflow: visible; /* Required by the close button. */
}
#cboxWrapper {
-moz-border-radius-bottomleft: 9px;
-moz-border-radius-bottomright: 9px;
-webkit-border-bottom-left-radius: 9px;
-webkit-border-bottom-right-radius: 9px;
border-bottom-left-radius: 9px;
border-bottom-right-radius: 9px;
}
#cboxTopLeft {
width: 0;
height: 0;
}
#cboxTopCenter {
height: 0;
}
#cboxTopRight {
width: 0;
height: 0;
}
#cboxBottomLeft {
width: 15px;
height: 10px;
}
#cboxBottomCenter {
height: 10px;
}
#cboxBottomRight {
width: 15px;
height: 10px;
}
#cboxMiddleLeft {
width: 0;
}
#cboxMiddleRight {
width: 0;
}
#cboxContent {
background: #fff;
overflow: hidden;
margin-bottom: 28px;
}
#cboxError {
padding: 50px;
border: 1px solid #ccc;
}
#cboxLoadedContent {
}
#cboxTitle {
left: 0;
height: 38px;
color: #313131;
padding: 0 140px 0 15px;
display: table-cell !important;
vertical-align: middle;
float: none !important;
}
#cboxCurrent {
position: absolute;
bottom: -26px;
right: 80px;
color: #313131;
border-left: 1px solid #313131;
padding: 0 0 0 15px;
}
/* Slideshow not implemented. */
.cboxSlideshow_on #cboxSlideshow {
display: none;
}
.cboxSlideshow_on #cboxSlideshow:hover {
}
.cboxSlideshow_off #cboxSlideshow {
display: none;
}
.cboxSlideshow_off #cboxSlideshow:hover {
}
#cboxPrevious {
position: absolute;
bottom: -26px;
right: 45px;
background: url(images/controls.png) no-repeat 0 -48px;
width: 21px;
height: 15px;
text-indent: -9999px;
}
#cboxPrevious:hover {
background-position: 0 -111px;
}
#cboxNext {
position: absolute;
bottom: -26px;
right: 15px;
background: url(images/controls.png) no-repeat 0 -29px;
width: 21px;
height: 15px;
text-indent: -9999px;
}
#cboxNext:hover {
background-position: 0 -92px;
}
#cboxLoadingOverlay {
background: #e6e6e6;
}
#cboxLoadingGraphic {
background: url(images/loading_animation.gif) no-repeat center center;
}
#cboxClose {
position: absolute;
top: -10px;
right: -10px;
background: url(images/controls.png) no-repeat 0px 0px;
width: 25px;
height: 25px;
text-indent: -9999px;
opacity: 0;
}
#cboxClose:hover {
background-position: 0 -63px;
}
@@ -0,0 +1,20 @@
(function ($) {
Drupal.behaviors.initColorboxStockholmsyndromeStyle = {
attach: function (context, settings) {
$(context).bind('cbox_open', function () {
// Hide close button initially.
$('#cboxClose', context).css('opacity', 0);
});
$(context).bind('cbox_load', function () {
// Hide close button. (It doesn't handle the load animation well.)
$('#cboxClose', context).css('opacity', 0);
});
$(context).bind('cbox_complete', function () {
// Show close button with a delay.
$('#cboxClose', context).fadeTo('fast', 0, function () {$(this).css('opacity', 1)});
});
}
};
})(jQuery);
Binary file not shown.

After

Width:  |  Height:  |  Size: 210 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

@@ -0,0 +1,16 @@
{#
/**
* @file
* Default theme implementation to display a formatted colorbox image field.
*
* Available variables:
* - image: A collection of image data.
* - url: An URL the image can be linked to.
* - attributes: Link attributes.
*
* @see template_preprocess_colorbox_formatter()
*
* @ingroup themeable
*/
#}
<a href="{{ url }}"{{ attributes }}>{{ image }}</a>
@@ -0,0 +1,12 @@
name: Colorbox Library Test
description: Ensure colorbox can be tested properly with the downloaded library.
type: module
hidden: true
package: Testing
# core: 8.x
# Information added by Drupal.org packaging script on 2017-04-24
version: '8.x-1.4'
core: '8.x'
project: 'colorbox'
datestamp: 1493051361
@@ -0,0 +1,26 @@
<?php
/**
* @file
* Install file for the colorbox library test module.
*/
use Drupal\Core\Site\Settings;
/**
* Implements hook_install().
*/
function colorbox_library_test_install() {
$library_folder = Settings::get('file_public_path') . '/libraries';
$zip_file = $library_folder . '/colorbox.zip';
$colorbox_folder = $library_folder . '/colorbox';
if (file_exists($colorbox_folder)) {
return;
}
file_prepare_directory($library_folder, FILE_MODIFY_PERMISSIONS | FILE_CREATE_DIRECTORY);
copy('https://github.com/jackmoore/colorbox/archive/master.zip', $zip_file);
$zip = new \ZipArchive();
$zip->open($zip_file);
$zip->extractTo($library_folder);
rename($library_folder . '/colorbox-master', $colorbox_folder);
}
@@ -0,0 +1,21 @@
<?php
/**
* @file
* Test specific changes for the colorbox library test.
*/
use Drupal\Core\Site\Settings;
/**
* Implements hook_library_alter().
*/
function colorbox_library_test_library_info_alter(&$libraries, $extension) {
if ($extension !== 'colorbox') {
return;
}
foreach ($libraries['colorbox']['js'] as $key => $library) {
$libraries['colorbox']['js']['/' . Settings::get('file_public_path') . $key] = $library;
unset($libraries['colorbox']['js'][$key]);
}
}
@@ -0,0 +1,191 @@
<?php
namespace Drupal\Tests\colorbox\FunctionalJavascript;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\file\Entity\File;
use Drupal\FunctionalJavascriptTests\JavascriptTestBase;
use Drupal\simpletest\ContentTypeCreationTrait;
use Drupal\simpletest\NodeCreationTrait;
/**
* Test the colorbox JavaScript.
*
* @group colorbox
*/
class ColorboxJavascriptTest extends JavascriptTestBase {
use NodeCreationTrait;
use ContentTypeCreationTrait;
/**
* {@inheritdoc}
*/
public static $modules = [
'colorbox',
'colorbox_library_test',
'node',
];
/**
* How long to wait for colorbox to launch.
*/
const COLORBOX_WAIT_TIMEOUT = 500;
/**
* Node var.
*
* @var \Drupal\node\NodeInterface
*/
protected $node;
/**
* Test the colorbox launches when a gallery is clicked.
*/
public function testColorboxLaunches() {
$this->drupalGet('node/' . $this->node->id());
$this->getSession()->getPage()->find('css', 'img')->click();
$this->getSession()->wait(static::COLORBOX_WAIT_TIMEOUT);
$this->assertSession()->elementContains('css', '#colorbox', 'test.png');
}
/**
* Test the gallery works.
*/
public function testColorboxGallery() {
$this->drupalGet('node/' . $this->node->id());
// Click and launch the gallery.
$this->getSession()->getPage()->find('css', 'img')->click();
$this->getSession()->wait(static::COLORBOX_WAIT_TIMEOUT);
$this->assertSession()->elementContains('css', '#cboxTitle', 'Image title 1');
$this->assertSession()->elementContains('css', '#colorbox', 'test.png');
// Click on the next image and assert the second image is visible.
$this->assertSession()->elementExists('css', '#cboxNext')->click();
$this->getSession()->wait(static::COLORBOX_WAIT_TIMEOUT);
$this->assertSession()->elementContains('css', '#cboxTitle', 'Image title 2');
$this->assertSession()->elementContains('css', '#colorbox', 'test.png');
// Use alt captions.
\Drupal::entityTypeManager()
->getStorage('entity_view_display')
->load('node.page.default')
->setComponent('field_test_image', [
'type' => 'colorbox',
'settings' => ['colorbox_caption' => 'alt'],
'status' => TRUE,
])
->save();
drupal_flush_all_caches();
// Ensure the caption being used is the alt text.
$this->drupalGet('node/' . $this->node->id());
$this->getSession()->getPage()->find('css', 'img')->click();
$this->getSession()->wait(static::COLORBOX_WAIT_TIMEOUT);
$this->assertSession()->elementContains('css', '#cboxTitle', 'Image alt 1');
}
/**
* Test the mobile detection.
*/
public function testMobileDetection() {
$this->changeSetting('advanced.mobile_detect', TRUE);
$this->changeSetting('advanced.mobile_detect_width', '1200px');
$this->getSession()->resizeWindow(200, 200);
$this->drupalGet('node/' . $this->node->id());
$this->assertSession()->elementAttributeContains('css', '#colorbox', 'style', 'display: none;');
}
/**
* Test the admin form.
*/
public function testAdminForm() {
$this->drupalLogin($this->drupalCreateUser([
'administer site configuration',
]));
$this->drupalGet('admin/config/media/colorbox');
$this->assertFalse($this->getSession()->getPage()->find('css', '.form-item-colorbox-transition-speed')->isVisible());
$this->assertSession()->fieldExists('colorbox_custom_settings_activate')->setValue(TRUE);
$this->assertTrue($this->getSession()->getPage()->find('css', '.form-item-colorbox-transition-speed')->isVisible());
$this->assertSession()->fieldExists('colorbox_overlayclose')->setValue(FALSE);
$this->getSession()->getPage()->find('css', '.form-submit')->click();
$this->assertSession()->pageTextContains('The configuration options have been saved.');
}
/**
* Change a colorbox setting.
*
* @param string $setting
* The name of the setting.
* @param string $value
* The value.
*/
protected function changeSetting($setting, $value) {
\Drupal::configFactory()
->getEditable('colorbox.settings')
->set($setting, $value)
->save();
}
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->createContentType(['type' => 'page']);
FieldStorageConfig::create(array(
'field_name' => 'field_test_image',
'entity_type' => 'node',
'type' => 'image',
'settings' => [],
'cardinality' => 3,
))->save();
$field_config = FieldConfig::create([
'field_name' => 'field_test_image',
'label' => 'Colorbox Field',
'entity_type' => 'node',
'bundle' => 'page',
'required' => TRUE,
'settings' => [],
]);
$field_config->save();
\Drupal::entityTypeManager()
->getStorage('entity_view_display')
->load('node.page.default')
->setComponent('field_test_image', [
'type' => 'colorbox',
'settings' => [],
'status' => TRUE,
])
->save();
file_unmanaged_copy(DRUPAL_ROOT . '/core/modules/simpletest/files/image-1.png', 'public://test.png');
$file_a = File::create([
'uri' => 'public://test.png',
'filename' => 'test.png',
]);
$file_a->save();
$file_b = File::create([
'uri' => 'public://test.png',
'filename' => 'test.png',
]);
$file_b->save();
$this->node = $this->createNode([
'type' => 'page',
'field_test_image' => [
[
'target_id' => $file_a->id(),
'alt' => 'Image alt 1',
'title' => 'Image title 1',
],
[
'target_id' => $file_b->id(),
'alt' => 'Image alt 2',
'title' => 'Image title 2',
],
],
]);
}
}