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
-24
View File
@@ -9,30 +9,6 @@ sites/*/private
sites/*/translations sites/*/translations
# Ignore default text files # Ignore default text files
robots.txt
/CHANGELOG.txt
/COPYRIGHT.txt
/INSTALL*.txt
/LICENSE.txt
/MAINTAINERS.txt
/UPGRADE.txt
/README.txt
sites/README.txt
sites/all/libraries/README.txt
sites/all/modules/README.txt
sites/all/themes/README.txt
# Ignore everything but the "sites" folder ( for non core developer ) # Ignore everything but the "sites" folder ( for non core developer )
.htaccess .htaccess
web.config
authorize.php
cron.php
index.php
install.php
update.php
xmlrpc.php
/includes
/misc
/modules
/profiles
/scripts
+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.
+139
View File
@@ -0,0 +1,139 @@
CONTENTS OF THIS FILE
---------------------
* About Drupal
* Configuration and features
* Installation profiles
* Appearance
* Developing for Drupal
* More information
ABOUT DRUPAL
------------
Drupal is an open source content management platform supporting a variety of
websites ranging from personal weblogs to large community-driven websites. For
more information, see the Drupal website at https://www.drupal.org, and join
the Drupal community at https://www.drupal.org/community.
Legal information about Drupal:
* Know your rights when using Drupal:
See LICENSE.txt in the "core" directory.
* Learn about the Drupal trademark and logo policy:
https://www.drupal.com/trademark
CONFIGURATION AND FEATURES
--------------------------
Drupal core (what you get when you download and extract a drupal-x.y.tar.gz or
drupal-x.y.zip file from https://www.drupal.org/project/drupal) has what you
need to get started with your website. It includes several modules (extensions
that add functionality) for common website features, such as managing content,
user accounts, image uploading, and search. Core comes with many options that
allow site-specific configuration. In addition to the core modules, there are
thousands of contributed modules (for functionality not included with Drupal
core) available for download.
More about configuration:
* Install, update, and maintain Drupal:
See INSTALL.txt and UPDATE.txt in the "core" directory.
* Learn about how to use Drupal to create your site:
https://www.drupal.org/documentation
* Follow best practices:
https://www.drupal.org/best-practices
* Download contributed modules to /modules to extend Drupal's functionality:
https://www.drupal.org/project/modules
* See also: "Developing for Drupal" for writing your own modules, below.
INSTALLATION PROFILES
---------------------
Installation profiles define additional steps (such as enabling modules,
defining content types, etc.) that run after the base installation provided
by core when Drupal is first installed. There are two basic installation
profiles provided with Drupal core.
Installation profiles from the Drupal community modify the installation process
to provide a website for a specific use case, such as a CMS for media
publishers, a web-based project tracking tool, or a full-fledged CRM for
non-profit organizations raising money and accepting donations. They can be
distributed as bare installation profiles or as "distributions". Distributions
include Drupal core, the installation profile, and all other required
extensions, such as contributed and custom modules, themes, and third-party
libraries. Bare installation profiles require you to download Drupal Core and
the required extensions separately; place the downloaded profile in the
/profiles directory before you start the installation process.
More about installation profiles and distributions:
* Read about the difference between installation profiles and distributions:
https://www.drupal.org/node/1089736
* Download contributed installation profiles and distributions:
https://www.drupal.org/project/distributions
* Develop your own installation profile or distribution:
https://www.drupal.org/developing/distributions
APPEARANCE
----------
In Drupal, the appearance of your site is set by the theme (themes are
extensions that set fonts, colors, and layout). Drupal core comes with several
themes. More themes are available for download, and you can also create your own
custom theme.
More about themes:
* Download contributed themes to /themes to modify Drupal's appearance:
https://www.drupal.org/project/themes
* Develop your own theme:
https://www.drupal.org/documentation/theme
DEVELOPING FOR DRUPAL
---------------------
Drupal contains an extensive API that allows you to add to and modify the
functionality of your site. The API consists of "hooks", which allow modules to
react to system events and customize Drupal's behavior, and functions that
standardize common operations such as database queries and form generation. The
flexible hook architecture means that you should never need to directly modify
the files that come with Drupal core to achieve the functionality you want;
instead, functionality modifications take the form of modules.
When you need new functionality for your Drupal site, search for existing
contributed modules. If you find a module that matches except for a bug or an
additional needed feature, change the module and contribute your improvements
back to the project in the form of a "patch". Create new custom modules only
when nothing existing comes close to what you need.
More about developing:
* Search for existing contributed modules:
https://www.drupal.org/project/modules
* Contribute a patch:
https://www.drupal.org/patch/submit
* Develop your own module:
https://www.drupal.org/developing/modules
* Follow programming best practices:
https://www.drupal.org/developing/best-practices
* Refer to the API documentation:
https://api.drupal.org/api/drupal/8
* Learn from documented Drupal API examples:
https://www.drupal.org/project/examples
MORE INFORMATION
----------------
* See the Drupal.org online documentation:
https://www.drupal.org/documentation
* For a list of security announcements, see the "Security advisories" page at
https://www.drupal.org/security (available as an RSS feed). This page also
describes how to subscribe to these announcements via email.
* For information about the Drupal security process, or to find out how to
report a potential security issue to the Drupal security team, see the
"Security team" page at https://www.drupal.org/security-team
* For information about the wide range of available support options, visit
https://www.drupal.org and click on Community and Support in the top or
bottom navigation.
+198
View File
@@ -0,0 +1,198 @@
<?php
/**
* @file
* Administrative script for running authorized file operations.
*
* Using this script, the site owner (the user actually owning the files on the
* webserver) can authorize certain file-related operations to proceed with
* elevated privileges, for example to deploy and upgrade modules or themes.
* Users should not visit this page directly, but instead use an administrative
* user interface which knows how to redirect the user to this script as part of
* a multistep process. This script actually performs the selected operations
* without loading all of Drupal, to be able to more gracefully recover from
* errors. Access to the script is controlled by a global killswitch in
* settings.php ('allow_authorize_operations') and via the 'administer software
* updates' permission.
*
* There are helper functions for setting up an operation to run via this
* system in modules/system/system.module. For more information, see:
* @link authorize Authorized operation helper functions @endlink
*/
use Drupal\Core\DrupalKernel;
use Drupal\Core\Form\EnforcedResponseException;
use Drupal\Core\Url;
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Drupal\Core\Site\Settings;
// Change the directory to the Drupal root.
chdir('..');
$autoloader = require_once 'autoload.php';
/**
* Global flag to identify update.php and authorize.php runs.
*
* Identifies update.php and authorize.php runs, avoiding unwanted operations
* such as css/js preprocessing and translation, and solves some theming issues.
* The flag is checked in other places in Drupal code (not just authorize.php).
*/
const MAINTENANCE_MODE = 'update';
/**
* Determines if the current user is allowed to run authorize.php.
*
* The killswitch in settings.php overrides all else, otherwise, the user must
* have access to the 'administer software updates' permission.
*
* @param \Symfony\Component\HttpFoundation\Request $request
* The incoming request.
*
* @return bool
* TRUE if the current user can run authorize.php, and FALSE if not.
*/
function authorize_access_allowed(Request $request) {
$account = \Drupal::service('authentication')->authenticate($request);
if ($account) {
\Drupal::currentUser()->setAccount($account);
}
return Settings::get('allow_authorize_operations', TRUE) && \Drupal::currentUser()->hasPermission('administer software updates');
}
try {
$request = Request::createFromGlobals();
$kernel = DrupalKernel::createFromRequest($request, $autoloader, 'prod');
$kernel->prepareLegacyRequest($request);
}
catch (HttpExceptionInterface $e) {
$response = new Response('', $e->getStatusCode());
$response->prepare($request)->send();
exit;
}
// We have to enable the user and system modules, even to check access and
// display errors via the maintenance theme.
\Drupal::moduleHandler()->addModule('system', 'core/modules/system');
\Drupal::moduleHandler()->addModule('user', 'core/modules/user');
\Drupal::moduleHandler()->load('system');
\Drupal::moduleHandler()->load('user');
// Initialize the maintenance theme for this administrative script.
drupal_maintenance_theme();
$content = [];
$show_messages = TRUE;
$is_allowed = authorize_access_allowed($request);
// Build content.
if ($is_allowed) {
// Load both the Form API and Batch API.
require_once __DIR__ . '/includes/form.inc';
require_once __DIR__ . '/includes/batch.inc';
if (isset($_SESSION['authorize_page_title'])) {
$page_title = $_SESSION['authorize_page_title'];
}
else {
$page_title = t('Authorize file system changes');
}
// See if we've run the operation and need to display a report.
if (isset($_SESSION['authorize_results']) && $results = $_SESSION['authorize_results']) {
// Clear the session out.
unset($_SESSION['authorize_results']);
unset($_SESSION['authorize_operation']);
unset($_SESSION['authorize_filetransfer_info']);
if (!empty($results['page_title'])) {
$page_title = $results['page_title'];
}
if (!empty($results['page_message'])) {
drupal_set_message($results['page_message']['message'], $results['page_message']['type']);
}
$content['authorize_report'] = [
'#theme' => 'authorize_report',
'#messages' => $results['messages'],
];
if (is_array($results['tasks'])) {
$links = $results['tasks'];
}
else {
// Since this is being called outsite of the primary front controller,
// the base_url needs to be set explicitly to ensure that links are
// relative to the site root.
// @todo Simplify with https://www.drupal.org/node/2548095
$default_options = [
'#type' => 'link',
'#options' => [
'absolute' => TRUE,
'base_url' => $GLOBALS['base_url'],
],
];
$links = [
$default_options + [
'#url' => Url::fromRoute('system.admin'),
'#title' => t('Administration pages'),
],
$default_options + [
'#url' => Url::fromRoute('<front>'),
'#title' => t('Front page'),
],
];
}
$content['next_steps'] = [
'#theme' => 'item_list',
'#items' => $links,
'#title' => t('Next steps'),
];
}
// If a batch is running, let it run.
elseif ($request->query->has('batch')) {
$content = _batch_page($request);
// If _batch_page() returns a response object (likely a JsonResponse for
// JavaScript-based batch processing), send it immediately.
if ($content instanceof Response) {
$content->send();
exit;
}
}
else {
if (empty($_SESSION['authorize_operation']) || empty($_SESSION['authorize_filetransfer_info'])) {
$content = ['#markup' => t('It appears you have reached this page in error.')];
}
elseif (!$batch = batch_get()) {
// We have a batch to process, show the filetransfer form.
try {
$content = \Drupal::formBuilder()->getForm('Drupal\Core\FileTransfer\Form\FileTransferAuthorizeForm');
}
catch (EnforcedResponseException $e) {
$e->getResponse()->send();
exit;
}
}
}
// We defer the display of messages until all operations are done.
$show_messages = !(($batch = batch_get()) && isset($batch['running']));
}
else {
\Drupal::logger('access denied')->warning('authorize.php');
$page_title = t('Access denied');
$content = ['#markup' => t('You are not allowed to access this page.')];
}
$bare_html_page_renderer = \Drupal::service('bare_html_page_renderer');
$response = $bare_html_page_renderer->renderBarePage($content, $page_title, 'maintenance_page', [
'#show_messages' => $show_messages,
]);
if (!$is_allowed) {
$response->setStatusCode(403);
}
$response->send();
+44
View File
@@ -0,0 +1,44 @@
<?php
/**
* @file
* Initiates a browser-based installation of Drupal.
*/
use Drupal\Component\Utility\OpCodeCache;
// Change the directory to the Drupal root.
chdir('..');
// Store the Drupal root path.
$root_path = realpath('');
/**
* Global flag to indicate the site is in installation mode.
*
* The constant is defined using define() instead of const so that PHP
* versions prior to 5.3 can display proper PHP requirements instead of causing
* a fatal error.
*/
define('MAINTENANCE_MODE', 'install');
// Exit early if running an incompatible PHP version to avoid fatal errors.
// The minimum version is specified explicitly, as DRUPAL_MINIMUM_PHP is not
// yet available. It is defined in bootstrap.inc, but it is not possible to
// load that file yet as it would cause a fatal error on older versions of PHP.
if (version_compare(PHP_VERSION, '5.5.9') < 0) {
print 'Your PHP installation is too old. Drupal requires at least PHP 5.5.9. See the <a href="https://www.drupal.org/requirements">system requirements</a> page for more information.';
exit;
}
// Initialize the autoloader.
$class_loader = require_once $root_path . '/autoload.php';
// If OPCache is in use, ensure opcache.save_comments is enabled.
if (OpCodeCache::isEnabled() && !ini_get('opcache.save_comments')) {
print 'Systems with OPcache installed must have <a href="http://php.net/manual/en/opcache.configuration.php#ini.opcache.save-comments">opcache.save_comments</a> enabled.';
exit();
}
// Start the installer.
require_once $root_path . '/core/includes/install.core.inc';
install_drupal($class_loader);
+22
View File
@@ -0,0 +1,22 @@
<?php
/**
* @file
* The PHP page that serves all page requests on a Drupal installation.
*
* All Drupal code is released under the GNU General Public License.
* See COPYRIGHT.txt and LICENSE.txt files in the "core" directory.
*/
use Drupal\Core\DrupalKernel;
use Symfony\Component\HttpFoundation\Request;
$autoloader = require_once 'autoload.php';
$kernel = new DrupalKernel('prod', $autoloader);
$request = Request::createFromGlobals();
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);
+42
View File
@@ -0,0 +1,42 @@
Modules extend your site functionality beyond Drupal core.
WHAT TO PLACE IN THIS DIRECTORY?
--------------------------------
Placing downloaded and custom modules in this directory separates downloaded and
custom modules from Drupal core's modules. This allows Drupal core to be updated
without overwriting these files.
DOWNLOAD ADDITIONAL MODULES
---------------------------
Contributed modules from the Drupal community may be downloaded at
https://www.drupal.org/project/project_module.
ORGANIZING MODULES IN THIS DIRECTORY
------------------------------------
You may create subdirectories in this directory, to organize your added modules,
without breaking the site. Some common subdirectories include "contrib" for
contributed modules, and "custom" for custom modules. Note that if you move a
module to a subdirectory after it has been enabled, you may need to clear the
Drupal cache so it can be found.
There are number of directories that are ignored when looking for modules. These
are 'src', 'lib', 'vendor', 'assets', 'css', 'files', 'images', 'js', 'misc',
'templates', 'includes', 'fixtures' and 'Drupal'.
MULTISITE CONFIGURATION
-----------------------
In multisite configurations, modules found in this directory are available to
all sites. You may also put modules in the sites/all/modules directory, and the
versions in sites/all/modules will take precedence over versions of the same
module that are here. Alternatively, the sites/your_site_name/modules directory
pattern may be used to restrict modules to a specific site instance.
MORE INFORMATION
----------------
Refer to the “Developing for Drupal” section of the README.txt in the Drupal
root directory for further information on extending Drupal with custom modules.
+21
View File
@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2016 Purushotam Rai
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
+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.
+83
View File
@@ -0,0 +1,83 @@
CONTENTS OF THIS FILE
---------------------
* Introduction
* Module Details
* Recommended modules
* Configuration
* Troubleshooting
* FAQ
* Maintainers
INTRODUCTION
------------
Add to Calendar Module integrates 'Add to Calendar' button provided by
addtocalendar.com which supports iCalender, Google Calendar, Outlook,
Outlook Online and Yahoo Calendar. It's basically a thirdparty field
formatter setting available for datetime field formatters.
MODULE DETAILS
--------------
Add to Calendar Module makes use of ADDTOCALENDAR.COM's service which
provides free button for event page on website and email. Button
supports all modern browsers and platforms: iOS, iPad, iPhone, Android,
Windows, Blackberry. Provides handful of configuration for a really
flexible experience.
Module internally extends Datetime field formatters using third party
settings to append the "Add to Calendar" button besides date field.
When clicked on this button, the event is exported to the corresponding
website with proper information in the next tab where user can add the
event to their calendar.
External CSS and JS files are provided by Addtocalendar.com
SIMILAR MODULES
---------------
* Addtocal (https://www.drupal.org/project/addtocal)
A field formatter providing a widget for exporting events to:
Google Calendar
Yahoo! Calendar
iCal
Outlook
CONFIGURATION
-------------
* Style: As of now 3 styles are available (Blue, Glow Orange and Basic).
* Display Text: Text to be displayed on the button.
* Title, Description, Location, Organizer, Organizer Email, End Date:
These are for collecting event information, which can be configured to
be collected from other fields, direct static data or tokens.
* Private: Use public for free access to event information from any
places. User private if the event is closed to public access.
* Security Level: Use https to protect your users.
* List of calenders to show in button list.
TROUBLESHOOTING
---------------
As of now, Add to calendar Module uses Addtocalandar.com service and
css, js files. In case the module is not working properly, you may try:
* Rebuilding the cache
* Reinstalling the module.
* Try different style.
MAINTAINERS
-----------
Current maintainers:
* Purushotam Rai (https://drupal.org/user/3193859)
This project has been sponsored by:
* QED42
QED42 is a web development agency focussed on helping organisations and
individuals reach their potential, most of our work is in the space of
publishing, e-commerce, social and enterprise.
@@ -0,0 +1,13 @@
name: Add To Calendar
type: module
description: 'Add to calendar button to be used for event page.'
# version: VERSION
# core: 8.x
dependencies:
- datetime
# Information added by Drupal.org packaging script on 2017-04-26
version: '8.x-2.0'
core: '8.x'
project: 'addtocalendar'
datestamp: 1493189646
@@ -0,0 +1,16 @@
base:
css:
component:
'//addtocalendar.com/atc/1.5/atc-base.css': {type: external}
js:
'//addtocalendar.com/atc/1.5/atc.min.js': { type: external, minified: true }
glow_orange:
css:
component:
'//addtocalendar.com/atc/1.5/atc-style-glow-orange.css': {type: external}
blue:
css:
component:
'//addtocalendar.com/atc/1.5/atc-style-blue.css': {type: external}
@@ -0,0 +1,54 @@
<?php
/**
* @file
* Contains module code.
*/
use Drupal\Core\Routing\RouteMatchInterface;
require 'includes/addtocalendar.form.inc';
require 'includes/addtocalendar.build.inc';
/**
* Implements hook_help().
*/
function addtocalendar_help($route_name, RouteMatchInterface $route_match) {
switch ($route_name) {
case 'help.page.addtocalendar':
$output = file_get_contents(drupal_get_path('module', 'addtocalendar') . '/README.md');
return $output;
}
}
/**
* Implements hook_field_formatter_third_party_settings_form().
*/
function addtocalendar_field_formatter_third_party_settings_form($plugin, $field_definition, $view_mode, $form, $form_state) {
$element = [];
if (count(array_intersect(['datetime', 'daterange'], $plugin->getPluginDefinition()['field_types']))) {
$settings = $plugin->getThirdPartySettings('addtocalendar');
$element = _addtocalendar_build_form($settings, $field_definition);
}
return $element;
}
/**
* Implements hook_field_formatter_settings_summary_alter().
*/
function addtocalendar_field_formatter_settings_summary_alter(&$summary, $context) {
if (count(array_intersect(['datetime', 'daterange'], $context['formatter']->getPluginDefinition()['field_types']))) {
if ($context['formatter']->getThirdPartySetting('addtocalendar', 'addtocalendar_show')) {
$summary[] = t('Add to calendar enabled');
}
}
}
/**
* Implements hook_preprocess_field().
*/
function addtocalendar_preprocess_field(&$variables) {
if ($variables['field_type'] == 'datetime' || $variables['field_type'] == 'daterange') {
_addtocalendar_preprocess_field($variables);
}
}
@@ -0,0 +1,196 @@
<?php
/**
* @file
* Contains preprocess helper function.
*/
use \Drupal\Core\Entity\Entity\EntityViewDisplay;
use \Drupal\Core\Datetime\DrupalDateTime;
/**
* Helper function to preprocess datetime field.
*/
function _addtocalendar_preprocess_field(&$variables) {
$entity = $variables['element']['#object'];
$view_mode = $variables['element']['#view_mode'];
$field_name = $variables['element']['#field_name'];
// Get the field formatter settings...
$entity_display = EntityViewDisplay::collectRenderDisplay($entity, $view_mode);
$field_display = $entity_display->getComponent($field_name);
if (!empty($field_display['third_party_settings']['addtocalendar'])) {
$build['addtocalendar'] = [];
$settings = $field_display['third_party_settings']['addtocalendar'];
$style = [];
if ($settings['addtocalendar_show']) {
$token_service = \Drupal::token();
$token_options = ['langcode' => $entity->language()->getId(), 'callback' => '', 'clear' => TRUE];
$timeZone = date_default_timezone_get();
$values = $entity->{$field_name}->getValue();
$delta = !empty($settings['addtocalendar_settings']['delta']) ? $settings['addtocalendar_settings']['delta'] : 0;
if (empty($values[$delta]['value'])) {
return;
}
// Unsetting values other than delta if single value is selected.
if ($settings['addtocalendar_settings']['multiple_value'] == 1) {
$temp = $values[$delta];
unset($values);
$values = array($delta => $temp);
unset($temp);
}
foreach ($values as $index => $date_val) {
$date = new DrupalDateTime(preg_replace('/T/', ' ', $values[$index]['value']), 'UTC');
if (!empty($values[$index]['end_value']) && isset($values[$index]['end_value'])) {
$end_date = new DrupalDateTime(preg_replace('/T/', ' ', $values[$index]['end_value']), 'UTC');
}
$build['addtocalendar'][$index]['atc_date_start'] = [
'#type' => 'html_tag',
'#tag' => 'var',
'#value' => $date->format('Y-m-d H:i:s', ['timezone' => $timeZone]),
'#attributes' => [
'class' => 'atc_date_start',
],
];
$info = [
'atc_date_end',
'atc_title',
'atc_description',
'atc_location',
'atc_organizer',
'atc_organizer_email',
];
foreach ($info as $value) {
switch ($settings['addtocalendar_settings'][$value]['field']) {
case 'token':
$class_value = $settings['addtocalendar_settings'][$value]['tokenized'];
$class_value = $token_service->replace($class_value, array('node' => $entity), $token_options);
break;
case 'title':
$class_value = $entity->getTitle();
break;
default:
$field = $settings['addtocalendar_settings'][$value]['field'];
if (strip_tags($entity->{$field}->getFieldDefinition()
->getType()) == 'daterange'
) {
$class_value = strip_tags($entity->{$field}->end_value);
}
else {
$class_value = strip_tags($entity->{$field}->value);
}
break;
}
$build['addtocalendar'][$index][$value] = [
'#type' => 'html_tag',
'#tag' => 'var',
'#value' => $class_value,
'#attributes' => [
'class' => $value,
],
];
}
// Assign end date the value of start date if no end date is present and its not a daterange field.
if (empty($end_date)) {
$build['addtocalendar'][$index]['atc_date_end']['#value'] = (!empty($build['addtocalendar'][$index]['atc_date_end']['#value'])) ? $build['addtocalendar'][$index]['atc_date_end']['#value'] : $build['addtocalendar'][$index]['atc_date_start']['#value'];
$build['addtocalendar'][$index]['atc_date_end']['#value'] = (!empty($build['addtocalendar'][$index]['atc_date_end']['#value'])) ? $build['addtocalendar'][$index]['atc_date_start']['#value'] : $date->format('Y-m-d H:i:s', ['timezone' => $timeZone]);
}
// Assign end date the value of end date if no end date is present and its a daterange field.
else {
$end_date_val = $end_date->__toString();
$build['addtocalendar'][$index]['atc_date_end']['#value'] = (!empty($build['addtocalendar'][$index]['atc_date_end']['#value'])) ? $build['addtocalendar'][$index]['atc_date_end']['#value'] : $end_date_val;
$build['addtocalendar'][$index]['atc_date_end']['#value'] = $end_date->format('Y-m-d H:i:s', ['timezone' => $timeZone]);
}
$build['addtocalendar'][$index]['atc_timezone'] = [
'#type' => 'html_tag',
'#tag' => 'var',
'#value' => $timeZone,
'#attributes' => [
'class' => 'atc_timezone',
],
];
$build['addtocalendar'][$index]['atc_privacy'] = [
'#type' => 'html_tag',
'#tag' => 'var',
'#value' => $settings['addtocalendar_settings']['atc_privacy'],
'#attributes' => [
'class' => 'atc_privacy',
],
];
$build['addtocalendar'][$index] = [
'#type' => 'html_tag',
'#tag' => 'span',
'#value' => '<var class="atc_event">' . render($build['addtocalendar'][$index]) . '</var>',
'#attributes' => [
'class' => [
'addtocalendar',
],
],
];
if ($settings['addtocalendar_settings']['data_calendars']) {
$value = '';
foreach ($settings['addtocalendar_settings']['data_calendars'] as $key => $set) {
if ($set) {
$value .= $key . ', ';
}
}
if ($value) {
$build['addtocalendar'][$index]['#attributes']['data-calendars'] = $value;
}
}
$build['addtocalendar'][$index]['#attributes']['data-secure'] = $settings['addtocalendar_settings']['data_secure'];
// Styling.
switch ($settings['addtocalendar_settings']['style']) {
case 'blue':
$style['class'] = 'atc-style-blue';
$style['library'] = 'addtocalendar/blue';
break;
case 'glow_orange':
$style['class'] = 'atc-style-glow-orange';
$style['library'] = 'addtocalendar/glow_orange';
break;
}
if (!empty($style)) {
$build['addtocalendar'][$index]['#attributes']['class'][] = $style['class'];
$variables['#attached']['library'][] = $style['library'];
}
}
}
// Setting #markup for all the date or daterange fields if multivalue is selected.
if ($settings['addtocalendar_settings']['multiple_value'] == 2) {
foreach ($variables['items'] as $k => $content) {
if (isset($variables['items'][$k]['content']['#markup'])) {
$variables['items'][$k]['content']['#markup'] .= render($build['addtocalendar'][$k]);
}
elseif (isset($variables['items'][$k]['content'])) {
unset($variables['items'][$k]['content']['#theme']);
$variables['items'][$k]['content']['#markup'] = $variables['items'][$k]['content']['#text'] . render($build['addtocalendar'][$k]);
}
$variables['#attached']['library'][] = 'addtocalendar/base';
}
}
// Setting #markup for all the date or daterange fields if single value is selected.
else {
if (isset($variables['items'][$delta]['content']['#markup'])) {
$variables['items'][$delta]['content']['#markup'] .= render($build['addtocalendar']);
}
elseif (isset($variables['items'][$delta]['content'])) {
unset($variables['items'][$delta]['content']['#theme']);
$variables['items'][$delta]['content']['#markup'] = $variables['items'][$delta]['content']['#text'] . render($build['addtocalendar']);
}
$variables['#attached']['library'][] = 'addtocalendar/base';
}
}
}
@@ -0,0 +1,183 @@
<?php
/**
* @file
* Contains form for addtocalendar module.
*/
/**
* Creates Settings form.
*
* @param $settings
* Third party Settings array.
* @param $field_definition
* Field Definition of current field.
*
* @return array
*/
function _addtocalendar_build_form($settings, $field_definition) {
$element = [];
$element['addtocalendar_show'] = [
'#type' => 'checkbox',
'#title' => t('Show Add to Calendar'),
'#default_value' => !empty($settings['addtocalendar_show']) ? $settings['addtocalendar_show'] : 0,
];
$element['addtocalendar_settings'] = [
'#type' => 'fieldset',
'#title' => t('Add to Calendar Settings'),
'#states' => [
'visible' => [
'input[name*="addtocalendar_show"]' => ['checked' => TRUE],
],
],
];
$element['addtocalendar_settings']['style'] = [
'#type' => 'select',
'#title' => t('Select Style'),
'#options' => [
0 => t('No Styling'),
'blue' => t('Blue'),
'glow_orange' => t('Glow Orange'),
],
'#default_value' => !empty($settings['addtocalendar_settings']['style']) ? $settings['addtocalendar_settings']['style'] : 'blue',
];
$element['addtocalendar_settings']['display_text'] = [
'#type' => 'textfield',
'#title' => t('Display Text'),
'#default_value' => !empty($settings['addtocalendar_settings']['display_text']) ? $settings['addtocalendar_settings']['display_text'] : t('Add to Calender'),
];
// Fetching site name and site email id.
$config = \Drupal::config('system.site');
$site_name = $config->get('name');
$site_mail = $config->get('mail');
$info = [
'atc_title' => [
'label' => t('Title'),
'sample_data' => 'Title',
],
'atc_description' => [
'label' => t('Description'),
'sample_data' => 'Description',
],
'atc_location' => [
'label' => t('Location'),
'sample_data' => 'Location',
],
'atc_organizer' => [
'label' => t('Organizer'),
'sample_data' => $site_name,
],
'atc_organizer_email' => [
'label' => t('Organizer'),
'sample_data' => $site_mail,
],
'atc_date_end' => [
'label' => t('End Date'),
'sample_data' => '',
],
];
$fields = Drupal::service('entity_field.manager')->getFieldDefinitions($field_definition->get('entity_type'), $field_definition->get('bundle'));
$field_options = [];
foreach ($fields as $id => $field) {
if (is_a($field, 'Drupal\field\Entity\FieldConfig')) {
$field_options[$id] = $field->getLabel();
}
}
$field_options = array_merge(
['token' => t('Use Token/Static Content')],
['title' => t('Title')],
$field_options
);
if (\Drupal::moduleHandler()->moduleExists('token')) {
$element['addtocalendar_settings']['token_help'] = [
'#type' => 'markup',
'#token_types' => array('node'),
'#theme' => 'token_tree_link',
];
}
foreach ($info as $id => $data) {
$element['addtocalendar_settings'][$id]['field'] = [
'#type' => 'select',
'#title' => $data['label'] . t(': field'),
'#options' => $field_options,
'#description' => t('Select field to be used as @label for calendar events', array('@label' => $data['label'])),
'#default_value' => !empty($settings['addtocalendar_settings'][$id]['field']) ? $settings['addtocalendar_settings'][$id]['field'] : '',
];
$element['addtocalendar_settings'][$id]['tokenized'] = [
'#type' => 'textfield',
'#title' => $data['label'] . t(': Static/Tokenized Content'),
'#default_value' => !empty($settings['addtocalendar_settings'][$id]['tokenized']) ? $settings['addtocalendar_settings'][$id]['tokenized'] : $data['sample_data'],
];
}
$element['addtocalendar_settings']['atc_privacy'] = [
'#type' => 'select',
'#title' => t('Privacy'),
'#options' => [
'public' => t('Public'),
'private' => t('Private'),
],
'#description' => t('Use public for free access to event information from any places. User private if the event is closed to public access.'),
'#default_value' => !empty($settings['addtocalendar_settings']['atc_privacy']) ? $settings['addtocalendar_settings']['atc_privacy'] : '',
];
$element['addtocalendar_settings']['data_secure'] = [
'#type' => 'select',
'#title' => t('Security level'),
'#options' => [
'auto' => t('Auto'),
'true' => t('Use https only'),
'false' => t('Use http only'),
],
'#default_value' => !empty($settings['addtocalendar_settings']['data_secure']) ? $settings['addtocalendar_settings']['data_secure'] : '',
];
$element['addtocalendar_settings']['data_calendars'] = [
'#type' => 'checkboxes',
'#options' => [
'iCalendar' => t('iCalendar'),
'Google Calendar' => t('Google Calendar'),
'Outlook' => t('Outlook'),
'Outlook Online' => t('Outlook Online'),
'Yahoo! Calendar' => t('Yahoo! Calendar'),
],
'#default_value' => !empty($settings['addtocalendar_settings']['data_calendars']) ? $settings['addtocalendar_settings']['data_calendars'] : '',
'#title' => t('List of calendars to show in button list.'),
];
$cardinality = $field_definition->getFieldStorageDefinition()->getCardinality();
if ($cardinality != 1) {
$element['addtocalendar_settings']['multiple_value'] = [
'#type' => 'select',
'#title' => t('AddToCalendar button visibility'),
'#options' => [
1 => t('Single'),
2 => t('All'),
],
'#default_value' => !empty($settings['addtocalendar_settings']['multiple_value']) ? $settings['addtocalendar_settings']['multiple_value'] : 1,
];
$element['addtocalendar_settings']['delta'] = [
'#type' => 'textfield',
'#title' => t('Delta'),
'#description' => 'AddToCalendar button visibility for a particular date field (default starts with 0).',
'#states' => [
'visible' => [
':input[name="fields[' . $field_definition->get('field_name') . '][settings_edit_form][third_party_settings][addtocalendar][addtocalendar_settings][multiple_value]"]' => [
'value' => 1,
],
],
],
'#default_value' => !empty($settings['addtocalendar_settings']['delta']) ? $settings['addtocalendar_settings']['delta'] : 0,
];
}
return $element;
}
+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',
],
],
]);
}
}
+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.
+57
View File
@@ -0,0 +1,57 @@
CONTENTS OF THIS FILE
---------------------
* Introduction
* Requirements
* Installation
* Configuration
* Maintainers
INTRODUCTION
------------
Colorbox Inline allows you to open content already on the page within a
colorbox. If you would like to load content via AJAX, you can use colorbox_load.
REQUIREMENTS
------------
Requires the following modules:
* Colorbox (https://drupal.org/project/colorbox)
To create an element which opens the colorbox on click:
Add a the attribute data-colorbox-inline to an element and make it's value a
selector for the content you wish to open.
Eg, <a data-colorbox-inline=".user-login">User Login</a>.
Optional extra configuration you can add:
- `data-width` and `data-height` to the anchor to control the size of the
modal window.
- `data-class` to add a class to the colorbox wrapper.
INSTALLATION
------------
Install as you would normally install a contributed Drupal module. See:
https://drupal.org/documentation/install/modules-themes/modules-8 for further
information.
CONFIGURATION
-------------
No special requirements
MAINTAINERS
-----------
Current maintainers:
* Sam Becker (Sam152) - https://www.drupal.org/user/1485048
* Renato Gonçalves (RenatoG) - https://www.drupal.org/user/3326031
* Nick Wilde (NickWilde) - https://www.drupal.org/u/nickwilde
@@ -0,0 +1,14 @@
name: Colorbox Inline
type: module
description: Enabled the "colorbox inline" functionality for Drupal 8.
package: Media
# core: 8.x
dependencies:
- drupal:colorbox
# Information added by Drupal.org packaging script on 2017-11-01
version: '8.x-1.0'
core: '8.x'
project: 'colorbox_inline'
datestamp: 1509503290
@@ -0,0 +1,5 @@
colorbox_inline:
js:
js/colorbox_inline.js: {}
dependencies:
- colorbox/colorbox
@@ -0,0 +1,14 @@
<?php
/**
* @file
* Enabled the "colorbox inline" functionality for Drupal 8.
*/
/**
* Implements hook_page_attachments().
*/
function colorbox_inline_page_attachments(array &$page) {
\Drupal::service('colorbox.attachment')->attach($page);
$page['#attached']['library'][] = 'colorbox_inline/colorbox_inline';
}
@@ -0,0 +1,23 @@
(function ($) {
"use strict";
/**
* Enable the colorbox inline functionality.
*/
Drupal.behaviors.colorboxInline = {
attach: function (context, drupalSettings) {
$('[data-colorbox-inline]', context).once().click(function () {
var $link = $(this);
var settings = $.extend({}, drupalSettings.colorbox, {
href: false,
inline: true
}, {
className: $link.data('class'),
href: $link.data('colorbox-inline'),
width: $link.data('width'),
height: $link.data('height')
});
$link.colorbox(settings);
});
}
};
})(jQuery);
+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.
@@ -0,0 +1,16 @@
name: Colorbox Load
type: module
description: 'Allow you to load any content in a colorbox.'
package: Media
# core: 8.x
configure: ng_lightbox.settings
dependencies:
- colorbox
- ng_lightbox
# Information added by Drupal.org packaging script on 2016-07-07
version: '8.x-1.0-rc2'
core: '8.x'
project: 'colorbox_load'
datestamp: 1467852845
@@ -0,0 +1,24 @@
<?php
/**
* @file
* Colorbox load file.
*/
/**
* Implements hook_install().
*/
function colorbox_load_install() {
$config = \Drupal::configFactory()->getEditable('ng_lightbox.settings');
$config->set('renderer', 'drupal_colorbox');
$config->save();
}
/**
* Implements hook_uninstall().
*/
function colorbox_load_uninstall() {
$config = \Drupal::configFactory()->getEditable('ng_lightbox.settings');
$config->set('renderer', NULL);
$config->save();
}
@@ -0,0 +1,6 @@
colorbox_load:
js:
js/colorbox_load.js: {}
dependencies:
- core/drupal.ajax
- colorbox/colorbox
@@ -0,0 +1,14 @@
<?php
/**
* @file
* Allow you to load any content in a colorbox.
*/
/**
* Implements hook_page_attachments().
*/
function colorbox_load_page_attachments(array &$page) {
\Drupal::service('colorbox.attachment')->attach($page);
$page['#attached']['library'][] = 'colorbox_load/colorbox_load';
}
@@ -0,0 +1,5 @@
services:
colorbox_load.renderer:
class: Drupal\colorbox_load\Renderer
tags:
- { name: render.main_content_renderer, format: drupal_colorbox, ng_lightbox: Colorbox }
+11
View File
@@ -0,0 +1,11 @@
(function ($) {
"use strict";
Drupal.AjaxCommands.prototype.colorboxLoadOpen = function (ajax, response) {
$.colorbox($.extend(drupalSettings.colorbox, {
html: response.data,
width: '90%',
height: '90%'
}));
Drupal.attachBehaviors(response.data);
};
})(jQuery);
+44
View File
@@ -0,0 +1,44 @@
<?php
/**
* @file
* Contains \Drupal\colorbox_load\OpenCommand.
*/
namespace Drupal\colorbox_load;
use Drupal\Core\Ajax\CommandInterface;
/**
* Defines an AJAX command to open content in a colorbox.
*/
class OpenCommand implements CommandInterface {
/**
* The content for the colorbox.
*
* @var string
*/
protected $content;
/**
* Constructs an OpenCommand object.
*
* @param string $content
* The content that will be placed in the colorbox.
*/
public function __construct($content) {
$this->content = $content;
}
/**
* {@inheritdoc{
*/
public function render() {
return [
'command' => 'colorboxLoadOpen',
'data' => $this->content,
];
}
}
+31
View File
@@ -0,0 +1,31 @@
<?php
/**
* @file
* Contains \Drupal\colorbox_load\Renderer.
*/
namespace Drupal\colorbox_load;
use Drupal\Core\Ajax\AjaxResponse;
use Drupal\Core\Render\MainContent\MainContentRendererInterface;
use Drupal\Core\Routing\RouteMatchInterface;
use Symfony\Component\HttpFoundation\Request;
/**
* Render content in a colorbox.
*/
class Renderer implements MainContentRendererInterface {
/**
* {@inheritdoc}
*/
public function renderResponse(array $main_content, Request $request, RouteMatchInterface $route_match) {
$response = new AjaxResponse();
$content = drupal_render_root($main_content);
$response->setAttachments($main_content['#attached']);
$response->addCommand(new OpenCommand($content));
return $response;
}
}
+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.
+50
View File
@@ -0,0 +1,50 @@
History:
Field_group was originally written when drupal 7 was released. For drupal 6, the module is
located in the CCK module (http://drupal.org/project/cck).
As drupal core has a fields API drupal > 6, the field_group module
is considered a contribution.
Description:
field_group is a module that will group a set of fields. In Drupal8,
with fields, one means all fields that come from fieldable entities.
You can add fieldgroups in several types with their own format settings.
field_group uses plugins to add your own formatter and rendering for
it.
One of the biggest improvements to previous versions, is that fieldgroups
have unlimited nesting, better display control.
Note that field_group will only group fields, it can not be used to hide
certain fields since this a permission matter.
Module project page:
http://drupal.org/project/field_group
Documentation page (D7 version):
http://drupal.org/node/1017838
http://drupal.org/node/1017962
Available group types:
- Html element
- Fieldsets
- Tabs (horizontal and vertical)
- Accordions
- Details (Use this if you want collapsible fieldsets)
To submit bug reports and feature suggestions, or to track changes:
http://drupal.org/project/issues/field_group
-- Configuration --
1. You can configure the field groups for different displays like, in managed_form_display and managed_display of the entity type.
2. You can create different field groups under managed_form_display by adding a new group under "Add new group" label and the format the grouping using the desired formatter for displaying the same.
3. Same thing can be done in managed_display.
4. The field grouping done in managed display will be reflected on the view detail page of the entity, while that done in the managed_form_display will be
reflected in the add/edit form of the entity.
-- MAINTAINERS --
stalski - http://drupal.org/user/322618
zuuperman - http://drupal.org/user/361625
swentel - http://drupal.org/user/107403
-- INSPIRATORS --
yched - http://drupal.org/user/39567
+8
View File
@@ -0,0 +1,8 @@
{
"name": "drupal/field_group",
"description": "Provides the field_group module.",
"type": "drupal-module",
"license": "GPL-2.0+",
"minimum-stability": "dev",
"require": {}
}
@@ -0,0 +1,55 @@
core.entity_view_display.*.*.*.third_party.field_group:
type: sequence
label: 'Field group settings on entity view'
sequence:
- type: mapping
label: A field group
mapping:
children:
type: sequence
label: 'The fields belonging to the group'
sequence:
- type: string
label: 'The field name'
label:
type: string
label: Readable name of the group
parent_name:
type: string
label: 'The parent group of this group'
weight:
type: integer
label: 'The weight of the group'
format_type:
type: string
label: 'The formatter of the group'
format_settings:
type: field_group.field_group_formatter_plugin.[%parent.format_type]
core.entity_form_display.*.*.*.third_party.field_group:
type: sequence
label: 'Field group settings on entity form'
sequence:
- type: mapping
label: A field group
mapping:
children:
type: sequence
label: 'The fields belonging to the group'
sequence:
- type: string
label: 'The field name'
label:
type: string
label: Readable name of the group
parent_name:
type: string
label: 'The parent group of this group'
weight:
type: integer
label: 'The weight of the group'
format_type:
type: string
label: 'The formatter of the group'
format_settings:
type: field_group.field_group_formatter_plugin.[%parent.format_type]
@@ -0,0 +1,105 @@
field_group.field_group_formatter_plugin.accordion:
type: field_group.field_group_formatter_plugin.base
label: 'Mapping for the accordion formatter settings'
mapping:
effect:
type: string
label: 'Effect on the accordion'
field_group.field_group_formatter_plugin.accordion_item:
type: field_group.field_group_formatter_plugin.base
label: 'Mapping for the accordion item formatter settings'
mapping:
formatter:
type: string
label: 'Formatting of the item'
description:
type: string
label: 'description of the item'
required_fields:
type: boolean
label: 'Mark for required fields'
field_group.field_group_formatter_plugin.details:
type: field_group.field_group_formatter_plugin.base
label: 'Mapping for the details formatter settings'
mapping:
open:
type: boolean
label: 'Display element open by default.'
required_fields:
type: boolean
label: 'Mark for required fields'
field_group.field_group_formatter_plugin.fieldset:
type: field_group.field_group_formatter_plugin.base
label: 'Mapping for the fieldset formatter settings'
mapping:
description:
type: string
label: 'description of the item'
required_fields:
type: boolean
label: 'Mark for required fields'
field_group.field_group_formatter_plugin.html_element:
type: field_group.field_group_formatter_plugin.base
label: 'Mapping for the html element formatter settings'
mapping:
element:
type: string
label: 'html element tag to be used'
show_label:
type: boolean
label: 'show the label'
label_element:
type: string
label: 'html element tag to be used for the label'
attributes:
type: string
label: 'html attributes for the element'
effect:
type: string
label: 'effect on the element'
speed:
type: string
label: 'speed of the effect'
required_fields:
type: boolean
label: 'Mark for required fields'
field_group.field_group_formatter_plugin.tab:
type: field_group.field_group_formatter_plugin.base
label: 'Mapping for the tab formatter settings'
mapping:
formatter:
type: string
label: 'default state for the tab'
description:
type: string
label: 'description of the tab'
required_fields:
type: boolean
label: 'Mark for required fields'
field_group.field_group_formatter_plugin.tabs:
type: field_group.field_group_formatter_plugin.base
label: 'Mapping for the tab formatter settings'
mapping:
direction:
type: string
label: 'Direction of the tabs'
field_group.field_group_formatter_plugin.base:
type: mapping
label: 'Mapping for the base formatter settings'
mapping:
label:
type: string
label: 'Label of the fieldgroup'
classes:
type: string
label: 'Classes of the fieldgroup'
id:
type: string
label: 'Html id of the fieldgroup'
@@ -0,0 +1,14 @@
name: 'Field Group Migrate'
type: module
description: 'Provides the ability to migrate field groups from D6/D7 to D8.'
package: Migrate
# version: VERSION
# core: 8.x
dependencies:
- field_group:field_group
# Information added by Drupal.org packaging script on 2016-11-28
version: '8.x-1.0-rc6'
core: '8.x'
project: 'field_group'
datestamp: 1480365490
@@ -0,0 +1,41 @@
langcode: en
status: true
dependencies:
config:
- migrate.migration.d6_field_instance
module:
- field_group_migrate
- node
id: d6_field_group_entity_form_display
migration_tags:
- 'Drupal 6'
label: 'Field groups'
source:
plugin: d6_field_group
constants:
mode: entity_form_display
entity_type: node
form_mode: default
third_party_settings: { }
process:
mode: constants/mode
entity_type: constants/entity_type
bundle: type_name
form_mode: constants/form_mode
id:
plugin: concat
source:
- group_name
delimiter: .
field_group/label: label
field_group/weight: weight
field_group/children: children
field_group/format_type: converted_settings/format_type
field_group/format_settings: converted_settings/format_settings
destination:
plugin: field_group_entity_form_display
template: d6_field_instance_widget_settings
migration_dependencies:
required:
- d6_field_instance
migration_group: null
@@ -0,0 +1,39 @@
langcode: en
status: true
dependencies:
config:
- migrate.migration.d6_field_instance
module:
- field_group_migrate
- node
id: d6_field_group_entity_view_display
migration_tags:
- 'Drupal 6'
label: 'Field groups'
source:
plugin: d6_field_group
constants:
mode: entity_view_display
entity_type: node
third_party_settings: { }
process:
mode: constants/mode
entity_type: constants/entity_type
bundle: type_name
id:
plugin: concat
source:
- group_name
delimiter: .
field_group/label: label
field_group/weight: weight
field_group/children: children
field_group/format_type: converted_settings/format_type
field_group/format_settings: converted_settings/format_settings
destination:
plugin: field_group_entity_view_display
template: d6_field_instance_widget_settings
migration_dependencies:
required:
- d6_field_instance
migration_group: null
@@ -0,0 +1,28 @@
id: d7_field_group
label: Field groups
migration_tags:
- Drupal 7
source:
plugin: d7_field_group
process:
entity_type: entity_type
bundle: bundle
mode:
plugin: static_map
source: mode
bypass: true
map:
form: default
type:
plugin: static_map
source: mode
default_value: entity_view_display
map:
form: entity_form_display
group_name: group_name
settings: settings
destination:
plugin: d7_field_group
migration_dependencies:
required:
- d7_field_formatter_settings
@@ -0,0 +1,39 @@
<?php
namespace Drupal\field_group_migrate\Plugin\migrate\destination;
use Drupal\migrate\Plugin\migrate\destination\PerComponentEntityFormDisplay;
use Drupal\migrate\Row;
/**
* This class imports one field_group of an entity form display.
*
* @MigrateDestination(
* id = "field_group_entity_form_display"
* )
*/
class FieldGroupEntityFormDisplay extends PerComponentEntityFormDisplay {
/**
* {@inheritdoc}
*/
public function import(Row $row, array $old_destination_id_values = array()) {
$values = array();
// array_intersect_key() won't work because the order is important because
// this is also the return value.
foreach (array_keys($this->getIds()) as $id) {
$values[$id] = $row->getDestinationProperty($id);
}
$entity = $this->getEntity($values['entity_type'], $values['bundle'], $values[static::MODE_NAME]);
if (!$entity->isNew()) {
$settings = $row->getDestinationProperty('field_group');
$entity->setThirdPartySetting('field_group', $row->getDestinationProperty('id'), $settings);
if (isset($settings['format_type']) && ($settings['format_type'] == 'no_style' || $settings['format_type'] == 'hidden')) {
$entity->unsetThirdPartySetting('field_group', $row->getDestinationProperty('id'));
}
$entity->save();
}
return array_values($values);
}
}
@@ -0,0 +1,43 @@
<?php
namespace Drupal\field_group_migrate\Plugin\migrate\destination;
use Drupal\migrate\Plugin\migrate\destination\PerComponentEntityDisplay;
use Drupal\migrate\Row;
/**
* This class imports one field_group of an entity form display.
*
* @MigrateDestination(
* id = "field_group_entity_view_display"
* )
*/
class FieldGroupEntityViewDisplay extends PerComponentEntityDisplay {
/**
* {@inheritdoc}
*/
public function import(Row $row, array $old_destination_id_values = array()) {
$values = array();
// array_intersect_key() won't work because the order is important because
// this is also the return value.
foreach (array_keys($this->getIds()) as $id) {
$values[$id] = $row->getDestinationProperty($id);
}
foreach ($row->getSourceProperty('view_modes') as $view_mode => $settings) {
$entity = $this->getEntity($values['entity_type'], $values['bundle'], $view_mode);
if (!$entity->isNew()) {
$settings = array_merge($row->getDestinationProperty('field_group'), $settings);
$entity->setThirdPartySetting('field_group', $row->getDestinationProperty('id'), $settings);
if (isset($settings['format_type']) && ($settings['format_type'] == 'no_style' || $settings['format_type'] == 'hidden')) {
$entity->unsetThirdPartySetting('field_group', $row->getDestinationProperty('id'));
}
$entity->save();
}
}
return array_values($values);
}
}
@@ -0,0 +1,97 @@
<?php
/**
* @file
* Contains \Drupal\field_group_migrate\Plugin\migrate\destination\d7\FieldGroup.
*/
namespace Drupal\field_group_migrate\Plugin\migrate\destination\d7;
use Drupal\migrate\Plugin\migrate\destination\DestinationBase;
use Drupal\migrate\Plugin\MigrationInterface;
use Drupal\migrate\Row;
/**
* This class imports one field_group of an entity form display.
*
* @MigrateDestination(
* id = "d7_field_group"
* )
*/
class FieldGroup extends DestinationBase {
/**
* {@inheritdoc}
*/
public function import(Row $row, array $old_destination_id_values = array()) {
$values = array();
// array_intersect_key() won't work because the order is important because
// this is also the return value.
foreach (array_keys($this->getIds()) as $id) {
$values[$id] = $row->getDestinationProperty($id);
}
$entity = $this->getEntity($values['entity_type'], $values['bundle'], $values['mode'], $values['type']);
if (!$entity->isNew()) {
$settings = $row->getDestinationProperty('settings');
$entity->setThirdPartySetting('field_group', $row->getDestinationProperty('group_name'), $settings);
if (isset($settings['format_type']) && ($settings['format_type'] == 'hidden')) {
$entity->unsetThirdPartySetting('field_group', $row->getDestinationProperty('group_name'));
}
$entity->save();
}
return array_values($values);
}
/**
* {@inheritdoc}
*/
public function getIds() {
$ids['entity_type']['type'] = 'string';
$ids['bundle']['type'] = 'string';
$ids['mode']['type'] = 'string';
$ids['type']['type'] = 'string';
$ids['group_name']['type'] = 'string';
return $ids;
}
/**
* {@inheritdoc}
*/
public function rollback(array $destination_identifier) {
$entity = $this->getEntity($destination_identifier['entity_type'], $destination_identifier['bundle'], $destination_identifier['mode'], $destination_identifier['type']);
if (!$entity->isNew()) {
$entity->unsetThirdPartySetting('field_group', $destination_identifier['group_name']);
$entity->save();
}
}
/**
* {@inheritdoc}
*/
public function fields(MigrationInterface $migration = NULL) {
// This is intentionally left empty.
}
/**
* Gets the entity.
*
* @param string $entity_type
* The entity type to retrieve.
* @param string $bundle
* The entity bundle.
* @param string $mode
* The display mode.
* @param string $type
* The destination type.
*
* @return \Drupal\Core\Entity\Display\EntityDisplayInterface
* The entity display object.
*/
protected function getEntity($entity_type, $bundle, $mode, $type) {
$function = $type == 'entity_form_display' ? 'entity_get_form_display' : 'entity_get_display';
return $function($entity_type, $bundle, $mode);
}
}
@@ -0,0 +1,188 @@
<?php
namespace Drupal\field_group_migrate\Plugin\migrate\source\d6;
use Drupal\migrate\Row;
use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
/**
* Drupal 6 field_group source.
*
* @MigrateSource(
* id = "d6_field_group"
* )
*/
class FieldGroup extends DrupalSqlBase {
/**
* {@inheritdoc}
*/
public function query() {
$query = $this->select('content_group', 'g')
->fields('g', [
'group_type',
'type_name',
'group_name',
'label',
'settings',
'weight',
]);
return $query;
}
/**
* {@inheritdoc}
*/
public function prepareRow(Row $row) {
$query = $this->select('content_group_fields', 'f');
$query->fields('f', ['field_name'])
->condition('type_name', $row->getSourceProperty('type_name'))
->condition('group_name', $row->getSourceProperty('group_name'));
$fields = $query->execute()->fetchCol();
$row->setSourceProperty('children', $fields);
$row->setSourceProperty('settings', unserialize($row->getSourceProperty('settings')));
switch ($row->getSourceProperty('constants/mode')) {
case 'entity_form_display':
$this->transformEntityFormDisplaySettings($row);
break;
case 'entity_view_display':
$this->transformEntityViewDisplaySettings($row);
break;
}
return parent::prepareRow($row);
}
protected function transformEntityFormDisplaySettings(Row $row) {
$row->setSourceProperty('extracted_settings', $row->getSourceProperty('settings/form'));
$source_settings = $row->getSourceProperty('extracted_settings');
$settings = [
'format_type' => 'details',
'format_settings' => [],
];
switch ($source_settings['style']) {
case 'no_style':
$settings['format_type'] = 'no_style';
break;
case 'simple':
$settings['format_type'] = 'html_element';
$settings['format_settings']['element'] = 'div';
$settings['format_settings']['label_element'] = 'h2';
break;
case 'fieldset':
$settings['format_type'] = 'fieldset';
break;
case 'fieldset_collapsible':
$settings['format_type'] = 'details';
$settings['format_settings']['open'] = TRUE;
break;
case 'fieldset_collapsed':
$settings['format_type'] = 'details';
$settings['format_settings']['open'] = FALSE;
break;
case 'hidden':
$settings['format_type'] = 'hidden';
break;
}
$row->setSourceProperty('converted_settings', $settings);
}
protected function transformEntityViewDisplaySettings(Row $row) {
$row->setSourceProperty('extracted_settings', $row->getSourceProperty('settings/display'));
$view_modes = array_diff(array_keys($row->getSourceProperty('extracted_settings')), ['label', 'description', 'weight']);
$view_modes = array_filter($view_modes, function ($value) {
return !is_numeric($value);
});
$row->setSourceProperty('view_mode_keys', $view_modes);
$view_modes = [];
foreach ($row->getSourceProperty('view_mode_keys') as $view_mode) {
$source_settings = $row->getSourceProperty('extracted_settings/' . $view_mode);
$row->setSourceProperty('view_modes', []);
$settings = [
'format_type' => 'details',
'format_settings' => [],
];
switch ($source_settings['format']) {
case 'no_style':
$settings['format_type'] = 'no_style';
break;
case 'simple':
$settings['format_type'] = 'html_element';
$settings['format_settings']['element'] = 'div';
$settings['format_settings']['label_element'] = 'h2';
break;
case 'fieldset':
$settings['format_type'] = 'fieldset';
break;
case 'fieldset_collapsible':
$settings['format_type'] = 'details';
$settings['format_settings']['open'] = TRUE;
break;
case 'fieldset_collapsed':
$settings['format_type'] = 'details';
$settings['format_settings']['open'] = FALSE;
break;
case 'hidden':
$settings['format_type'] = 'hidden';
break;
}
/**
* @todo: ?
*/
if ($view_mode == 'full') {
$view_mode = 'default';
}
// $row->setSourceProperty('view_modes/' . $view_mode, $settings);
$view_modes[$view_mode] = $settings;
}
$row->setSourceProperty('view_modes', $view_modes);
}
/**
* {@inheritdoc}
*/
public function getIds() {
$ids['type_name']['type'] = 'string';
$ids['type_name']['alias'] = 'g';
$ids['group_name']['type'] = 'string';
$ids['group_name']['alias'] = 'g';
return $ids;
}
/**
* {@inheritdoc}
*/
public function fields() {
$fields = [
'group_type',
'type_name',
'group_name',
'label',
'settings',
'weight'
];
return array_combine($fields, $fields);
}
}
@@ -0,0 +1,104 @@
<?php
/**
* @file
* Contains \Drupal\field_group_migrate\Plugin\migrate\source\d7\FieldGroup.
*/
namespace Drupal\field_group_migrate\Plugin\migrate\source\d7;
use Drupal\migrate\Row;
use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
/**
* Drupal 7 field_group source.
*
* @MigrateSource(
* id = "d7_field_group"
* )
*/
class FieldGroup extends DrupalSqlBase {
/**
* {@inheritdoc}
*/
public function query() {
return $this->select('field_group', 'f')->fields('f');
}
/**
* {@inheritdoc}
*/
public function prepareRow(Row $row) {
$data = unserialize($row->getSourceProperty('data'));
$format_settings = $data['format_settings'] + $data['format_settings']['instance_settings'];
unset($format_settings['instance_settings']);
$settings = array(
'children' => $data['children'],
'parent_name' => $row->getSourceProperty('parent_name'),
'weight' => $data['weight'],
'label' => $data['label'],
'format_settings' => $format_settings,
'format_type' => $data['format_type'],
);
switch ($data['format_type']) {
case 'div':
$settings['format_type'] = 'html_element';
$settings['format_settings']['element'] = 'div';
break;
case 'tabs':
$settings['format_type'] = 'tabs';
$settings['format_settings']['direction'] = 'vertical';
break;
case 'htabs':
$settings['format_type'] = 'tabs';
$settings['format_settings']['direction'] = 'horizontal';
break;
case 'htab':
$settings['format_type'] = 'tab';
break;
case 'multipage-group':
// @todo Check if there is a better way to deal with this format type.
$settings['format_type'] = 'tabs';
break;
case 'multipage':
// @todo Check if there is a better way to deal with this format type.
$settings['format_type'] = 'tab';
break;
}
$row->setSourceProperty('settings', $settings);
return parent::prepareRow($row);
}
/**
* {@inheritdoc}
*/
public function getIds() {
$ids['id']['type'] = 'integer';
return $ids;
}
/**
* {@inheritdoc}
*/
public function fields() {
$fields = array(
'id' => $this->t('ID'),
'identifier' => $this->t('Identifier'),
'group_name' => $this->t('Group name'),
'entity_type' => $this->t('Entity type'),
'bundle' => $this->t('Bundle'),
'mode' => $this->t('View mode'),
'parent_name' => $this->t('Parent name'),
'data' => $this->t('Data'),
);
return $fields;
}
}
@@ -0,0 +1,147 @@
<?php
/**
* @file
* A database agnostic dump for testing purposes.
*/
use Drupal\Core\Database\Database;
$connection = Database::getConnection();
$connection->schema()->createTable('field_group', array(
'fields' => array(
'id' => array(
'type' => 'serial',
'not null' => TRUE,
'size' => 'normal',
),
'identifier' => array(
'type' => 'varchar',
'not null' => TRUE,
'length' => '255',
'default' => '',
),
'group_name' => array(
'type' => 'varchar',
'not null' => TRUE,
'length' => '32',
'default' => '',
),
'entity_type' => array(
'type' => 'varchar',
'not null' => TRUE,
'length' => '32',
'default' => '',
),
'bundle' => array(
'type' => 'varchar',
'not null' => TRUE,
'length' => '128',
'default' => '',
),
'mode' => array(
'type' => 'varchar',
'not null' => TRUE,
'length' => '128',
'default' => '',
),
'parent_name' => array(
'type' => 'varchar',
'not null' => TRUE,
'length' => '32',
'default' => '',
),
'data' => array(
'type' => 'blob',
'not null' => TRUE,
'size' => 'big',
),
),
'primary key' => array(
'id',
),
'unique keys' => array(
'identifier' => array(
'identifier',
),
),
'indexes' => array(
'group_name' => array(
'group_name',
),
),
'mysql_character_set' => 'utf8',
));
$connection->insert('field_group')
->fields(array(
'id',
'identifier',
'group_name',
'entity_type',
'bundle',
'mode',
'parent_name',
'data',
))
->values(array(
'id' => '1',
'identifier' => 'group_page|node|page|default',
'group_name' => 'group_page',
'entity_type' => 'node',
'bundle' => 'page',
'mode' => 'default',
'parent_name' => '',
'data' => 'a:5:{s:5:"label";s:10:"Node group";s:6:"weight";i:0;s:8:"children";a:0:{}s:11:"format_type";s:5:"htabs";s:15:"format_settings";a:1:{s:17:"instance_settings";a:0:{}}}',
))
->values(array(
'id' => '2',
'identifier' => 'group_user|user|user|default',
'group_name' => 'group_user',
'entity_type' => 'user',
'bundle' => 'user',
'mode' => 'default',
'parent_name' => '',
'data' => 'a:5:{s:5:"label";s:17:"User group parent";s:6:"weight";i:1;s:8:"children";a:0:{}s:11:"format_type";s:3:"div";s:15:"format_settings";a:1:{s:17:"instance_settings";a:0:{}}}',
))
->values(array(
'id' => '3',
'identifier' => 'group_user_child|user|user|default',
'group_name' => 'group_user_child',
'entity_type' => 'user',
'bundle' => 'user',
'mode' => 'default',
'parent_name' => 'group_user',
'data' => 'a:5:{s:5:"label";s:16:"User group child";s:6:"weight";i:99;s:8:"children";a:1:{i:0;s:12:"user_picture";}s:11:"format_type";s:4:"tabs";s:15:"format_settings";a:2:{s:5:"label";s:16:"User group child";s:17:"instance_settings";a:2:{s:7:"classes";s:16:"user-group-child";s:2:"id";s:33:"group_article_node_article_teaser";}}}',
))
->values(array(
'id' => '4',
'identifier' => 'group_article|node|article|teaser',
'group_name' => 'group_article',
'entity_type' => 'node',
'bundle' => 'article',
'mode' => 'teaser',
'parent_name' => '',
'data' => 'a:5:{s:5:"label";s:10:"htab group";s:6:"weight";i:2;s:8:"children";a:1:{i:0;s:11:"field_image";}s:11:"format_type";s:4:"htab";s:15:"format_settings";a:1:{s:17:"instance_settings";a:1:{s:7:"classes";s:10:"htab-group";}}}',
))
->values(array(
'id' => '5',
'identifier' => 'group_page|node|page|form',
'group_name' => 'group_page',
'entity_type' => 'node',
'bundle' => 'page',
'mode' => 'form',
'parent_name' => '',
'data' => 'a:5:{s:5:"label";s:15:"Node form group";s:6:"weight";i:0;s:8:"children";a:0:{}s:11:"format_type";s:5:"htabs";s:15:"format_settings";a:1:{s:17:"instance_settings";a:0:{}}}',
))
->values(array(
'id' => '6',
'identifier' => 'group_article|node|article|form',
'group_name' => 'group_article',
'entity_type' => 'node',
'bundle' => 'article',
'mode' => 'form',
'parent_name' => '',
'data' => 'a:5:{s:5:"label";s:15:"htab form group";s:6:"weight";i:2;s:8:"children";a:1:{i:0;s:11:"field_image";}s:11:"format_type";s:4:"htab";s:15:"format_settings";a:1:{s:17:"instance_settings";a:0:{}}}',
))
->execute();
@@ -0,0 +1,114 @@
<?php
namespace Drupal\Tests\field_group_migrate\Kernel\Migrate\d7;
use Drupal\Core\Entity\Display\EntityDisplayInterface;
use Drupal\Tests\migrate_drupal\Kernel\d7\MigrateDrupal7TestBase;
/**
* Tests field group migration.
*
* @group field_group
*/
class MigrateFieldGroupTest extends MigrateDrupal7TestBase {
static $modules = [
'field_group',
'field_group_migrate',
'comment',
'datetime',
'image',
'link',
'node',
'taxonomy',
'telephone',
'text',
];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->loadFixture(__DIR__ . '/../../../../fixtures/drupal7.php');
$this->installConfig(static::$modules);
$this->executeMigrations([
'd7_node_type',
'd7_comment_type',
'd7_view_modes',
'd7_field',
'd7_field_instance',
'd7_field_formatter_settings',
'd7_field_group',
]);
}
/**
* Asserts various aspects of a migrated field group.
*
* @param $id
* The id of the entity display to which the field group applies.
* @param $type
* The destination type.
* @param $group_name
* The name of the field group.
* @param $expected_label
* The expected label.
* @param int $expected_weight
* The expected label.
* @param array $expected_format_settings
* The expected format settings.
* @param string $expected_format_type
* The expected format type.
* @param array $expected_children
* The expected children.
* @param string $expected_parent_name
* The expected parent name.
*/
protected function assertEntity($id, $type, $group_name, $expected_label, $expected_weight = 0, $expected_format_settings = [], $expected_format_type = 'tabs', $expected_children = [], $expected_parent_name = '') {
/** @var EntityDisplayInterface $entity */
$entity = \Drupal::entityTypeManager()
->getStorage($type)
->load($id);
$field_group_settings = $entity->getThirdPartySettings('field_group');
$this->assertNotEmpty($field_group_settings);
$this->assertArrayHasKey($group_name, $field_group_settings);
$field_group = $field_group_settings[$group_name];
$this->assertEquals($expected_label, $field_group['label']);
$this->assertEquals($expected_format_settings, $field_group['format_settings']);
$this->assertEquals($expected_children, $field_group['children']);
$this->assertEquals($expected_parent_name, $field_group['parent_name']);
$this->assertEquals($expected_weight, $field_group['weight']);
$this->assertEquals($expected_format_type, $field_group['format_type']);
}
/**
* Test field group migration from Drupal 7 to 8.
*/
public function testFieldGroup() {
$this->assertEntity('node.page.default', 'entity_view_display', 'group_page', 'Node group', 0, ['direction' => 'horizontal']);
$this->assertEntity('user.user.default', 'entity_view_display', 'group_user', 'User group parent', 1, ['element' => 'div'], 'html_element');
$this->assertEntity('user.user.default', 'entity_view_display', 'group_user_child', 'User group child', 99, ['direction' => 'vertical', 'label' => 'User group child', 'classes' => 'user-group-child', 'id' => 'group_article_node_article_teaser'], 'tabs', ['user_picture'], 'group_user');
$this->assertEntity('node.article.teaser', 'entity_view_display', 'group_article', 'htab group', 2, ['classes' => 'htab-group'], 'tab', ['field_image']);
// Check an entity_view_display without a field group.
/** @var EntityDisplayInterface $entity */
$entity = \Drupal::entityTypeManager()
->getStorage('entity_view_display')
->load('node.page.teaser');
$field_group_settings = $entity->getThirdPartySettings('field_group');
$this->assertEmpty($field_group_settings);
$this->assertEntity('node.page.default', 'entity_form_display', 'group_page', 'Node form group', 0, ['direction' => 'horizontal']);
$this->assertEntity('node.article.default', 'entity_form_display', 'group_article', 'htab form group', 2, [], 'tab', ['field_image']);
// Check an entity_form_display without a field group.
$entity = \Drupal::entityTypeManager()
->getStorage('entity_form_display')
->load('node.blog.default');
$field_group_settings = $entity->getThirdPartySettings('field_group');
$this->assertEmpty($field_group_settings);
}
}
@@ -0,0 +1,94 @@
<?php
namespace Drupal\Tests\field_group_migrate\Unit\Migrate\d7;
use Drupal\Tests\migrate\Unit\MigrateSqlSourceTestCase;
/**
* Tests D7 field group source plugin.
*
* @group field_group
*/
class FieldGroupTest extends MigrateSqlSourceTestCase {
const PLUGIN_CLASS = 'Drupal\field_group_migrate\Plugin\migrate\source\d7\FieldGroup';
protected $migrationConfiguration = [
'id' => 'test',
'source' => [
'plugin' => 'd7_field_group',
],
];
protected $expectedResults = [
[
'id' => '1',
'identifier' => 'group_page|node|page|default',
'group_name' => 'group_page',
'entity_type' => 'node',
'bundle' => 'page',
'mode' => 'default',
'parent_name' => '',
'data' => 'a:5:{s:5:"label";s:10:"Node group";s:6:"weight";i:0;s:8:"children";a:0:{}s:11:"format_type";s:5:"htabs";s:15:"format_settings";a:1:{s:17:"instance_settings";a:0:{}}}',
],
[
'id' => '2',
'identifier' => 'group_user|user|user|default',
'group_name' => 'group_user',
'entity_type' => 'user',
'bundle' => 'user',
'mode' => 'default',
'parent_name' => '',
'data' => 'a:5:{s:5:"label";s:17:"User group parent";s:6:"weight";i:1;s:8:"children";a:0:{}s:11:"format_type";s:3:"div";s:15:"format_settings";a:1:{s:17:"instance_settings";a:0:{}}}',
],
[
'id' => '3',
'identifier' => 'group_user_child|user|user|default',
'group_name' => 'group_user_child',
'entity_type' => 'user',
'bundle' => 'user',
'mode' => 'default',
'parent_name' => 'group_user',
'data' => 'a:5:{s:5:"label";s:16:"User group child";s:6:"weight";i:99;s:8:"children";a:1:{i:0;s:12:"user_picture";}s:11:"format_type";s:4:"tabs";s:15:"format_settings";a:2:{s:5:"label";s:16:"User group child";s:17:"instance_settings";a:2:{s:7:"classes";s:16:"user-group-child";s:2:"id";s:33:"group_article_node_article_teaser";}}}',
],
[
'id' => '4',
'identifier' => 'group_article|node|article|teaser',
'group_name' => 'group_article',
'entity_type' => 'node',
'bundle' => 'article',
'mode' => 'teaser',
'parent_name' => '',
'data' => 'a:5:{s:5:"label";s:10:"htab group";s:6:"weight";i:2;s:8:"children";a:1:{i:0;s:11:"field_image";}s:11:"format_type";s:4:"htab";s:15:"format_settings";a:1:{s:17:"instance_settings";a:1:{s:7:"classes";s:10:"htab-group";}}}',
],
[
'id' => '5',
'identifier' => 'group_page|node|page|form',
'group_name' => 'group_page',
'entity_type' => 'node',
'bundle' => 'page',
'mode' => 'form',
'parent_name' => '',
'data' => 'a:5:{s:5:"label";s:15:"Node form group";s:6:"weight";i:0;s:8:"children";a:0:{}s:11:"format_type";s:5:"htabs";s:15:"format_settings";a:1:{s:17:"instance_settings";a:0:{}}}',
],
[
'id' => '6',
'identifier' => 'group_article|node|article|form',
'group_name' => 'group_article',
'entity_type' => 'node',
'bundle' => 'article',
'mode' => 'form',
'parent_name' => '',
'data' => 'a:5:{s:5:"label";s:15:"htab form group";s:6:"weight";i:2;s:8:"children";a:1:{i:0;s:11:"field_image";}s:11:"format_type";s:4:"htab";s:15:"format_settings";a:1:{s:17:"instance_settings";a:0:{}}}',
],
];
/**
* {@inheritdoc}
*/
protected function setUp() {
$this->databaseContents['field_group'] = $this->expectedResults;
parent::setUp();
}
}
@@ -0,0 +1,14 @@
#field-overview tr.field-group .group-label,
#field-display-overview tr.field-group .group-label {
font-weight: bold;
}
#field-overview tr.static-region,
#field-display-overview tr.static-region {
background-color: #ddd;
}
#edit-refresh {
display:none;
}
+13
View File
@@ -0,0 +1,13 @@
name: 'Field Group'
type: module
description: 'Provides the ability to group your fields on both form and display.'
package : Fields
# core: 8.x
dependencies:
- drupal:field
# Information added by Drupal.org packaging script on 2016-11-28
version: '8.x-1.0-rc6'
core: '8.x'
project: 'field_group'
datestamp: 1480365490
@@ -0,0 +1,60 @@
field_ui:
version: VERSION
js:
js/field_group.field_ui.js: {}
css:
component:
css/field_group.field_ui.css: {}
dependencies:
- core/jquery
- core/jquery.once
- core/drupal
- core/drupalSettings
core:
version: VERSION
js:
js/field_group.js: {}
dependencies:
- core/jquery
- core/jquery.once
- core/drupal
- core/drupalSettings
formatter.accordion:
version: VERSION
js:
formatters/accordion/accordion.js: {}
dependencies:
- core/jquery.ui.accordion
formatter.html_element:
version: VERSION
js:
formatters/html_element/html-element.js: {}
formatter.fieldset:
version: VERSION
js:
formatters/fieldset/fieldset.js: {}
formatter.details:
version: VERSION
js:
formatters/details/details.js: {}
formatter.tabs:
version: VERSION
js:
formatters/tabs/tabs.js: {}
element.horizontal_tabs:
version: VERSION
js:
# Load before field_group/core.
formatters/tabs/horizontal-tabs.js: {weight: -1}
css:
component:
formatters/tabs/horizontal-tabs.css: {}
dependencies:
- core/drupal.collapse
@@ -0,0 +1,3 @@
field_group.field_group_add:
class: \Drupal\Core\Menu\LocalActionDefault
deriver: \Drupal\field_group\Plugin\Derivative\FieldGroupLocalAction
+786
View File
@@ -0,0 +1,786 @@
<?php
/**
* @file
* Allows administrators to attach custom fields to fieldable types.
*/
use Drupal\Core\Entity\ContentEntityFormInterface;
use Drupal\Core\Entity\Display\EntityDisplayInterface;
use Drupal\Core\Entity\Display\EntityFormDisplayInterface;
use Drupal\Core\Entity\Entity\EntityFormDisplay;
use Drupal\Core\Entity\Entity\EntityViewDisplay;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Form\ConfirmFormInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Render\Element;
require_once __DIR__ . '/includes/helpers.inc';
/**
* Implements hook_theme_registry_alter().
*/
function field_group_theme_registry_alter(&$theme_registry) {
// Inject field_group_build_entity_groups in all entity theming functions.
$entity_info = Drupal::entityTypeManager()->getDefinitions();
$entity_types = array();
foreach ($entity_info as $entity_type_id => $entity_type) {
if ($route_name = $entity_type->get('field_ui_base_route')) {
$entity_types[] = $entity_type_id;
}
}
foreach ($theme_registry as $theme_hook => $info) {
if (in_array($theme_hook, $entity_types) || (!empty($info['base hook']) && in_array($info['base hook'], $entity_types))) {
$theme_registry[$theme_hook]['preprocess functions'][] = 'field_group_build_entity_groups';
}
}
// ECK does not use the eck as theme function.
if (isset($theme_registry['eck_entity'])) {
$theme_registry['eck_entity']['preprocess functions'][] = 'field_group_build_entity_groups';
}
}
/**
* Implements hook_theme().
*/
function field_group_theme() {
return array(
'horizontal_tabs' => array(
'render element' => 'element',
'template' => 'horizontal-tabs',
'file' => 'templates/theme.inc',
),
'field_group_accordion_item' => array(
'render element' => 'element',
'template' => 'field-group-accordion-item',
'file' => 'templates/theme.inc',
),
'field_group_accordion' => array(
'render element' => 'element',
'template' => 'field-group-accordion',
'file' => 'templates/theme.inc',
),
'field_group_html_element' => array(
'render element' => 'element',
'template' => 'field-group-html-element',
'file' => 'templates/theme.inc',
),
);
}
/**
* Implements hook_theme_suggestions_alter().
*
* @param array $suggestions
* @param array $variables
* @param $hook
*/
function field_group_theme_suggestions_alter(array &$suggestions, array $variables, $hook) {
switch ($hook) {
case 'horizontal_tabs':
case 'field_group_accordion_item':
case 'field_group_accordion':
case 'field_group_html_element':
$element = $variables['element'];
$name = $element['#group_name'];
$entity_type = $element['#entity_type'];
$bundle = $element['#bundle'];
$wrapper = '';
if (isset($element['#wrapper_element'])) {
$wrapper = $element['#wrapper_element'];
$suggestions[] = $hook . '__' . $wrapper;
}
$suggestions[] = $hook . '__' . $entity_type;
$suggestions[] = $hook . '__' . $bundle;
$suggestions[] = $hook . '__' . $name;
if ($wrapper) {
$suggestions[] = $hook . '__' . $entity_type . '__' . $wrapper;
}
$suggestions[] = $hook . '__' . $entity_type . '__' . $bundle;
$suggestions[] = $hook . '__' . $entity_type . '__' . $name;
if ($wrapper) {
$suggestions[] = $hook . '__' . $entity_type . '__' . $bundle . '__' . $wrapper;
}
$suggestions[] = $hook . '__' . $entity_type . '__' . $bundle . '__' . $name;
break;
}
}
/**
* Implements hook_form_FORM_ID_alter().
* Using hook_form_field_ui_form_display_overview_form_alter.
*/
function field_group_form_entity_form_display_edit_form_alter(&$form, FormStateInterface $form_state) {
$form_state->loadInclude('field_group', 'inc', 'includes/field_ui');
field_group_field_ui_display_form_alter($form, $form_state);
}
/**
* Implements hook_form_FORM_ID_alter().
* Using hook_form_field_ui_display_overview_form_alter.
*/
function field_group_form_entity_view_display_edit_form_alter(&$form, FormStateInterface $form_state) {
$form_state->loadInclude('field_group', 'inc', 'includes/field_ui');
field_group_field_ui_display_form_alter($form, $form_state);
}
/**
* Implements hook_field_info_max_weight().
*/
function field_group_field_info_max_weight($entity_type, $bundle, $context, $context_mode) {
$groups = field_group_info_groups($entity_type, $bundle, $context, $context_mode);
$weights = array();
foreach ($groups as $group) {
$weights[] = $group->weight;
}
return $weights ? max($weights) : NULL;
}
/**
* Implements hook_form_alter().
*/
function field_group_form_alter(array &$form, FormStateInterface $form_state) {
if ($form_state->getFormObject() instanceof ContentEntityFormInterface && !$form_state->getFormObject() instanceof ConfirmFormInterface) {
/**
* @var EntityFormDisplayInterface $form_display
*/
if ($form_display = $form_state->getStorage()['form_display']) {
$entity = $form_state->getFormObject()->getEntity();
$context = array(
'entity_type' => $entity->getEntityTypeId(),
'bundle' => $entity->bundle(),
'entity' => $entity,
'context' => 'form',
'display_context' => 'form',
'mode' => $form_display->getMode(),
);
field_group_attach_groups($form, $context);
$form['#pre_render'][] = 'field_group_form_pre_render';
}
}
}
/**
* Implements hook_inline_entity_form_entity_form_alter().
*/
function field_group_inline_entity_form_entity_form_alter(&$entity_form, FormStateInterface $form_state) {
// Attach the fieldgroups to current entity form.
$context = [
'entity_type' => $entity_form['#entity']->getEntityTypeId(),
'bundle' => $entity_form['#entity']->bundle(),
'entity' => $entity_form['#entity'],
'display_context' => 'form',
'mode' => 'default',
];
field_group_attach_groups($entity_form, $context);
$entity_form['#pre_render'][] = 'field_group_form_pre_render';
}
/**
* Implements hook_entity_view_alter().
*/
function field_group_entity_view_alter(&$build, EntityInterface $entity, EntityDisplayInterface $display) {
$context = array(
'entity_type' => $display->getTargetEntityTypeId(),
'bundle' => $entity->bundle(),
'entity' => $entity,
'display_context' => 'view',
'mode' => $display->getMode(),
);
field_group_attach_groups($build, $context);
// If no theme hook, we have no theme hook to preprocess.
// Add a prerender.
if (empty($build['#theme'])) {
$ds_enabled = false;
if (Drupal::moduleHandler()->moduleExists('ds')) {
// Check if DS is enabled for this display.
if ($display->getThirdPartySetting('ds', 'layout') && !Drupal\ds\Ds::isDisabled()) {
$ds_enabled = true;
}
}
// If DS is enabled, no pre render is needed (DS adds fieldgroup preprocessing).
if (!$ds_enabled) {
$build['#pre_render'][] = 'field_group_entity_view_pre_render';
}
}
}
/**
* Pre render callback for rendering groups.
* @see field_group_field_attach_form
* @param $element Form that is being rendered.
*/
function field_group_form_pre_render($element) {
if (empty($element['#field_group_form_pre_render'])) {
$element['#field_group_form_pre_render'] = TRUE;
field_group_build_entity_groups($element, 'form');
}
return $element;
}
/**
* Pre render callback for rendering groups on entities without theme hook.
* @param $element
* Entity being rendered.
*/
function field_group_entity_view_pre_render($element) {
field_group_build_entity_groups($element, 'view');
return $element;
}
/**
* Implements hook_field_group_pre_render().
*
* @param Array $element
* Group beïng rendered.
* @param Object $group
* The Field group info.
* @param $rendering_object
* The entity / form beïng rendered
*/
function field_group_field_group_pre_render(&$element, &$group, &$rendering_object) {
// Add all field_group format types to the js settings.
$element['#attached']['drupalSettings']['field_group'] = array(
$group->format_type => [
'mode' => $group->mode,
'context' => $group->context,
'settings' => $group->format_settings,
],
);
$element['#weight'] = $group->weight;
// Call the pre render function for the format type.
$manager = Drupal::service('plugin.manager.field_group.formatters');
$plugin = $manager->getInstance(array(
'format_type' => $group->format_type,
'configuration' => array('label' => $group->label, 'settings' => $group->format_settings),
'group' => $group,
));
$plugin->preRender($element, $rendering_object);
}
/**
* Implements hook_field_group_build_pre_render_alter().
* @param Array $elements by address.
*/
function field_group_field_group_build_pre_render_alter(& $element) {
// Someone is doing a node view, in a node view. Reset content.
if (isset($element['#node']->content) && count($element['#node']->content) > 0) {
$element['#node']->content = array();
}
$display = isset($element['#view_mode']);
$groups = array_keys($element['#fieldgroups']);
// Dish the fieldgroups with no fields for non-forms.
if ($display) {
field_group_remove_empty_display_groups($element, $groups);
}
else {
// Fix the problem on forms with additional settings.
field_group_remove_empty_form_groups('form', $element, $groups, $element['#fieldgroups'], $element['#entity_type']);
}
}
/**
* Attach groups to the (form) build.
*
* @param Array $element
* The part of the form.
* @param Array $context
* The contextual information.
*/
function field_group_attach_groups(&$element, $context) {
$entity_type = $context['entity_type'];
$bundle = $context['bundle'];
$mode = $context['mode'];
$display_context = $context['display_context'];
$element['#fieldgroups'] = field_group_info_groups($entity_type, $bundle, $display_context, $mode);
// Create a lookup array.
$group_children = array();
foreach ($element['#fieldgroups'] as $group_name => $group) {
foreach ($group->children as $child) {
$group_children[$child] = $group_name;
}
}
$element['#group_children'] = $group_children;
$element['#entity_type'] = $entity_type;
}
/**
* Preprocess/ Pre-render callback.
*
* @see field_group_form_pre_render()
* @see field_group_theme_registry_alter
* @see field_group_fields_nest()
* @param $vars preprocess vars or form element
* @param $context The display context (form or view)
* @return $element Array with re-arranged fields in groups.
*/
function field_group_build_entity_groups(&$vars, $context = 'view') {
if ($context == 'form') {
$element = &$vars;
$nest_vars = NULL;
}
else {
if (isset($vars['elements'])) {
$element = &$vars['elements'];
}
elseif (isset($vars['content'])) {
$element = &$vars['content'];
}
else {
if ($context === 'eck_entity') {
$element = &$vars['entity'];
}
else {
$element = &$vars;
}
}
$nest_vars = &$vars;
}
// No groups on the entity.
if (empty($element['#fieldgroups'])) {
return $element;
}
// Nest the fields in the corresponding field groups.
field_group_fields_nest($element, $nest_vars);
// Allow others to alter the pre_rendered build.
Drupal::moduleHandler()->alter('field_group_build_pre_render', $element);
// Return the element on forms.
if ($context == 'form') {
return $element;
}
// No groups on the entity. Prerender removed empty field groups.
if (empty($element['#fieldgroups'])) {
return $element;
}
// Put groups inside content if we are rendering an entity_view.
foreach ($element['#fieldgroups'] as $group) {
if (!empty($element[$group->group_name])) {
if (isset($vars['content'])) {
$vars['content'][$group->group_name] = $element[$group->group_name];
}
elseif (isset($vars['user_profile'])) {
$vars['user_profile'][$group->group_name] = $element[$group->group_name];
}
}
}
}
/**
* Recursive function to nest fields in the field groups.
*
* This function will take out all the elements in the form and
* place them in the correct container element, a fieldgroup.
* The current group element in the loop is passed recursively so we can
* stash fields and groups in it while we go deeper in the array.
* @param Array $element
* The current element to analyse for grouping.
* @param Array $vars
* Rendering vars from the entity being viewed.
*/
function field_group_fields_nest(&$element, &$vars = NULL) {
// Create all groups and keep a flat list of references to these groups.
$group_references = array();
foreach ($element['#fieldgroups'] as $group_name => $group) {
// Construct own weight, as some fields (for example preprocess fields) don't have weight set.
$element[$group_name] = array();
$group_references[$group_name] = &$element[$group_name];
}
// Loop through all form children looking for those that are supposed to be
// in groups, and insert placeholder element for the new group field in the
// correct location within the form structure.
$element_clone = array();
foreach (Element::children($element) as $child_name) {
$element_clone[$child_name] = $element[$child_name];
// If this element is in a group, create the placeholder element.
if (isset($element['#group_children'][$child_name])) {
$element_clone[$element['#group_children'][$child_name]] = array();
}
}
$element = array_merge($element_clone, $element);
// Move all children to their parents. Use the flat list of references for
// direct access as we don't know where in the root_element hierarchy the
// parent currently is situated.
foreach ($element['#group_children'] as $child_name => $parent_name) {
// Entity being viewed
if ($vars) {
// If not a group, check vars['content'] for empty field.
if (!isset($element['#fieldgroups'][$child_name]) && isset($vars['content'][$child_name])) {
$group_references[$parent_name][$child_name] = $vars['content'][$child_name];
unset($vars['content'][$child_name]);
}
elseif (!isset($element['#fieldgroups'][$child_name]) && isset($vars['user_profile'][$child_name])) {
$group_references[$parent_name][$child_name] = $vars['user_profile'][$child_name];
unset($vars['user_profile'][$child_name]);
}
// If this is a group, we have to use a reference to keep the reference
// list intact (but if it is a field we don't mind).
else {
$group_references[$parent_name][$child_name] = &$element[$child_name];
unset($element[$child_name]);
}
}
// Form being viewed
else {
// Block denied fields (#access) before they are put in groups.
// Fields (not groups) that don't have children (like field_permissions) are removed
// in field_group_field_group_build_pre_render_alter.
if (isset($element[$child_name]) && (!isset($element[$child_name]['#access']) || $element[$child_name]['#access'])) {
// If this is a group, we have to use a reference to keep the reference
// list intact (but if it is a field we don't mind).
$group_references[$parent_name][$child_name] = &$element[$child_name];
$group_references[$parent_name]['#weight'] = $element['#fieldgroups'][$parent_name]->weight;
}
// The child has been copied to its parent: remove it from the root element.
unset($element[$child_name]);
}
}
// Bring extra element wrappers to achieve a grouping of fields.
// This will mainly be prefix and suffix altering.
foreach ($element['#fieldgroups'] as $group_name => $group) {
field_group_pre_render($group_references[$group_name], $group, $element);
}
}
/**
* Function to pre render the field group element.
*
* @see field_group_fields_nest()
*
* @param $element
* Render array of group element that needs to be created.
* @param $group
* Object with the group information.
* @param $rendering_object
* The entity / form beïng rendered.
*/
function field_group_pre_render(& $element, $group, & $rendering_object) {
// Only run the pre_render function if the group has elements.
// $group->group_name
if ($element == array()) {
return;
}
// Let modules define their wrapping element.
// Note that the group element has no properties, only elements.
foreach (Drupal::moduleHandler()->getImplementations('field_group_pre_render') as $module) {
// The intention here is to have the opportunity to alter the
// elements, as defined in hook_field_group_formatter_info.
// Note, implement $element by reference!
$function = $module . '_field_group_pre_render';
$function($element, $group, $rendering_object);
}
// Allow others to alter the pre_render.
Drupal::moduleHandler()->alter('field_group_pre_render', $element, $group, $rendering_object);
}
/**
* Saves a group definition.
* This function is called by ctools export when calls are made
* through ctools_export_crud_save().
*
* @param $group
* A group definition.
* @param $display
* The display to update if known.
* @return EntityDisplayInterface || NULL
*/
function field_group_group_save($group, $display = NULL) {
if ($display === NULL) {
if ($group->context == 'form') {
$display = EntityFormDisplay::load($group->entity_type . '.' . $group->bundle . '.' . $group->mode);
}
elseif ($group->context == 'view') {
$display = EntityViewDisplay::load($group->entity_type . '.' . $group->bundle . '.' . $group->mode);
}
}
// If no display was found. It doesn't exist yet, create it.
if (!isset($display)) {
if ($group->context == 'form') {
$display = EntityFormDisplay::create(array(
'targetEntityType' => $group->entity_type,
'bundle' => $group->bundle,
'mode' => $group->mode,
))->setStatus(TRUE);
}
elseif ($group->context == 'view') {
$display = EntityViewDisplay::create(array(
'targetEntityType' => $group->entity_type,
'bundle' => $group->bundle,
'mode' => $group->mode,
))->setStatus(TRUE);
}
}
/**
* @var $display \Drupal\Core\Entity\Display\EntityDisplayInterface
*/
if (isset($display)) {
$data = (array) $group;
unset($data['group_name'], $data['entity_type'], $data['bundle'], $data['mode'], $data['form'], $data['context']);
$display->setThirdPartySetting('field_group', $group->group_name, $data);
$display->save();
}
return $display;
}
/**
* Delete a field group.
*
* @param $group
* A group definition.
*/
function field_group_group_delete($group) {
if ($group->context == 'form') {
$display = EntityFormDisplay::load($group->entity_type . '.' . $group->bundle . '.' . $group->mode);
}
elseif ($group->context == 'view') {
$display = EntityViewDisplay::load($group->entity_type . '.' . $group->bundle . '.' . $group->mode);
}
/**
* @var $display \Drupal\Core\Entity\Display\EntityDisplayInterface
*/
if (isset($display)) {
$display->unsetThirdPartySetting('field_group', $group->group_name);
$display->save();
}
Drupal::moduleHandler()->invokeAll('field_group_delete_field_group', array($group));
}
/**
* Get all groups.
*
* @param $entity_type
* The name of the entity.
* @param $bundle
* The name of the bundle.
* @param $context
* The context of the view mode (form or view)
* @param $mode
* The view mode.
*/
function field_group_info_groups($entity_type, $bundle, $context, $mode) {
if ($context == 'form') {
$display = EntityFormDisplay::load($entity_type . '.' . $bundle . '.' . $mode);
if (!$display) {
return array();
}
$data = $display->getThirdPartySettings('field_group');
}
if ($context == 'view') {
$display = EntityViewDisplay::load($entity_type . '.' . $bundle . '.' . $mode);
if (!$display) {
return array();
}
$data = $display->getThirdPartySettings('field_group');
}
$groups = array();
if (isset($data)) {
foreach ($data as $group_name => $definition) {
$definition += array(
'group_name' => $group_name,
'entity_type' => $entity_type,
'bundle' => $bundle,
'context' => $context,
'mode' => $mode,
);
$groups[$group_name] = (object) $definition;
}
}
return $groups;
}
/**
* Loads a group definition.
*
* @param $group_name
* The name of the group.
* @param $entity_type
* The name of the entity.
* @param $bundle
* The name of the bundle.
* @param $context
* The context of the view mode (form or view)
* @param $mode
* The view mode to load.
*/
function field_group_load_field_group($group_name, $entity_type, $bundle, $context, $mode) {
$groups = field_group_info_groups($entity_type, $bundle, $context, $mode);
if (isset($groups[$group_name])) {
return $groups[$group_name];
}
}
/**
* Checks if a field_group exists in required context.
*
* @param String $group_name
* The name of the group.
* @param String $entity_type
* The name of the entity.
* @param String $bundle
* The bundle for the entity.
* @param $context
* The context of the view mode (form or view)
* @param String $mode
* The view mode context the group will be rendered.
*/
function field_group_exists($group_name, $entity_type, $bundle, $context, $mode) {
return (bool) field_group_load_field_group($group_name, $entity_type, $bundle, $context, $mode);
}
/**
* Remove empty groups on forms.
*
* @param String $parent_name
* The name of the element.
* @param array $element
* The element to check the empty state.
* @param array $groups
* Array of group objects.
*/
function field_group_remove_empty_form_groups($name, & $element, $groups, &$form_groups, $entity) {
$exceptions = array('user__account', 'comment__author');
$children = Element::children($element);
$hasChildren = FALSE;
if (count($children)) {
foreach ($children as $childname) {
if (in_array($childname, $groups)) {
field_group_remove_empty_form_groups($childname, $element[$childname], $groups, $form_groups, $entity);
}
$exception = $entity . '__' . $childname;
$hasChildren = $hasChildren ? TRUE : (isset($element[$childname]['#type']) || isset($element[$childname]['#markup']) || in_array($exception, $exceptions));
}
}
if (!$hasChildren) {
// Remove empty elements from the #fieldgroups.
if (empty($element) && isset($form_groups[$name]) && !is_array($form_groups[$name])) {
foreach ($form_groups as $group_name => $group) {
if (isset($group->children)) {
$group_children = array_flip($group->children);
if (isset($group_children[$name])) {
unset($form_groups[$group_name]->children[$group_children[$name]]);
}
}
}
}
$element['#access'] = FALSE;
}
}
/**
* Remove empty groups on entity display.
*
* @param array $element
* The element to check the empty state.
* @param array $groups
* Array of group objects.
*/
function field_group_remove_empty_display_groups(& $element, $groups) {
$empty_child = TRUE;
$empty_group = TRUE;
// Loop through the visible children for current element.
foreach (Element::getVisibleChildren($element) as $name) {
// Descend if the child is a group.
if (in_array($name, $groups)) {
$empty_child = field_group_remove_empty_display_groups($element[$name], $groups);
if (!$empty_child) {
$empty_group = FALSE;
}
}
// Child is a field or a renderable array and the element is not empty.
elseif (!empty($element[$name])) {
$clone_element = $element[$name];
// Weight parameter can make empty element seen as not empty.
unset($clone_element['#weight']);
if (!Element::isEmpty($clone_element)) {
$empty_group = FALSE;
}
}
}
// Reset an empty group.
if ($empty_group) {
$element = [];
}
return $empty_group;
}
@@ -0,0 +1,13 @@
services:
plugin.manager.field_group.formatters:
class: Drupal\field_group\FieldGroupFormatterPluginManager
parent: default_plugin_manager
field_group.subscriber:
class: Drupal\field_group\Routing\RouteSubscriber
arguments: ['@entity.manager']
tags:
- { name: event_subscriber }
field_group.param_converter:
class: Drupal\field_group\Routing\FieldGroupConverter
tags:
- { name: paramconverter }

Some files were not shown because too many files have changed in this diff Show More