Vsebina, posodobitve
parent
cb4c625853
commit
34b99bde5b
|
@ -20,6 +20,8 @@
|
|||
"drupal/core-composer-scaffold": "^9.2",
|
||||
"drupal/core-project-message": "^9.2",
|
||||
"drupal/core-recommended": "^9.2",
|
||||
"drupal/pathauto": "^1.8",
|
||||
"drupal/views_slideshow": "^4.8",
|
||||
"drush/drush": "^10.6"
|
||||
},
|
||||
"conflict": {
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "3a4507df50c70c58c28226dd1344f87f",
|
||||
"content-hash": "661833152524e5f153d57b4704c9cb47",
|
||||
"packages": [
|
||||
{
|
||||
"name": "asm89/stack-cors",
|
||||
|
@ -1676,6 +1676,299 @@
|
|||
],
|
||||
"description": "Locked core dependencies; require this project INSTEAD OF drupal/core."
|
||||
},
|
||||
{
|
||||
"name": "drupal/ctools",
|
||||
"version": "3.7.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://git.drupalcode.org/project/ctools.git",
|
||||
"reference": "8.x-3.7"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://ftp.drupal.org/files/projects/ctools-8.x-3.7.zip",
|
||||
"reference": "8.x-3.7",
|
||||
"shasum": "b11c0981a1d2ab3cc9e8e614a337d8e2a2a70c0e"
|
||||
},
|
||||
"require": {
|
||||
"drupal/core": "^8.8 || ^9"
|
||||
},
|
||||
"type": "drupal-module",
|
||||
"extra": {
|
||||
"drupal": {
|
||||
"version": "8.x-3.7",
|
||||
"datestamp": "1623860918",
|
||||
"security-coverage": {
|
||||
"status": "covered",
|
||||
"message": "Covered by Drupal's security advisory policy"
|
||||
}
|
||||
},
|
||||
"branch-alias": {
|
||||
"dev-8.x-3.x": "3.x-dev"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packages.drupal.org/8/downloads",
|
||||
"license": [
|
||||
"GPL-2.0-or-later"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Kris Vanderwater (EclipseGc)",
|
||||
"homepage": "https://www.drupal.org/u/eclipsegc",
|
||||
"role": "Maintainer"
|
||||
},
|
||||
{
|
||||
"name": "Jakob Perry (japerry)",
|
||||
"homepage": "https://www.drupal.org/u/japerry",
|
||||
"role": "Maintainer"
|
||||
},
|
||||
{
|
||||
"name": "Tim Plunkett (tim.plunkett)",
|
||||
"homepage": "https://www.drupal.org/u/timplunkett",
|
||||
"role": "Maintainer"
|
||||
},
|
||||
{
|
||||
"name": "James Gilliland (neclimdul)",
|
||||
"homepage": "https://www.drupal.org/u/neclimdul",
|
||||
"role": "Maintainer"
|
||||
},
|
||||
{
|
||||
"name": "Daniel Wehner (dawehner)",
|
||||
"homepage": "https://www.drupal.org/u/dawehner",
|
||||
"role": "Maintainer"
|
||||
},
|
||||
{
|
||||
"name": "joelpittet",
|
||||
"homepage": "https://www.drupal.org/user/160302"
|
||||
},
|
||||
{
|
||||
"name": "merlinofchaos",
|
||||
"homepage": "https://www.drupal.org/user/26979"
|
||||
},
|
||||
{
|
||||
"name": "neclimdul",
|
||||
"homepage": "https://www.drupal.org/user/48673"
|
||||
},
|
||||
{
|
||||
"name": "sdboyer",
|
||||
"homepage": "https://www.drupal.org/user/146719"
|
||||
},
|
||||
{
|
||||
"name": "sun",
|
||||
"homepage": "https://www.drupal.org/user/54136"
|
||||
},
|
||||
{
|
||||
"name": "tim.plunkett",
|
||||
"homepage": "https://www.drupal.org/user/241634"
|
||||
}
|
||||
],
|
||||
"description": "Provides a number of utility and helper APIs for Drupal developers and site builders.",
|
||||
"homepage": "https://www.drupal.org/project/ctools",
|
||||
"support": {
|
||||
"source": "https://git.drupalcode.org/project/ctools",
|
||||
"issues": "https://www.drupal.org/project/issues/ctools"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "drupal/pathauto",
|
||||
"version": "1.8.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://git.drupalcode.org/project/pathauto.git",
|
||||
"reference": "8.x-1.8"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://ftp.drupal.org/files/projects/pathauto-8.x-1.8.zip",
|
||||
"reference": "8.x-1.8",
|
||||
"shasum": "ede3216abb9c4f77709338d9147334c595046329"
|
||||
},
|
||||
"require": {
|
||||
"drupal/core": "^8.8 || ^9",
|
||||
"drupal/ctools": "*",
|
||||
"drupal/token": "*"
|
||||
},
|
||||
"suggest": {
|
||||
"drupal/redirect": "When installed Pathauto will provide a new \"Update Action\" in case your URLs change. This is the recommended update action and is considered the best practice for SEO and usability."
|
||||
},
|
||||
"type": "drupal-module",
|
||||
"extra": {
|
||||
"drupal": {
|
||||
"version": "8.x-1.8",
|
||||
"datestamp": "1588103046",
|
||||
"security-coverage": {
|
||||
"status": "covered",
|
||||
"message": "Covered by Drupal's security advisory policy"
|
||||
}
|
||||
},
|
||||
"drush": {
|
||||
"services": {
|
||||
"drush.services.yml": "^9 || ^10"
|
||||
}
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packages.drupal.org/8/downloads",
|
||||
"license": [
|
||||
"GPL-2.0-or-later"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Berdir",
|
||||
"homepage": "https://www.drupal.org/user/214652"
|
||||
},
|
||||
{
|
||||
"name": "Dave Reid",
|
||||
"homepage": "https://www.drupal.org/user/53892"
|
||||
},
|
||||
{
|
||||
"name": "Freso",
|
||||
"homepage": "https://www.drupal.org/user/27504"
|
||||
},
|
||||
{
|
||||
"name": "greggles",
|
||||
"homepage": "https://www.drupal.org/user/36762"
|
||||
}
|
||||
],
|
||||
"description": "Provides a mechanism for modules to automatically generate aliases for the content they manage.",
|
||||
"homepage": "https://www.drupal.org/project/pathauto",
|
||||
"support": {
|
||||
"source": "https://cgit.drupalcode.org/pathauto",
|
||||
"issues": "https://www.drupal.org/project/issues/pathauto",
|
||||
"documentation": "https://www.drupal.org/docs/8/modules/pathauto"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "drupal/token",
|
||||
"version": "1.9.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://git.drupalcode.org/project/token.git",
|
||||
"reference": "8.x-1.9"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://ftp.drupal.org/files/projects/token-8.x-1.9.zip",
|
||||
"reference": "8.x-1.9",
|
||||
"shasum": "a5d234382a1a0e4ba61d4c7a2fa10671ca656be4"
|
||||
},
|
||||
"require": {
|
||||
"drupal/core": "^8.8 || ^9"
|
||||
},
|
||||
"type": "drupal-module",
|
||||
"extra": {
|
||||
"drupal": {
|
||||
"version": "8.x-1.9",
|
||||
"datestamp": "1608284866",
|
||||
"security-coverage": {
|
||||
"status": "covered",
|
||||
"message": "Covered by Drupal's security advisory policy"
|
||||
}
|
||||
},
|
||||
"drush": {
|
||||
"services": {
|
||||
"drush.services.yml": "^9 || ^10"
|
||||
}
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packages.drupal.org/8/downloads",
|
||||
"license": [
|
||||
"GPL-2.0-or-later"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Berdir",
|
||||
"homepage": "https://www.drupal.org/user/214652"
|
||||
},
|
||||
{
|
||||
"name": "Dave Reid",
|
||||
"homepage": "https://www.drupal.org/user/53892"
|
||||
},
|
||||
{
|
||||
"name": "eaton",
|
||||
"homepage": "https://www.drupal.org/user/16496"
|
||||
},
|
||||
{
|
||||
"name": "fago",
|
||||
"homepage": "https://www.drupal.org/user/16747"
|
||||
},
|
||||
{
|
||||
"name": "greggles",
|
||||
"homepage": "https://www.drupal.org/user/36762"
|
||||
},
|
||||
{
|
||||
"name": "mikeryan",
|
||||
"homepage": "https://www.drupal.org/user/4420"
|
||||
}
|
||||
],
|
||||
"description": "Provides a user interface for the Token API, some missing core tokens.",
|
||||
"homepage": "https://www.drupal.org/project/token",
|
||||
"support": {
|
||||
"source": "https://git.drupalcode.org/project/token"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "drupal/views_slideshow",
|
||||
"version": "4.8.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://git.drupalcode.org/project/views_slideshow.git",
|
||||
"reference": "8.x-4.8"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://ftp.drupal.org/files/projects/views_slideshow-8.x-4.8.zip",
|
||||
"reference": "8.x-4.8",
|
||||
"shasum": "88104843df5e2eaa7e70b796a80573d844583e42"
|
||||
},
|
||||
"require": {
|
||||
"drupal/core": "^8 || ^9"
|
||||
},
|
||||
"type": "drupal-module",
|
||||
"extra": {
|
||||
"drupal": {
|
||||
"version": "8.x-4.8",
|
||||
"datestamp": "1601309285",
|
||||
"security-coverage": {
|
||||
"status": "covered",
|
||||
"message": "Covered by Drupal's security advisory policy"
|
||||
}
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packages.drupal.org/8/downloads",
|
||||
"license": [
|
||||
"GPL-2.0-or-later"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Neslee Canil Pinto",
|
||||
"homepage": "https://www.drupal.org/u/neslee-canil-pinto",
|
||||
"role": "Maintainer"
|
||||
},
|
||||
{
|
||||
"name": "NickDickinsonWilde",
|
||||
"homepage": "https://www.drupal.org/user/3094661"
|
||||
},
|
||||
{
|
||||
"name": "aaron",
|
||||
"homepage": "https://www.drupal.org/user/33420"
|
||||
},
|
||||
{
|
||||
"name": "redndahead",
|
||||
"homepage": "https://www.drupal.org/user/160320"
|
||||
},
|
||||
{
|
||||
"name": "vbouchet",
|
||||
"homepage": "https://www.drupal.org/user/1671428"
|
||||
}
|
||||
],
|
||||
"description": "Describes relationships between entities.",
|
||||
"homepage": "https://www.drupal.org/project/views_slideshow",
|
||||
"support": {
|
||||
"source": "https://git.drupalcode.org/project/views_slideshow",
|
||||
"issues": "https://www.drupal.org/project/issues/views_slideshow",
|
||||
"irc": "irc://irc.freenode.org/drupal-contribute"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "drush/drush",
|
||||
"version": "10.6.1",
|
||||
|
@ -6140,5 +6433,5 @@
|
|||
"prefer-lowest": false,
|
||||
"platform": [],
|
||||
"platform-dev": [],
|
||||
"plugin-api-version": "2.0.0"
|
||||
"plugin-api-version": "2.1.0"
|
||||
}
|
||||
|
|
|
@ -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,84 @@
|
|||
CONTENTS OF THIS FILE
|
||||
---------------------
|
||||
|
||||
* Introduction
|
||||
* Requirements
|
||||
* Recommended Modules
|
||||
* Installation
|
||||
* Configuration
|
||||
|
||||
INTRODUCTION
|
||||
------------
|
||||
|
||||
The Chaos Tool Suite (ctools) module is primarily a set of APIs and tools to
|
||||
improve the developer experience. It also contains a module called the Page
|
||||
Manager whose job is to manage pages. In particular it manages panel pages, but
|
||||
as it grows it will be able to manage far more than just Panels.
|
||||
|
||||
The Chaos Tool Suite (ctools) is a series of tools that makes code readily
|
||||
available for developers and creates libraries for other modules to use. Modules
|
||||
that use ctools include Panels and Pathauto.
|
||||
|
||||
End users will use ctools as underlying user interface libraries when operating
|
||||
Views and Panels modules and will not need to explore further (ctools is geared
|
||||
more toward developer usage). Developers will use the module differently and
|
||||
work more with the tools provided.
|
||||
|
||||
For the moment, it includes the following tools:
|
||||
|
||||
* Plugins -- tools to make it easy for modules to let other modules implement
|
||||
plugins from .inc files.
|
||||
* Exportables -- tools to make it easier for modules to have objects that live
|
||||
in database or live in code, such as 'default views'.
|
||||
* AJAX responder -- tools to make it easier for the server to handle AJAX
|
||||
requests and tell the client what to do with them.
|
||||
* Form tools -- tools to make it easier for forms to deal with AJAX.
|
||||
* Object caching -- tool to make it easier to edit an object across multiple
|
||||
page requests and cache the editing work.
|
||||
* Contexts -- the notion of wrapping objects in a unified wrapper and providing
|
||||
an API to create and accept these contexts as input.
|
||||
* Modal dialog -- tool to make it simple to put a form in a modal dialog.
|
||||
* Dependent -- a simple form widget to make form items appear and disappear
|
||||
based upon the selections in another item.
|
||||
* Content -- pluggable content types used as panes in Panels and other modules
|
||||
like Dashboard.
|
||||
* Form wizard -- an API to make multi-step forms much easier.
|
||||
* CSS tools -- tools to cache and sanitize CSS easily to make user-input CSS
|
||||
safe.
|
||||
|
||||
* For a full description of the module visit:
|
||||
https://www.drupal.org/project/ctools
|
||||
|
||||
* To submit bug reports and feature suggestions, or to track changes visit:
|
||||
https://www.drupal.org/project/issues/ctools
|
||||
|
||||
|
||||
REQUIREMENTS
|
||||
------------
|
||||
|
||||
This module requires no modules outside of Drupal core.
|
||||
|
||||
|
||||
RECOMMENDED MODULES
|
||||
-------------------
|
||||
|
||||
The Advanced help module provides extended documentation. Once enabled,
|
||||
navigate to Administration > Advanced Help and select the Chaos Tools link to
|
||||
view documentation.
|
||||
|
||||
* Advanced help - https://www.drupal.org/project/advanced_help
|
||||
|
||||
|
||||
INSTALLATION
|
||||
------------
|
||||
|
||||
* Install the Chaos Tool Suite module as you would normally install a
|
||||
contributed Drupal module. Visit
|
||||
https://www.drupal.org/docs/8/extending-drupal-8/installing-drupal-8-modules
|
||||
for further information.
|
||||
|
||||
|
||||
CONFIGURATION
|
||||
-------------
|
||||
|
||||
No configuration is needed.
|
|
@ -0,0 +1,47 @@
|
|||
{
|
||||
"name": "drupal/ctools",
|
||||
"description": "Provides a number of utility and helper APIs for Drupal developers and site builders.",
|
||||
"type": "drupal-module",
|
||||
"license": "GPL-2.0-or-later",
|
||||
"minimum-stability": "dev",
|
||||
"homepage": "https://www.drupal.org/project/ctools",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Kris Vanderwater (EclipseGc)",
|
||||
"homepage": "https://www.drupal.org/u/eclipsegc",
|
||||
"role": "Maintainer"
|
||||
},
|
||||
{
|
||||
"name": "Jakob Perry (japerry)",
|
||||
"homepage": "https://www.drupal.org/u/japerry",
|
||||
"role": "Maintainer"
|
||||
},
|
||||
{
|
||||
"name": "Tim Plunkett (tim.plunkett)",
|
||||
"homepage": "https://www.drupal.org/u/timplunkett",
|
||||
"role": "Maintainer"
|
||||
},
|
||||
{
|
||||
"name": "James Gilliland (neclimdul)",
|
||||
"homepage": "https://www.drupal.org/u/neclimdul",
|
||||
"role": "Maintainer"
|
||||
},
|
||||
{
|
||||
"name": "Daniel Wehner (dawehner)",
|
||||
"homepage": "https://www.drupal.org/u/dawehner",
|
||||
"role": "Maintainer"
|
||||
}
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://www.drupal.org/project/issues/ctools",
|
||||
"source": "https://git.drupalcode.org/project/ctools"
|
||||
},
|
||||
"require": {
|
||||
"drupal/core": "^8.8 || ^9"
|
||||
},
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-8.x-3.x": "3.x-dev"
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,63 @@
|
|||
ctools.context:
|
||||
type: mapping
|
||||
label: Context
|
||||
mapping:
|
||||
label:
|
||||
type: label
|
||||
label: 'Label of the context'
|
||||
type:
|
||||
type: string
|
||||
label: 'Context type'
|
||||
description:
|
||||
type: string
|
||||
label: 'Description of the context'
|
||||
value:
|
||||
type: string
|
||||
label: 'Context value'
|
||||
|
||||
ctools.relationship:
|
||||
type: mapping
|
||||
label: 'Relationship'
|
||||
mapping:
|
||||
id:
|
||||
type: string
|
||||
label: 'ID'
|
||||
label:
|
||||
type: label
|
||||
label: 'Label'
|
||||
|
||||
condition.plugin.entity_bundle:*:
|
||||
type: condition.plugin
|
||||
mapping:
|
||||
bundles:
|
||||
type: sequence
|
||||
sequence:
|
||||
type: string
|
||||
|
||||
ctools.block_plugin.*:
|
||||
type: block.settings.[id]
|
||||
mapping:
|
||||
region:
|
||||
type: string
|
||||
label: 'Region'
|
||||
weight:
|
||||
type: integer
|
||||
label: 'Weight'
|
||||
uuid:
|
||||
type: string
|
||||
label: 'UUID'
|
||||
context_mapping:
|
||||
type: sequence
|
||||
label: 'Context assignments'
|
||||
sequence:
|
||||
- type: string
|
||||
|
||||
ctools.block_display_variant:
|
||||
type: display_variant.plugin
|
||||
label: 'Block display variant'
|
||||
mapping:
|
||||
blocks:
|
||||
type: sequence
|
||||
label: 'Blocks'
|
||||
sequence:
|
||||
- type: ctools.block_plugin.[id]
|
|
@ -0,0 +1,10 @@
|
|||
name: Chaos Tools
|
||||
type: module
|
||||
description: 'Provides a number of utility and helper APIs for Drupal developers and site builders.'
|
||||
package: Chaos tool suite
|
||||
core_version_requirement: ^8.8 || ^9
|
||||
|
||||
# Information added by Drupal.org packaging script on 2021-06-16
|
||||
version: '8.x-3.7'
|
||||
project: 'ctools'
|
||||
datestamp: 1623822132
|
|
@ -0,0 +1,122 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Provides utility and helper APIs for Drupal developers and site builders.
|
||||
*/
|
||||
|
||||
use Drupal\Core\Url;
|
||||
use Drupal\Core\Routing\RouteMatchInterface;
|
||||
|
||||
/**
|
||||
* Implements hook_theme().
|
||||
*
|
||||
* @param $existing
|
||||
* @param $type
|
||||
* @param $theme
|
||||
* @param $path
|
||||
*
|
||||
* @return \array[][]
|
||||
*/
|
||||
function ctools_theme($existing, $type, $theme, $path) {
|
||||
return [
|
||||
'ctools_wizard_trail' => [
|
||||
'variables' => [
|
||||
'wizard' => NULL,
|
||||
'cached_values' => [],
|
||||
'trail' => [],
|
||||
'divider' => ' » ',
|
||||
'step' => NULL,
|
||||
],
|
||||
],
|
||||
'ctools_wizard_trail_links' => [
|
||||
'variables' => [
|
||||
'wizard' => NULL,
|
||||
'cached_values' => [],
|
||||
'trail' => [],
|
||||
'divider' => ' » ',
|
||||
'step' => NULL,
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Template Preprocess for Wizard Trail.
|
||||
*
|
||||
* @param $variables
|
||||
*/
|
||||
function template_preprocess_ctools_wizard_trail(&$variables) {
|
||||
/** @var $wizard \Drupal\ctools\Wizard\FormWizardInterface|\Drupal\ctools\Wizard\EntityFormWizardInterface */
|
||||
$wizard = $variables['wizard'];
|
||||
$cached_values = $variables['cached_values'];
|
||||
$trail = $variables['trail'];
|
||||
$variables['step'] = $wizard->getStep($cached_values);
|
||||
foreach ($wizard->getOperations($cached_values) as $step => $operation) {
|
||||
$trail[$step] = !empty($operation['title']) ? $operation['title'] : '';
|
||||
}
|
||||
$variables['trail'] = $trail;
|
||||
}
|
||||
|
||||
/**
|
||||
* Template Preprocess for Trail links.
|
||||
*
|
||||
* @param $variables
|
||||
*/
|
||||
function template_preprocess_ctools_wizard_trail_links(&$variables) {
|
||||
/** @var $wizard \Drupal\ctools\Wizard\FormWizardInterface|\Drupal\ctools\Wizard\EntityFormWizardInterface */
|
||||
$wizard = $variables['wizard'];
|
||||
$cached_values = $variables['cached_values'];
|
||||
$trail = $variables['trail'];
|
||||
$variables['step'] = $wizard->getStep($cached_values);
|
||||
foreach ($wizard->getOperations($cached_values) as $step => $operation) {
|
||||
$parameters = $wizard->getNextParameters($cached_values);
|
||||
// Override step to be the step we want.
|
||||
$parameters['step'] = $step;
|
||||
$trail[$step] = [
|
||||
'title' => !empty($operation['title']) ? $operation['title'] : '',
|
||||
'url' => new Url($wizard->getRouteName(), $parameters),
|
||||
];
|
||||
}
|
||||
$variables['trail'] = $trail;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements Hook Info alter.
|
||||
*
|
||||
* @param $definitions
|
||||
*/
|
||||
function ctools_condition_info_alter(&$definitions) {
|
||||
// If the node_type's class is unaltered, use a custom ctools implementation.
|
||||
if (isset($definitions['node_type']) && $definitions['node_type']['class'] == 'Drupal\node\Plugin\Condition\NodeType') {
|
||||
$definitions['node_type']['class'] = 'Drupal\ctools\Plugin\Condition\NodeType';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Implements hook_help().
|
||||
*/
|
||||
function ctools_help($route_name, RouteMatchInterface $route_match) {
|
||||
switch ($route_name) {
|
||||
case 'help.page.ctools':
|
||||
$output = '';
|
||||
$output .= '<h3>' . t('About') . '</h3>';
|
||||
$output .= '<p>' . t('This suite is primarily a set of APIs and tools to improve the developer experience. It also contains a module called the Page Manager whose job is to manage pages. In particular it manages panel pages, but as it grows it will be able to manage far more than just Panels.') . '</p>';
|
||||
|
||||
$output .= '<p>' . t('For the moment, it includes the following tools:') . '</p>';
|
||||
$output .= '<ul>';
|
||||
$output .= '<li>' . t('Plugins -- tools to make it easy for modules to let other modules implement plugins from .inc files.') . '</li>';
|
||||
$output .= '<li>' . t('Exportables -- tools to make it easier for modules to have objects that live in database or live in code, such as "default views".') . '</li>';
|
||||
$output .= '<li>' . t('AJAX responder -- tools to make it easier for the server to handle AJAX requests and tell the client what to do with them.') . '</li>';
|
||||
$output .= '<li>' . t('Form tools -- tools to make it easier for forms to deal with AJAX.') . '</li>';
|
||||
$output .= '<li>' . t('Object caching -- tool to make it easier to edit an object across multiple page requests and cache the editing work.') . '</li>';
|
||||
$output .= '<li>' . t('Contexts -- the notion of wrapping objects in a unified wrapper and providing an API to create and accept these contexts as input.') . '</li>';
|
||||
$output .= '<li>' . t('Modal dialog -- tool to make it simple to put a form in a modal dialog.') . '</li>';
|
||||
$output .= '<li>' . t('Dependent -- a simple form widget to make form items appear and disappear based upon the selections in another item.') . '</li>';
|
||||
$output .= '<li>' . t('Content -- pluggable content types used as panes in Panels and other modules like Dashboard.') . '</li>';
|
||||
$output .= '<li>' . t('Form wizard -- an API to make multi-step forms much easier.') . '</li>';+ $output .= '<li>' . t('CSS tools -- tools to cache and sanitize CSS easily to make user-input CSS safe.') . '</li>';
|
||||
$output .= '</ul>';
|
||||
return $output;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
services:
|
||||
ctools.wizard.form:
|
||||
class: Drupal\ctools\Controller\WizardFormController
|
||||
arguments: ['@http_kernel.controller.argument_resolver', '@form_builder', '@ctools.wizard.factory']
|
||||
ctools.wizard.entity.form:
|
||||
class: Drupal\ctools\Controller\WizardEntityFormController
|
||||
arguments: ['@http_kernel.controller.argument_resolver', '@form_builder', '@ctools.wizard.factory', '@entity_type.manager']
|
||||
ctools.wizard_enhancer:
|
||||
class: Drupal\ctools\Routing\Enhancer\WizardEnhancer
|
||||
tags:
|
||||
- { name: route_enhancer }
|
||||
ctools.wizard.factory:
|
||||
class: Drupal\ctools\Wizard\WizardFactory
|
||||
arguments: ['@form_builder', '@event_dispatcher', '@renderer']
|
||||
ctools.paramconverter.tempstore:
|
||||
class: Drupal\ctools\ParamConverter\TempstoreConverter
|
||||
arguments: ['@tempstore.shared', '@entity_type.manager']
|
||||
tags:
|
||||
- { name: paramconverter }
|
||||
ctools.typed_data.resolver:
|
||||
class: Drupal\ctools\TypedDataResolver
|
||||
arguments: ['@typed_data_manager', '@string_translation']
|
||||
ctools.access:
|
||||
class: Drupal\ctools\Access\TempstoreAccess
|
||||
arguments: ['@tempstore.shared']
|
||||
tags:
|
||||
- { name: access_check, applies_to: _ctools_access }
|
||||
plugin.manager.ctools.relationship:
|
||||
class: Drupal\ctools\Plugin\RelationshipManager
|
||||
parent: default_plugin_manager
|
||||
ctools.context_mapper:
|
||||
class: Drupal\ctools\ContextMapper
|
||||
arguments: ['@entity.repository']
|
||||
ctools.serializable.tempstore.factory:
|
||||
class: Drupal\ctools\SerializableTempstoreFactory
|
||||
arguments: ['@keyvalue.expirable', '@lock', '@request_stack', '%tempstore.expire%', '@current_user']
|
||||
tags:
|
||||
- { name: backend_overridable }
|
|
@ -0,0 +1,28 @@
|
|||
block.settings.entity_field:*:*:
|
||||
type: block_settings
|
||||
label: 'Entity field block'
|
||||
mapping:
|
||||
formatter:
|
||||
type: mapping
|
||||
label: 'Field formatter'
|
||||
mapping:
|
||||
type:
|
||||
type: string
|
||||
label: 'Format type machine name'
|
||||
weight:
|
||||
type: integer
|
||||
label: 'Weight'
|
||||
region:
|
||||
type: string
|
||||
label: 'Region'
|
||||
label:
|
||||
type: string
|
||||
label: 'Label setting machine name'
|
||||
settings:
|
||||
type: field.formatter.settings.[%parent.type]
|
||||
label: 'Settings'
|
||||
third_party_settings:
|
||||
type: sequence
|
||||
label: 'Third party settings'
|
||||
sequence:
|
||||
type: field.formatter.third_party.[%key]
|
|
@ -0,0 +1,12 @@
|
|||
name: Chaos Tools Blocks
|
||||
type: module
|
||||
description: 'Provides improvements to blocks that will one day be added to Drupal core.'
|
||||
package: Chaos tool suite (Experimental)
|
||||
core_version_requirement: ^8.8 || ^9
|
||||
dependencies:
|
||||
- ctools:ctools
|
||||
|
||||
# Information added by Drupal.org packaging script on 2021-06-16
|
||||
version: '8.x-3.7'
|
||||
project: 'ctools'
|
||||
datestamp: 1623822132
|
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Chaos Tools Blocks.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Remove ctools block from appearing on viewable block types.
|
||||
*
|
||||
* In general, users should be using the core block types instead.
|
||||
*/
|
||||
function ctools_block_plugin_filter_block_alter(array &$definitions, array $extra, $consumer) {
|
||||
$moduleHandler = \Drupal::service('module_handler');
|
||||
if ($moduleHandler->moduleExists('layout_builder')) {
|
||||
foreach ($definitions as $label => $definition) {
|
||||
if ($definition['provider'] == 'ctools_block') {
|
||||
unset($definitions[$label]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,381 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\ctools_block\Plugin\Block;
|
||||
|
||||
use Drupal\Component\Utility\NestedArray;
|
||||
use Drupal\Core\Access\AccessResult;
|
||||
use Drupal\Core\Block\BlockBase;
|
||||
use Drupal\Core\Entity\EntityFieldManagerInterface;
|
||||
use Drupal\Core\Entity\EntityTypeManagerInterface;
|
||||
use Drupal\Core\Entity\FieldableEntityInterface;
|
||||
use Drupal\Core\Field\FieldTypePluginManagerInterface;
|
||||
use Drupal\Core\Field\FormatterPluginManager;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
|
||||
use Drupal\Core\Plugin\ContextAwarePluginInterface;
|
||||
use Drupal\Core\Render\Element;
|
||||
use Drupal\Core\Session\AccountInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
/**
|
||||
* Provides a block to a field on an entity.
|
||||
*
|
||||
* @Block(
|
||||
* id = "entity_field",
|
||||
* deriver = "Drupal\ctools_block\Plugin\Deriver\EntityFieldDeriver",
|
||||
* )
|
||||
*/
|
||||
class EntityField extends BlockBase implements ContextAwarePluginInterface, ContainerFactoryPluginInterface {
|
||||
|
||||
/**
|
||||
* The entity type manager.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
|
||||
*/
|
||||
protected $entityTypeManager;
|
||||
|
||||
/**
|
||||
* The entity field manager.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityFieldManagerInterface
|
||||
*/
|
||||
protected $entityFieldManager;
|
||||
|
||||
/**
|
||||
* The field type manager.
|
||||
*
|
||||
* @var \Drupal\Core\Field\FieldTypePluginManagerInterface
|
||||
*/
|
||||
protected $fieldTypeManager;
|
||||
|
||||
/**
|
||||
* The formatter manager.
|
||||
*
|
||||
* @var \Drupal\Core\Field\FormatterPluginManager
|
||||
*/
|
||||
protected $formatterManager;
|
||||
|
||||
/**
|
||||
* The entity type id.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $entityTypeId;
|
||||
|
||||
/**
|
||||
* The field name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $fieldName;
|
||||
|
||||
/**
|
||||
* The field definition.
|
||||
*
|
||||
* @var \Drupal\Core\Field\FieldDefinitionInterface
|
||||
*/
|
||||
protected $fieldDefinition;
|
||||
|
||||
/**
|
||||
* The field storage definition.
|
||||
*
|
||||
* @var \Drupal\Core\Field\FieldStorageDefinitionInterface
|
||||
*/
|
||||
protected $fieldStorageDefinition;
|
||||
|
||||
/**
|
||||
* Constructs a new EntityField.
|
||||
*
|
||||
* @param array $configuration
|
||||
* A configuration array containing information about the plugin instance.
|
||||
* @param string $plugin_id
|
||||
* The plugin ID for the plugin instance.
|
||||
* @param mixed $plugin_definition
|
||||
* The plugin implementation definition.
|
||||
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
|
||||
* The entity type manager.
|
||||
* @param \Drupal\Core\Entity\EntityFieldManagerInterface $entity_field_manager
|
||||
* The entity field manager.
|
||||
* @param \Drupal\Core\Field\FieldTypePluginManagerInterface $field_type_manager
|
||||
* The field type manager.
|
||||
* @param \Drupal\Core\Field\FormatterPluginManager $formatter_manager
|
||||
* The formatter manager.
|
||||
*/
|
||||
public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entity_type_manager, EntityFieldManagerInterface $entity_field_manager, FieldTypePluginManagerInterface $field_type_manager, FormatterPluginManager $formatter_manager) {
|
||||
$this->entityTypeManager = $entity_type_manager;
|
||||
$this->entityFieldManager = $entity_field_manager;
|
||||
$this->fieldTypeManager = $field_type_manager;
|
||||
$this->formatterManager = $formatter_manager;
|
||||
|
||||
// Get the entity type and field name from the plugin id.
|
||||
list (, $entity_type_id, $field_name) = explode(':', $plugin_id);
|
||||
$this->entityTypeId = $entity_type_id;
|
||||
$this->fieldName = $field_name;
|
||||
|
||||
parent::__construct($configuration, $plugin_id, $plugin_definition);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
|
||||
return new static(
|
||||
$configuration,
|
||||
$plugin_id,
|
||||
$plugin_definition,
|
||||
$container->get('entity_type.manager'),
|
||||
$container->get('entity_field.manager'),
|
||||
$container->get('plugin.manager.field.field_type'),
|
||||
$container->get('plugin.manager.field.formatter')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function build() {
|
||||
/** @var \Drupal\Core\Entity\FieldableEntityInterface $entity */
|
||||
$entity = $this->getContextValue('entity');
|
||||
$build = [];
|
||||
/** @var \Drupal\Core\Field\FieldItemListInterface $field */
|
||||
$field = $entity->{$this->fieldName};
|
||||
$display_settings = $this->getConfiguration()['formatter'];
|
||||
$build['field'] = $field->view($display_settings);
|
||||
|
||||
// Set the cache data appropriately.
|
||||
$build['#cache']['contexts'] = $this->getCacheContexts();
|
||||
$build['#cache']['tags'] = $this->getCacheTags();
|
||||
$build['#cache']['max-age'] = $this->getCacheMaxAge();
|
||||
|
||||
return $build;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function blockAccess(AccountInterface $account) {
|
||||
/** @var \Drupal\Core\Entity\EntityInterface $entity */
|
||||
$entity = $this->getContextValue('entity');
|
||||
// Make sure we have access to the entity.
|
||||
$access = $entity->access('view', $account, TRUE);
|
||||
if ($access->isAllowed()) {
|
||||
// Check that the entity in question has this field.
|
||||
if ($entity instanceof FieldableEntityInterface && $entity->hasField($this->fieldName)) {
|
||||
// Check field access.
|
||||
$field_access = $this->entityTypeManager
|
||||
->getAccessControlHandler($this->entityTypeId)
|
||||
->fieldAccess('view', $this->getFieldDefinition(), $account);
|
||||
|
||||
if ($field_access) {
|
||||
// Build a renderable array for the field.
|
||||
$build = $entity->get($this->fieldName)->view($this->configuration['formatter']);
|
||||
// If there are actual renderable children, grant access.
|
||||
if (Element::children($build)) {
|
||||
return AccessResult::allowed();
|
||||
}
|
||||
}
|
||||
}
|
||||
// Entity doesn't have this field, so access is denied.
|
||||
return AccessResult::forbidden();
|
||||
}
|
||||
// If we don't have access to the entity, return the forbidden result.
|
||||
return $access;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function defaultConfiguration() {
|
||||
$field_type_definition = $this->getFieldTypeDefinition();
|
||||
return [
|
||||
'formatter' => [
|
||||
'label' => 'above',
|
||||
'type' => isset($field_type_definition['default_formatter']) ? $field_type_definition['default_formatter'] : '',
|
||||
'settings' => [],
|
||||
'third_party_settings' => [],
|
||||
'weight' => 0,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function blockForm($form, FormStateInterface $form_state) {
|
||||
$config = $this->getConfiguration();
|
||||
|
||||
$form['formatter_label'] = [
|
||||
'#type' => 'select',
|
||||
'#title' => $this->t('Label'),
|
||||
'#options' => [
|
||||
'above' => $this->t('Above'),
|
||||
'inline' => $this->t('Inline'),
|
||||
'hidden' => '- ' . $this->t('Hidden') . ' -',
|
||||
'visually_hidden' => '- ' . $this->t('Visually Hidden') . ' -',
|
||||
],
|
||||
'#default_value' => $config['formatter']['label'],
|
||||
];
|
||||
|
||||
$form['formatter_type'] = [
|
||||
'#type' => 'select',
|
||||
'#title' => $this->t('Formatter'),
|
||||
'#options' => $this->getFormatterOptions(),
|
||||
'#default_value' => $config['formatter']['type'],
|
||||
'#ajax' => [
|
||||
'callback' => [static::class, 'formatterSettingsAjaxCallback'],
|
||||
'wrapper' => 'formatter-settings-wrapper',
|
||||
'effect' => 'fade',
|
||||
],
|
||||
];
|
||||
|
||||
// Add the formatter settings to the form via AJAX.
|
||||
$form['#process'][] = [$this, 'formatterSettingsProcessCallback'];
|
||||
$form['formatter_settings_wrapper'] = [
|
||||
'#prefix' => '<div id="formatter-settings-wrapper">',
|
||||
'#suffix' => '</div>',
|
||||
];
|
||||
$form['formatter_settings_wrapper']['formatter_settings'] = [
|
||||
'#tree' => TRUE,
|
||||
// The settings from the formatter plugin will be added in the
|
||||
// ::formatterSettingsProcessCallback method.
|
||||
];
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Render API callback: builds the formatter settings elements.
|
||||
*/
|
||||
public function formatterSettingsProcessCallback(array &$element, FormStateInterface $form_state, array &$complete_form) {
|
||||
$config = $this->getConfiguration();
|
||||
$parents_base = $element['#parents'];
|
||||
$formatter_parent = array_merge($parents_base, ['formatter_type']);
|
||||
$formatter_settings_parent = array_merge($parents_base, ['formatter_settings']);
|
||||
|
||||
$settings_element = &$element['formatter_settings_wrapper']['formatter_settings'];
|
||||
|
||||
// Set the #parents on the formatter_settings so they end up as a peer to
|
||||
// formatter_type.
|
||||
$settings_element['#parents'] = $formatter_settings_parent;
|
||||
|
||||
// Get the formatter name in a way that works regardless of whether we're
|
||||
// getting the value via AJAX or not.
|
||||
$formatter_name = NestedArray::getValue($form_state->getUserInput(), $formatter_parent) ?: $element['formatter_type']['#default_value'];
|
||||
|
||||
// Place the formatter settings on the form if a formatter is selected.
|
||||
$formatter = $this->getFormatter($formatter_name, $form_state->getValue('formatter_label'), $form_state->getValue($formatter_settings_parent, $config['formatter']['settings']), $config['formatter']['third_party_settings']);
|
||||
$settings_element = array_merge($formatter->settingsForm($settings_element, $form_state), $settings_element);
|
||||
|
||||
// Store the array parents for our element so that we can use it to pull out
|
||||
// the formatter settings in our AJAX callback.
|
||||
$complete_form['#formatter_array_parents'] = $element['#array_parents'];
|
||||
|
||||
return $element;
|
||||
}
|
||||
|
||||
/**
|
||||
* Render API callback: gets the layout settings elements.
|
||||
*/
|
||||
public static function formatterSettingsAjaxCallback(array $form, FormStateInterface $form_state) {
|
||||
$formatter_array_parents = $form['#formatter_array_parents'];
|
||||
return NestedArray::getValue($form, array_merge($formatter_array_parents, ['formatter_settings_wrapper']));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function blockSubmit($form, FormStateInterface $form_state) {
|
||||
$this->configuration['formatter']['label'] = $form_state->getValue('formatter_label');
|
||||
$this->configuration['formatter']['type'] = $form_state->getValue('formatter_type');
|
||||
// @todo Remove this manual cast after https://www.drupal.org/node/2635236
|
||||
// is resolved.
|
||||
$this->configuration['formatter']['settings'] = (array) $form_state->getValue('formatter_settings');
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the field definition.
|
||||
*
|
||||
* @return \Drupal\Core\Field\FieldDefinitionInterface
|
||||
* The field definition.
|
||||
*/
|
||||
protected function getFieldDefinition() {
|
||||
if (empty($this->fieldDefinition)) {
|
||||
$field_map = $this->entityFieldManager->getFieldMap();
|
||||
$bundle = reset($field_map[$this->entityTypeId][$this->fieldName]['bundles']);
|
||||
$field_definitions = $this->entityFieldManager->getFieldDefinitions($this->entityTypeId, $bundle);
|
||||
$this->fieldDefinition = $field_definitions[$this->fieldName];
|
||||
}
|
||||
return $this->fieldDefinition;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the field storage definition.
|
||||
*
|
||||
* @return \Drupal\Core\Field\FieldStorageDefinitionInterface
|
||||
* The field storage definition.
|
||||
*/
|
||||
protected function getFieldStorageDefinition() {
|
||||
if (empty($this->fieldStorageDefinition)) {
|
||||
$field_definitions = $this->entityFieldManager->getFieldStorageDefinitions($this->entityTypeId);
|
||||
$this->fieldStorageDefinition = $field_definitions[$this->fieldName];
|
||||
}
|
||||
return $this->fieldStorageDefinition;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets field type definition.
|
||||
*
|
||||
* @return array
|
||||
* The field type definition.
|
||||
*/
|
||||
protected function getFieldTypeDefinition() {
|
||||
return $this->fieldTypeManager->getDefinition($this->getFieldStorageDefinition()->getType());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the formatter options for this field type.
|
||||
*
|
||||
* @return array
|
||||
* The formatter options.
|
||||
*/
|
||||
protected function getFormatterOptions() {
|
||||
return $this->formatterManager->getOptions($this->getFieldStorageDefinition()->getType());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the formatter object.
|
||||
*
|
||||
* @param string $type
|
||||
* The formatter name.
|
||||
* @param string $label
|
||||
* The label option for the formatter.
|
||||
* @param array $settings
|
||||
* The formatter settings.
|
||||
* @param array $third_party_settings
|
||||
* The formatter third party settings.
|
||||
*
|
||||
* @return \Drupal\Core\Field\FormatterInterface
|
||||
* The formatter object.
|
||||
*/
|
||||
protected function getFormatter($type, $label, array $settings, array $third_party_settings) {
|
||||
return $this->formatterManager->createInstance($type, [
|
||||
'field_definition' => $this->getFieldDefinition(),
|
||||
'view_mode' => 'default',
|
||||
'prepare' => TRUE,
|
||||
'label' => $label,
|
||||
'settings' => $settings,
|
||||
'third_party_settings' => $third_party_settings,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function __wakeup() {
|
||||
parent::__wakeup();
|
||||
// @todo figure out why this happens.
|
||||
// prevent $fieldStorageDefinition being erroneously set to $this.
|
||||
$this->fieldStorageDefinition = NULL;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,65 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\ctools_block\Plugin\Deriver;
|
||||
|
||||
use Drupal\Core\Plugin\Context\EntityContextDefinition;
|
||||
use Drupal\ctools\Plugin\Deriver\EntityDeriverBase;
|
||||
|
||||
/**
|
||||
* Provides entity field block definitions for every field.
|
||||
*/
|
||||
class EntityFieldDeriver extends EntityDeriverBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getDerivativeDefinitions($base_plugin_definition) {
|
||||
$entity_type_labels = $this->entityTypeRepository->getEntityTypeLabels();
|
||||
foreach ($this->entityFieldManager->getFieldMap() as $entity_type_id => $entity_field_map) {
|
||||
foreach ($this->entityFieldManager->getFieldStorageDefinitions($entity_type_id) as $field_storage_definition) {
|
||||
$field_name = $field_storage_definition->getName();
|
||||
|
||||
// The blocks are based on fields. However, we are looping through field
|
||||
// storages for which no fields may exist. If that is the case, skip
|
||||
// this field storage.
|
||||
if (!isset($entity_field_map[$field_name])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$field_info = $entity_field_map[$field_name];
|
||||
$derivative_id = $entity_type_id . ":" . $field_name;
|
||||
|
||||
// Get the admin label for both base and configurable fields.
|
||||
if ($field_storage_definition->isBaseField()) {
|
||||
$admin_label = $field_storage_definition->getLabel();
|
||||
}
|
||||
else {
|
||||
// We take the field label used on the first bundle.
|
||||
$first_bundle = reset($field_info['bundles']);
|
||||
$bundle_field_definitions = $this->entityFieldManager->getFieldDefinitions($entity_type_id, $first_bundle);
|
||||
|
||||
// The field storage config may exist, but it's possible that no
|
||||
// fields are actually using it. If that's the case, skip to the next
|
||||
// field.
|
||||
if (empty($bundle_field_definitions[$field_name])) {
|
||||
continue;
|
||||
}
|
||||
$admin_label = $bundle_field_definitions[$field_name]->getLabel();
|
||||
}
|
||||
|
||||
// Set plugin definition for derivative.
|
||||
$derivative = $base_plugin_definition;
|
||||
$derivative['category'] = $this->t('@entity', ['@entity' => $entity_type_labels[$entity_type_id]]);
|
||||
$derivative['admin_label'] = $admin_label;
|
||||
$derivative['context_definitions'] = [
|
||||
'entity' => new EntityContextDefinition('entity:' . $entity_type_id, $entity_type_labels[$entity_type_id], TRUE),
|
||||
];
|
||||
|
||||
$this->derivatives[$derivative_id] = $derivative;
|
||||
|
||||
}
|
||||
}
|
||||
return $this->derivatives;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
langcode: en
|
||||
status: true
|
||||
dependencies:
|
||||
config:
|
||||
- node.type.ctools_block_field_test
|
||||
_core:
|
||||
default_config_hash: hoRuk0InNhhRVGnhQ9hzifTXVz432i9hvPe-tVstUbc
|
||||
id: node.ctools_block_field_test.promote
|
||||
field_name: promote
|
||||
entity_type: node
|
||||
bundle: ctools_block_field_test
|
||||
label: 'Promoted to front page'
|
||||
description: ''
|
||||
required: false
|
||||
translatable: true
|
||||
default_value:
|
||||
-
|
||||
value: 0
|
||||
default_value_callback: ''
|
||||
settings:
|
||||
on_label: 'On'
|
||||
off_label: 'Off'
|
||||
field_type: boolean
|
|
@ -0,0 +1,62 @@
|
|||
langcode: en
|
||||
status: true
|
||||
dependencies:
|
||||
config:
|
||||
- field.field.node.ctools_block_field_test.body
|
||||
- node.type.ctools_block_field_test
|
||||
module:
|
||||
- path
|
||||
- text
|
||||
_core:
|
||||
default_config_hash: xpDeWNLzjX4dDB9YyBlO9y9FR4vHwMv0GKsuqDYy0Bc
|
||||
id: node.ctools_block_field_test.default
|
||||
targetEntityType: node
|
||||
bundle: ctools_block_field_test
|
||||
mode: default
|
||||
content:
|
||||
body:
|
||||
type: text_textarea_with_summary
|
||||
weight: 31
|
||||
settings:
|
||||
rows: 9
|
||||
summary_rows: 3
|
||||
placeholder: ''
|
||||
third_party_settings: { }
|
||||
created:
|
||||
type: datetime_timestamp
|
||||
weight: 10
|
||||
settings: { }
|
||||
third_party_settings: { }
|
||||
path:
|
||||
type: path
|
||||
weight: 30
|
||||
settings: { }
|
||||
third_party_settings: { }
|
||||
promote:
|
||||
type: boolean_checkbox
|
||||
settings:
|
||||
display_label: true
|
||||
weight: 15
|
||||
third_party_settings: { }
|
||||
sticky:
|
||||
type: boolean_checkbox
|
||||
settings:
|
||||
display_label: true
|
||||
weight: 16
|
||||
third_party_settings: { }
|
||||
title:
|
||||
type: string_textfield
|
||||
weight: -5
|
||||
settings:
|
||||
size: 60
|
||||
placeholder: ''
|
||||
third_party_settings: { }
|
||||
uid:
|
||||
type: entity_reference_autocomplete
|
||||
weight: 5
|
||||
settings:
|
||||
match_operator: CONTAINS
|
||||
size: 60
|
||||
placeholder: ''
|
||||
third_party_settings: { }
|
||||
hidden: { }
|
|
@ -0,0 +1,18 @@
|
|||
langcode: en
|
||||
status: true
|
||||
dependencies:
|
||||
config:
|
||||
- field.field.node.ctools_block_field_test.body
|
||||
- node.type.ctools_block_field_test
|
||||
module:
|
||||
- user
|
||||
_core:
|
||||
default_config_hash: clNnyw6fhh5SwIme5I_3zjbLv-PMfpY-JXofVAC3CV8
|
||||
id: node.ctools_block_field_test.default
|
||||
targetEntityType: node
|
||||
bundle: ctools_block_field_test
|
||||
mode: default
|
||||
content: { }
|
||||
hidden:
|
||||
body: true
|
||||
links: true
|
|
@ -0,0 +1,27 @@
|
|||
langcode: en
|
||||
status: true
|
||||
dependencies:
|
||||
config:
|
||||
- core.entity_view_mode.node.teaser
|
||||
- field.field.node.ctools_block_field_test.body
|
||||
- node.type.ctools_block_field_test
|
||||
module:
|
||||
- text
|
||||
- user
|
||||
_core:
|
||||
default_config_hash: gQV5baI7pCIOBUtLkbJ1c2WJwM8CdlKiKOtLLIWnfy0
|
||||
id: node.ctools_block_field_test.teaser
|
||||
targetEntityType: node
|
||||
bundle: ctools_block_field_test
|
||||
mode: teaser
|
||||
content:
|
||||
body:
|
||||
label: hidden
|
||||
type: text_summary_or_trimmed
|
||||
weight: 101
|
||||
settings:
|
||||
trim_length: 600
|
||||
third_party_settings: { }
|
||||
links:
|
||||
weight: 100
|
||||
hidden: { }
|
|
@ -0,0 +1,23 @@
|
|||
langcode: en
|
||||
status: true
|
||||
dependencies:
|
||||
config:
|
||||
- field.storage.node.body
|
||||
- node.type.ctools_block_field_test
|
||||
module:
|
||||
- text
|
||||
_core:
|
||||
default_config_hash: fzUnwtwftRsgKExjpF6XdMqbUzP16ytkjQniBZl1Hqg
|
||||
id: node.ctools_block_field_test.body
|
||||
field_name: body
|
||||
entity_type: node
|
||||
bundle: ctools_block_field_test
|
||||
label: Body
|
||||
description: ''
|
||||
required: false
|
||||
translatable: true
|
||||
default_value: { }
|
||||
default_value_callback: ''
|
||||
settings:
|
||||
display_summary: true
|
||||
field_type: text_with_summary
|
|
@ -0,0 +1,37 @@
|
|||
langcode: en
|
||||
status: true
|
||||
dependencies:
|
||||
config:
|
||||
- field.storage.node.field_image
|
||||
- node.type.ctools_block_field_test
|
||||
module:
|
||||
- image
|
||||
id: node.ctools_block_field_test.field_image
|
||||
field_name: field_image
|
||||
entity_type: node
|
||||
bundle: ctools_block_field_test
|
||||
label: Image
|
||||
description: ''
|
||||
required: false
|
||||
translatable: true
|
||||
default_value: { }
|
||||
default_value_callback: ''
|
||||
settings:
|
||||
file_directory: '[date:custom:Y]-[date:custom:m]'
|
||||
file_extensions: 'png gif jpg jpeg'
|
||||
max_filesize: ''
|
||||
max_resolution: ''
|
||||
min_resolution: ''
|
||||
alt_field: true
|
||||
title_field: false
|
||||
alt_field_required: true
|
||||
title_field_required: false
|
||||
default_image:
|
||||
uuid: null
|
||||
alt: ''
|
||||
title: ''
|
||||
width: null
|
||||
height: null
|
||||
handler: 'default:file'
|
||||
handler_settings: { }
|
||||
field_type: image
|
|
@ -0,0 +1,31 @@
|
|||
langcode: en
|
||||
status: true
|
||||
dependencies:
|
||||
module:
|
||||
- file
|
||||
- image
|
||||
- node
|
||||
id: node.field_image
|
||||
field_name: field_image
|
||||
entity_type: node
|
||||
type: image
|
||||
settings:
|
||||
uri_scheme: public
|
||||
default_image:
|
||||
uuid: null
|
||||
alt: ''
|
||||
title: ''
|
||||
width: null
|
||||
height: null
|
||||
target_type: file
|
||||
display_field: false
|
||||
display_default: false
|
||||
module: image
|
||||
locked: false
|
||||
cardinality: 1
|
||||
translatable: true
|
||||
indexes:
|
||||
target_id:
|
||||
- target_id
|
||||
persist_with_no_fields: false
|
||||
custom_storage: false
|
|
@ -0,0 +1,18 @@
|
|||
langcode: en
|
||||
status: true
|
||||
dependencies:
|
||||
module:
|
||||
- menu_ui
|
||||
third_party_settings:
|
||||
menu_ui:
|
||||
available_menus: { }
|
||||
parent: ''
|
||||
_core:
|
||||
default_config_hash: hjC271ZF6B5XYgF6-F5Ak73sJiZWJRmSLsgk8S7Vo-8
|
||||
name: 'CTools block field test'
|
||||
type: ctools_block_field_test
|
||||
description: 'A content type used for the ctools_block field tests.'
|
||||
help: ''
|
||||
new_revision: false
|
||||
preview_mode: 0
|
||||
display_submitted: false
|
|
@ -0,0 +1,18 @@
|
|||
name: 'Chaos Tools Blocks Test'
|
||||
type: module
|
||||
description: 'Support module for Chaos Tools Blocks Tests.'
|
||||
package: Testing
|
||||
# version: 8.0.1
|
||||
dependencies:
|
||||
- drupal:image
|
||||
- drupal:menu_ui
|
||||
- drupal:node
|
||||
- drupal:path
|
||||
- drupal:text
|
||||
- drupal:user
|
||||
features: true
|
||||
|
||||
# Information added by Drupal.org packaging script on 2021-06-16
|
||||
version: '8.x-3.7'
|
||||
project: 'ctools'
|
||||
datestamp: 1623822132
|
|
@ -0,0 +1,139 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\ctools_block\Functional;
|
||||
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
|
||||
/**
|
||||
* Tests the entity field block.
|
||||
*
|
||||
* @group ctools_block
|
||||
*/
|
||||
class EntityFieldBlockTest extends BrowserTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['block', 'ctools_block', 'ctools_block_field_test'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected $defaultTheme = 'stark';
|
||||
|
||||
/**
|
||||
* Tests using the node body field in a block.
|
||||
*/
|
||||
public function testBodyField() {
|
||||
$block = $this->drupalPlaceBlock('entity_field:node:body', [
|
||||
'formatter' => [
|
||||
'type' => 'text_default',
|
||||
],
|
||||
'context_mapping' => [
|
||||
'entity' => '@node.node_route_context:node',
|
||||
],
|
||||
]);
|
||||
$node = $this->drupalCreateNode(['type' => 'ctools_block_field_test']);
|
||||
$this->drupalGet('node/' . $node->id());
|
||||
$assert = $this->assertSession();
|
||||
$assert->pageTextContains($block->label());
|
||||
$assert->pageTextContains($node->body->value);
|
||||
|
||||
$node->set('body', NULL)->save();
|
||||
$this->getSession()->reload();
|
||||
// The block should not appear if there is no value in the field.
|
||||
$assert->pageTextNotContains($block->label());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that empty image fields will still render their default value.
|
||||
*/
|
||||
public function testEmptyImageField() {
|
||||
$entityTypeManager = $this->container->get('entity_type.manager');
|
||||
$source = $this->container->get('module_handler')->getModule('image')->getPath() . '/sample.png';
|
||||
|
||||
/** @var \Drupal\Core\File\FileSystemInterface $file_system */
|
||||
$file_system = $this->container->get('file_system');
|
||||
$file_system->copy($source, 'public://sample.png');
|
||||
|
||||
/** @var \Drupal\file\FileInterface $file */
|
||||
$file = $entityTypeManager->getStorage('file')
|
||||
->create([
|
||||
'uri' => 'public://sample.png',
|
||||
]);
|
||||
$file->save();
|
||||
|
||||
/** @var \Drupal\field\FieldConfigInterface $field */
|
||||
$field = $entityTypeManager->getStorage('field_config')
|
||||
->load('node.ctools_block_field_test.field_image');
|
||||
$settings = $field->getSettings();
|
||||
$settings['default_image']['uuid'] = $file->uuid();
|
||||
$field->set('settings', $settings)->save();
|
||||
|
||||
$this->drupalPlaceBlock('entity_field:node:field_image', [
|
||||
'formatter' => [
|
||||
'type' => 'image_image',
|
||||
],
|
||||
'context_mapping' => [
|
||||
'entity' => '@node.node_route_context:node',
|
||||
],
|
||||
]);
|
||||
|
||||
$node = $this->drupalCreateNode(['type' => 'ctools_block_field_test']);
|
||||
$this->drupalGet('node/' . $node->id());
|
||||
|
||||
$url = $file->getFileUri();
|
||||
$url = file_create_url($url);
|
||||
$url = file_url_transform_relative($url);
|
||||
$this->assertSession()->responseContains('src="' . $url . '"');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests using the node uid base field in a block.
|
||||
*/
|
||||
public function testNodeBaseFields() {
|
||||
$block = $this->drupalPlaceBlock('entity_field:node:title', [
|
||||
'formatter' => [
|
||||
'type' => 'string',
|
||||
],
|
||||
'context_mapping' => [
|
||||
'entity' => '@node.node_route_context:node',
|
||||
],
|
||||
]);
|
||||
$node = $this->drupalCreateNode(['type' => 'ctools_block_field_test', 'uid' => 1]);
|
||||
$this->drupalGet('node/' . $node->id());
|
||||
$assert = $this->assertSession();
|
||||
$assert->pageTextContains($block->label());
|
||||
$assert->pageTextContains($node->getTitle());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that we are setting the render cache metadata correctly.
|
||||
*/
|
||||
public function testRenderCache() {
|
||||
$this->drupalPlaceBlock('entity_field:node:body', [
|
||||
'formatter' => [
|
||||
'type' => 'text_default',
|
||||
],
|
||||
'context_mapping' => [
|
||||
'entity' => '@node.node_route_context:node',
|
||||
],
|
||||
]);
|
||||
$a = $this->drupalCreateNode(['type' => 'ctools_block_field_test']);
|
||||
$b = $this->drupalCreateNode(['type' => 'ctools_block_field_test']);
|
||||
|
||||
$assert = $this->assertSession();
|
||||
$this->drupalGet('node/' . $a->id());
|
||||
$assert->pageTextContains($a->body->value);
|
||||
$this->drupalGet('node/' . $b->id());
|
||||
$assert->pageTextNotContains($a->body->value);
|
||||
$assert->pageTextContains($b->body->value);
|
||||
|
||||
$text = 'This is my text. Are you not entertained?';
|
||||
$a->body->value = $text;
|
||||
$a->save();
|
||||
$this->drupalGet('node/' . $a->id());
|
||||
$assert->pageTextContains($text);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
name: 'Entity Mask'
|
||||
core_version_requirement: ^8.8 || ^9
|
||||
type: module
|
||||
description: 'Allows an entity type to borrow the fields and display configuration of another entity type.'
|
||||
|
||||
# Information added by Drupal.org packaging script on 2021-06-16
|
||||
version: '8.x-3.7'
|
||||
project: 'ctools'
|
||||
datestamp: 1623822132
|
|
@ -0,0 +1,194 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Helps entity type to take the fields, display configuration from entity type.
|
||||
*/
|
||||
|
||||
use Drupal\Core\Entity\Display\EntityDisplayInterface;
|
||||
use Drupal\Core\Entity\Display\EntityFormDisplayInterface;
|
||||
use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
|
||||
use Drupal\Core\Entity\EntityTypeInterface;
|
||||
use Drupal\Core\Entity\Sql\SqlContentEntityStorage;
|
||||
use Drupal\ctools_entity_mask\MaskContentEntityStorage;
|
||||
|
||||
/**
|
||||
* Ensures that mask entity types have the same display modes as masked ones.
|
||||
*
|
||||
* @param array $display_modes
|
||||
* The display modes.
|
||||
*
|
||||
* @see hook_entity_view_mode_info_alter()
|
||||
* @see \Drupal\Core\Entity\EntityDisplayRepository::getAllDisplayModesByEntityType()
|
||||
*/
|
||||
function ctools_entity_mask_copy_display_modes(array &$display_modes) {
|
||||
foreach (\Drupal::entityTypeManager()->getDefinitions() as $id => $entity_type) {
|
||||
$mask = $entity_type->get('mask');
|
||||
|
||||
if ($mask && isset($display_modes[$mask])) {
|
||||
$display_modes[$id] = $display_modes[$mask];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_entity_view_mode_info_alter().
|
||||
*/
|
||||
function ctools_entity_mask_entity_view_mode_info_alter(&$view_modes) {
|
||||
ctools_entity_mask_copy_display_modes($view_modes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_entity_form_mode_info_alter().
|
||||
*/
|
||||
function ctools_entity_mask_entity_form_mode_info_alter(&$form_modes) {
|
||||
ctools_entity_mask_copy_display_modes($form_modes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_entity_type_alter().
|
||||
*/
|
||||
function ctools_entity_mask_entity_type_alter(array &$entity_types) {
|
||||
/** @var \Drupal\Core\Entity\EntityTypeInterface $entity_type */
|
||||
foreach ($entity_types as $entity_type) {
|
||||
// Mask entities should use our specialized storage handler, which simulates
|
||||
// a save but does not write anything to the database.
|
||||
if ($entity_type->get('mask') && $entity_type->getStorageClass() == SqlContentEntityStorage::class) {
|
||||
$entity_type->setStorageClass(MaskContentEntityStorage::class);
|
||||
// Mask entities should not maintain any tables.
|
||||
$entity_type->set('base_table', NULL);
|
||||
$entity_type->set('revision_table', NULL);
|
||||
$entity_type->set('data_table', NULL);
|
||||
$entity_type->set('revision_data_table', NULL);
|
||||
|
||||
// Nor should they be exposed to Field UI.
|
||||
$entity_type->set('field_ui_base_route', NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies all components from a display for a masked entity type.
|
||||
*
|
||||
* If the given display is for a mask entity type, the corresponding display for
|
||||
* the masked entity type is loaded and all of its components are copied into
|
||||
* the given display. If no corresponding display exists for the masked entity
|
||||
* type, the default display will be loaded and used.
|
||||
*
|
||||
* @param \Drupal\Core\Entity\Display\EntityDisplayInterface $display
|
||||
* The display for the mask entity type.
|
||||
*/
|
||||
function ctools_entity_mask_copy_display(EntityDisplayInterface $display) {
|
||||
$mask = \Drupal::entityTypeManager()
|
||||
->getDefinition($display->getTargetEntityTypeId())
|
||||
->get('mask');
|
||||
|
||||
// If the target entity type is not masking another entity type, there is
|
||||
// nothing to do here.
|
||||
if (empty($mask)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Try to load the corresponding entity display for the masked entity type,
|
||||
// in descending order of preference.
|
||||
$bundle = $display->getTargetBundle();
|
||||
$displays = $display::loadMultiple([
|
||||
$mask . '.' . $bundle . '.' . $display->getMode(),
|
||||
$mask . '.' . $bundle . '.default',
|
||||
]);
|
||||
|
||||
// Nothing to do if there is no display we can borrow components from.
|
||||
if (empty($displays)) {
|
||||
return;
|
||||
}
|
||||
foreach (reset($displays)->getComponents() as $key => $component) {
|
||||
$display->setComponent($key, $component);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_ENTITY_TYPE_create().
|
||||
*/
|
||||
function ctools_entity_mask_entity_view_display_create(EntityViewDisplayInterface $display) {
|
||||
ctools_entity_mask_copy_display($display);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_ENTITY_TYPE_create().
|
||||
*/
|
||||
function ctools_entity_mask_entity_form_display_create(EntityFormDisplayInterface $display) {
|
||||
ctools_entity_mask_copy_display($display);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_entity_view_display_alter().
|
||||
*/
|
||||
function ctools_entity_mask_entity_view_display_alter(EntityViewDisplayInterface $display, array $context) {
|
||||
ctools_entity_mask_copy_display($display);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_entity_form_display_alter().
|
||||
*/
|
||||
function ctools_entity_mask_entity_form_display_alter(EntityFormDisplayInterface $form_display, array $context) {
|
||||
ctools_entity_mask_copy_display($form_display);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_entity_bundle_field_info().
|
||||
*/
|
||||
function ctools_entity_mask_entity_bundle_field_info(EntityTypeInterface $entity_type, $bundle) {
|
||||
$info = [];
|
||||
|
||||
$mask = $entity_type->get('mask');
|
||||
// Nothing to do if the entity type is not masking another entity type.
|
||||
if (empty($mask)) {
|
||||
return $info;
|
||||
}
|
||||
|
||||
$storage_info = ctools_entity_mask_entity_field_storage_info($entity_type);
|
||||
|
||||
/** @var \Drupal\field\FieldConfigInterface[] $fields */
|
||||
$fields = \Drupal::entityTypeManager()
|
||||
->getStorage('field_config')
|
||||
->loadByProperties([
|
||||
'entity_type' => $mask,
|
||||
'bundle' => $bundle,
|
||||
]);
|
||||
|
||||
foreach ($fields as $field) {
|
||||
$field_name = $field->getName();
|
||||
|
||||
$info[$field_name] = $field
|
||||
->createDuplicate()
|
||||
->set('entity_type', $mask)
|
||||
->set('fieldStorage', $storage_info[$field_name]);
|
||||
}
|
||||
return $info;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_entity_field_storage_info().
|
||||
*/
|
||||
function ctools_entity_mask_entity_field_storage_info(EntityTypeInterface $entity_type) {
|
||||
$info = [];
|
||||
|
||||
$mask = $entity_type->get('mask');
|
||||
// Nothing to do if the entity type is not masking another entity type.
|
||||
if (empty($mask)) {
|
||||
return $info;
|
||||
}
|
||||
|
||||
/** @var \Drupal\field\FieldStorageConfigInterface[] $fields */
|
||||
$fields = \Drupal::entityTypeManager()
|
||||
->getStorage('field_storage_config')
|
||||
->loadByProperties([
|
||||
'entity_type' => $mask,
|
||||
]);
|
||||
|
||||
foreach ($fields as $field) {
|
||||
$field_name = $field->getName();
|
||||
$info[$field_name] = $field->createDuplicate()->set('entity_type', $mask);
|
||||
}
|
||||
return $info;
|
||||
}
|
|
@ -0,0 +1,88 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\ctools_entity_mask;
|
||||
|
||||
use Drupal\Core\Entity\ContentEntityInterface;
|
||||
use Drupal\Core\Entity\ContentEntityStorageBase;
|
||||
use Drupal\Core\Entity\EntityInterface;
|
||||
use Drupal\Core\Field\FieldDefinitionInterface;
|
||||
|
||||
/**
|
||||
* Storage handler that simulates a full save, without writing to the database.
|
||||
*/
|
||||
class MaskContentEntityStorage extends ContentEntityStorageBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function readFieldItemsToPurge(FieldDefinitionInterface $field_definition, $batch_size) {
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function purgeFieldItems(ContentEntityInterface $entity, FieldDefinitionInterface $field_definition) {
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doLoadRevisionFieldItems($revision_id) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doSaveFieldItems(ContentEntityInterface $entity, array $names = []) {
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doDeleteFieldItems($entities) {
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doDeleteRevisionFieldItems(ContentEntityInterface $revision) {
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doLoadMultiple(array $ids = NULL) {
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function has($id, EntityInterface $entity) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getQueryServiceName() {
|
||||
return 'entity.query.null';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function countFieldData($storage_definition, $as_bool = FALSE) {
|
||||
return $as_bool ? FALSE : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doLoadMultipleRevisionsFieldItems($revision_ids) {
|
||||
return [];
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\ctools_entity_mask;
|
||||
|
||||
/**
|
||||
* Provides common functionality for mask entities.
|
||||
*/
|
||||
trait MaskEntityTrait {
|
||||
|
||||
/**
|
||||
* Implements \Drupal\Core\Entity\EntityInterface::id().
|
||||
*
|
||||
* Mask entities are generally not saved to the database like standard content
|
||||
* entities, so it cannot be assumed that they will have a serial ID at any
|
||||
* point in their lives. However, Drupal still expects all entities to have an
|
||||
* identifier of some kind, so this dual-purposes the UUID as the canonical
|
||||
* entity ID. (It would be nice if core did this as a rule for all entities
|
||||
* and stopped using serial IDs, but, y'know, baby steps.)
|
||||
*
|
||||
* @return string
|
||||
* Returns the UUID of the Entity.
|
||||
*/
|
||||
public function id() {
|
||||
return $this->uuid();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
langcode: en
|
||||
status: true
|
||||
dependencies: { }
|
||||
id: basic
|
||||
label: 'Basic block'
|
||||
revision: 0
|
||||
description: 'A basic block contains a title and a body.'
|
|
@ -0,0 +1,52 @@
|
|||
langcode: en
|
||||
status: true
|
||||
dependencies:
|
||||
config:
|
||||
- block_content.type.basic
|
||||
- field.field.block_content.basic.body
|
||||
- field.field.block_content.basic.field_image
|
||||
- field.field.block_content.basic.field_link
|
||||
- image.style.thumbnail
|
||||
module:
|
||||
- image
|
||||
- link
|
||||
- text
|
||||
id: block_content.basic.default
|
||||
targetEntityType: block_content
|
||||
bundle: basic
|
||||
mode: default
|
||||
content:
|
||||
body:
|
||||
type: text_textarea_with_summary
|
||||
weight: 1
|
||||
settings:
|
||||
rows: 9
|
||||
summary_rows: 3
|
||||
placeholder: ''
|
||||
third_party_settings: { }
|
||||
region: content
|
||||
field_image:
|
||||
type: image_image
|
||||
weight: 3
|
||||
settings:
|
||||
preview_image_style: thumbnail
|
||||
progress_indicator: throbber
|
||||
third_party_settings: { }
|
||||
region: content
|
||||
field_link:
|
||||
weight: 2
|
||||
settings:
|
||||
placeholder_url: ''
|
||||
placeholder_title: ''
|
||||
third_party_settings: { }
|
||||
type: link_default
|
||||
region: content
|
||||
info:
|
||||
type: string_textfield
|
||||
weight: 0
|
||||
settings:
|
||||
size: 60
|
||||
placeholder: ''
|
||||
third_party_settings: { }
|
||||
region: content
|
||||
hidden: { }
|
|
@ -0,0 +1,46 @@
|
|||
langcode: en
|
||||
status: true
|
||||
dependencies:
|
||||
config:
|
||||
- block_content.type.basic
|
||||
- field.field.block_content.basic.body
|
||||
- field.field.block_content.basic.field_image
|
||||
- field.field.block_content.basic.field_link
|
||||
module:
|
||||
- image
|
||||
- link
|
||||
- text
|
||||
id: block_content.basic.default
|
||||
targetEntityType: block_content
|
||||
bundle: basic
|
||||
mode: default
|
||||
content:
|
||||
body:
|
||||
type: text_default
|
||||
weight: 0
|
||||
label: hidden
|
||||
settings: { }
|
||||
third_party_settings: { }
|
||||
region: content
|
||||
field_image:
|
||||
weight: 2
|
||||
label: above
|
||||
settings:
|
||||
image_style: ''
|
||||
image_link: ''
|
||||
third_party_settings: { }
|
||||
type: image
|
||||
region: content
|
||||
field_link:
|
||||
weight: 1
|
||||
label: above
|
||||
settings:
|
||||
trim_length: 80
|
||||
url_only: false
|
||||
url_plain: false
|
||||
rel: ''
|
||||
target: ''
|
||||
third_party_settings: { }
|
||||
type: link
|
||||
region: content
|
||||
hidden: { }
|
|
@ -0,0 +1,21 @@
|
|||
langcode: en
|
||||
status: true
|
||||
dependencies:
|
||||
config:
|
||||
- block_content.type.basic
|
||||
- field.storage.block_content.body
|
||||
module:
|
||||
- text
|
||||
id: block_content.basic.body
|
||||
field_name: body
|
||||
entity_type: block_content
|
||||
bundle: basic
|
||||
label: Body
|
||||
description: ''
|
||||
required: false
|
||||
translatable: true
|
||||
default_value: { }
|
||||
default_value_callback: ''
|
||||
settings:
|
||||
display_summary: false
|
||||
field_type: text_with_summary
|
|
@ -0,0 +1,37 @@
|
|||
langcode: en
|
||||
status: true
|
||||
dependencies:
|
||||
config:
|
||||
- block_content.type.basic
|
||||
- field.storage.block_content.field_image
|
||||
module:
|
||||
- image
|
||||
id: block_content.basic.field_image
|
||||
field_name: field_image
|
||||
entity_type: block_content
|
||||
bundle: basic
|
||||
label: Image
|
||||
description: ''
|
||||
required: false
|
||||
translatable: false
|
||||
default_value: { }
|
||||
default_value_callback: ''
|
||||
settings:
|
||||
file_directory: '[date:custom:Y]-[date:custom:m]'
|
||||
file_extensions: 'png gif jpg jpeg'
|
||||
max_filesize: ''
|
||||
max_resolution: ''
|
||||
min_resolution: ''
|
||||
alt_field: true
|
||||
alt_field_required: true
|
||||
title_field: false
|
||||
title_field_required: false
|
||||
default_image:
|
||||
uuid: ''
|
||||
alt: ''
|
||||
title: ''
|
||||
width: null
|
||||
height: null
|
||||
handler: 'default:file'
|
||||
handler_settings: { }
|
||||
field_type: image
|
|
@ -0,0 +1,22 @@
|
|||
langcode: en
|
||||
status: true
|
||||
dependencies:
|
||||
config:
|
||||
- block_content.type.basic
|
||||
- field.storage.block_content.field_link
|
||||
module:
|
||||
- link
|
||||
id: block_content.basic.field_link
|
||||
field_name: field_link
|
||||
entity_type: block_content
|
||||
bundle: basic
|
||||
label: Link
|
||||
description: ''
|
||||
required: false
|
||||
translatable: false
|
||||
default_value: { }
|
||||
default_value_callback: ''
|
||||
settings:
|
||||
link_type: 17
|
||||
title: 1
|
||||
field_type: link
|
|
@ -0,0 +1,29 @@
|
|||
langcode: en
|
||||
status: true
|
||||
dependencies:
|
||||
module:
|
||||
- block_content
|
||||
- file
|
||||
- image
|
||||
id: block_content.field_image
|
||||
field_name: field_image
|
||||
entity_type: block_content
|
||||
type: image
|
||||
settings:
|
||||
uri_scheme: public
|
||||
default_image:
|
||||
uuid: ''
|
||||
alt: ''
|
||||
title: ''
|
||||
width: null
|
||||
height: null
|
||||
target_type: file
|
||||
display_field: false
|
||||
display_default: false
|
||||
module: image
|
||||
locked: false
|
||||
cardinality: 1
|
||||
translatable: true
|
||||
indexes: { }
|
||||
persist_with_no_fields: false
|
||||
custom_storage: false
|
|
@ -0,0 +1,18 @@
|
|||
langcode: en
|
||||
status: true
|
||||
dependencies:
|
||||
module:
|
||||
- block_content
|
||||
- link
|
||||
id: block_content.field_link
|
||||
field_name: field_link
|
||||
entity_type: block_content
|
||||
type: link
|
||||
settings: { }
|
||||
module: link
|
||||
locked: false
|
||||
cardinality: 1
|
||||
translatable: true
|
||||
indexes: { }
|
||||
persist_with_no_fields: false
|
||||
custom_storage: false
|
|
@ -0,0 +1,13 @@
|
|||
name: 'Entity Mask test'
|
||||
type: module
|
||||
package: Testing
|
||||
dependencies:
|
||||
- drupal:block_content
|
||||
- ctools_entity_mask:ctools_entity_mask
|
||||
- drupal:image
|
||||
- drupal:text
|
||||
|
||||
# Information added by Drupal.org packaging script on 2021-06-16
|
||||
version: '8.x-3.7'
|
||||
project: 'ctools'
|
||||
datestamp: 1623822132
|
|
@ -0,0 +1,9 @@
|
|||
fake_block_content.add_form:
|
||||
path: '/fake-block/add/{block_content_type}'
|
||||
defaults:
|
||||
_controller: '\Drupal\block_content\Controller\BlockContentController::addForm'
|
||||
_title_callback: 'Drupal\block_content\Controller\BlockContentController::getAddFormTitle'
|
||||
options:
|
||||
_admin_route: TRUE
|
||||
requirements:
|
||||
_permission: 'administer blocks'
|
|
@ -0,0 +1,70 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\entity_mask_test\Entity;
|
||||
|
||||
use Drupal\block_content\Entity\BlockContent as BaseBlockContent;
|
||||
use Drupal\ctools_entity_mask\MaskEntityTrait;
|
||||
|
||||
/**
|
||||
* Provides a masked version of BlockContent.
|
||||
*
|
||||
* @todo Investigate a better way to copy the upstream properties instead of
|
||||
* manually duplicating them.
|
||||
*
|
||||
* @ContentEntityType(
|
||||
* id = "fake_block_content",
|
||||
* label = @Translation("Custom block"),
|
||||
* bundle_label = @Translation("Custom block type"),
|
||||
* handlers = {
|
||||
* "storage" = "Drupal\Core\Entity\Sql\SqlContentEntityStorage",
|
||||
* "access" = "Drupal\block_content\BlockContentAccessControlHandler",
|
||||
* "list_builder" = "Drupal\block_content\BlockContentListBuilder",
|
||||
* "view_builder" = "Drupal\block_content\BlockContentViewBuilder",
|
||||
* "views_data" = "Drupal\block_content\BlockContentViewsData",
|
||||
* "form" = {
|
||||
* "add" = "Drupal\block_content\BlockContentForm",
|
||||
* "edit" = "Drupal\block_content\BlockContentForm",
|
||||
* "delete" = "Drupal\block_content\Form\BlockContentDeleteForm",
|
||||
* "default" = "Drupal\block_content\BlockContentForm"
|
||||
* },
|
||||
* "translation" = "Drupal\block_content\BlockContentTranslationHandler"
|
||||
* },
|
||||
* admin_permission = "administer blocks",
|
||||
* base_table = "block_content",
|
||||
* revision_table = "block_content_revision",
|
||||
* data_table = "block_content_field_data",
|
||||
* revision_data_table = "block_content_field_revision",
|
||||
* show_revision_ui = TRUE,
|
||||
* links = {
|
||||
* "canonical" = "/block/{block_content}",
|
||||
* "delete-form" = "/block/{block_content}/delete",
|
||||
* "edit-form" = "/block/{block_content}",
|
||||
* "collection" = "/admin/structure/block/block-content",
|
||||
* "create" = "/block",
|
||||
* },
|
||||
* translatable = TRUE,
|
||||
* entity_keys = {
|
||||
* "id" = "id",
|
||||
* "revision" = "revision_id",
|
||||
* "bundle" = "type",
|
||||
* "label" = "info",
|
||||
* "langcode" = "langcode",
|
||||
* "uuid" = "uuid",
|
||||
* "published" = "status",
|
||||
* },
|
||||
* revision_metadata_keys = {
|
||||
* "revision_user" = "revision_user",
|
||||
* "revision_created" = "revision_created",
|
||||
* "revision_log_message" = "revision_log"
|
||||
* },
|
||||
* bundle_entity_type = "block_content_type",
|
||||
* field_ui_base_route = "entity.block_content_type.edit_form",
|
||||
* render_cache = FALSE,
|
||||
* mask = "block_content",
|
||||
* )
|
||||
*/
|
||||
class BlockContent extends BaseBlockContent {
|
||||
|
||||
use MaskEntityTrait;
|
||||
|
||||
}
|
|
@ -0,0 +1,121 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\ctools_entity_mask\Functional;
|
||||
|
||||
use Drupal\entity_mask_test\Entity\BlockContent;
|
||||
use Drupal\file\Entity\File;
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
|
||||
/**
|
||||
* Class DisplayTest.
|
||||
*
|
||||
* @group ctools_entity_mask
|
||||
*/
|
||||
class DisplayTest extends BrowserTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected $defaultTheme = 'stark';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = [
|
||||
'block',
|
||||
'block_content',
|
||||
'ctools_entity_mask',
|
||||
'entity_mask_test',
|
||||
'field',
|
||||
'field_ui',
|
||||
'file',
|
||||
'image',
|
||||
'link',
|
||||
'system',
|
||||
'text',
|
||||
'user',
|
||||
];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$account = $this->drupalCreateUser(['administer blocks']);
|
||||
$this->drupalLogin($account);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that the form display for a masked entity replicates its source.
|
||||
*/
|
||||
public function testFormDisplay() {
|
||||
$assert = $this->assertSession();
|
||||
|
||||
$this->drupalGet('/fake-block/add/basic');
|
||||
$assert->statusCodeEquals(200);
|
||||
$assert->fieldExists('Body');
|
||||
$assert->fieldExists('Link');
|
||||
$assert->fieldExists('Image');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that the view display for a masked entity replicates its source.
|
||||
*/
|
||||
public function testViewDisplay() {
|
||||
// Generate a random image for the image field, since that can potentially
|
||||
// be tricky.
|
||||
$image_uri = uniqid('public://') . '.png';
|
||||
$image_uri = $this->getRandomGenerator()->image($image_uri, '100x100', '200x200');
|
||||
$image = File::create(['uri' => $image_uri]);
|
||||
$image->save();
|
||||
|
||||
$body = 'Qui animated corpse, cricket bat max brucks terribilem incessu zomby.';
|
||||
$link = 'https://www.drupal.org/project/ctools';
|
||||
|
||||
$block = BlockContent::create([
|
||||
'type' => 'basic',
|
||||
'body' => $body,
|
||||
'field_link' => $link,
|
||||
'field_image' => $image,
|
||||
]);
|
||||
$block->save();
|
||||
|
||||
// Ensure that the entity is intact after serialization and deserialization,
|
||||
// since that may prove to be a common storage mechanism for mask entities.
|
||||
$block = serialize($block);
|
||||
$block = unserialize($block);
|
||||
|
||||
$this->assertSame($body, $block->body->value);
|
||||
$this->assertSame($link, $block->field_link->uri);
|
||||
$this->assertSame($image_uri, $block->field_image->entity->getFileUri());
|
||||
|
||||
$build = $this->container->get('entity_type.manager')
|
||||
->getViewBuilder('fake_block_content')
|
||||
->view($block);
|
||||
|
||||
// If the fields are not in the renderable array, something has gone awry.
|
||||
$this->assertArrayHasKey('body', $build);
|
||||
$this->assertArrayHasKey('field_link', $build);
|
||||
$this->assertArrayHasKey('field_image', $build);
|
||||
|
||||
// Render the block and check the output too, just to be sure.
|
||||
$rendered = $this->container->get('renderer')->renderRoot($build);
|
||||
$rendered = (string) $rendered;
|
||||
|
||||
// @todo Use assertStringContainsString() when we rely exclusively on
|
||||
// PHPUnit 8.
|
||||
$this->assertNotFalse(strpos($rendered, $block->body->value));
|
||||
$this->assertNotFalse(strpos($rendered, $block->field_link->uri));
|
||||
|
||||
$image_url = $block->field_image->entity->getFileUri();
|
||||
$image_url = file_create_url($image_url);
|
||||
// file_create_url() will include the host and port, but the rendered output
|
||||
// won't include those.
|
||||
$image_url = file_url_transform_relative($image_url);
|
||||
// @todo Use assertStringContainsString() when we rely exclusively on
|
||||
// PHPUnit 8.
|
||||
$this->assertNotFalse(strpos($rendered, $image_url));
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,235 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\ctools_entity_mask\Kernel;
|
||||
|
||||
use Drupal\Core\Entity\Entity\EntityFormMode;
|
||||
use Drupal\entity_mask_test\Entity\BlockContent;
|
||||
use Drupal\KernelTests\KernelTestBase;
|
||||
|
||||
/**
|
||||
* Basic test of entity type masking.
|
||||
*
|
||||
* @group ctools_entity_mask
|
||||
*/
|
||||
class EntityMaskTest extends KernelTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = [
|
||||
'block',
|
||||
'block_content',
|
||||
'ctools_entity_mask',
|
||||
'entity_mask_test',
|
||||
'field',
|
||||
'field_ui',
|
||||
'file',
|
||||
'image',
|
||||
'link',
|
||||
'system',
|
||||
'text',
|
||||
'user',
|
||||
];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->installConfig(['block_content', 'entity_mask_test']);
|
||||
$this->installEntitySchema('fake_block_content');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that fields are correctly masked.
|
||||
*/
|
||||
public function testFields() {
|
||||
$block = BlockContent::create([
|
||||
'type' => 'basic',
|
||||
]);
|
||||
|
||||
$this->assertTrue($block->hasField('body'));
|
||||
$this->assertTrue($block->hasField('field_link'));
|
||||
$this->assertTrue($block->hasField('field_image'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that entity view displays are correctly masked.
|
||||
*/
|
||||
public function testViewDisplays() {
|
||||
$view_modes = $this->container
|
||||
->get('entity_display.repository')
|
||||
->getAllViewModes();
|
||||
$this->assertSame($view_modes['block_content'], $view_modes['fake_block_content']);
|
||||
|
||||
$storage = $this->container->get('entity_type.manager')->getStorage('entity_view_display');
|
||||
$display = $storage->create([
|
||||
'targetEntityType' => 'fake_block_content',
|
||||
'bundle' => 'basic',
|
||||
'mode' => 'default',
|
||||
'status' => TRUE,
|
||||
]);
|
||||
|
||||
$this->assertTrue($display->isNew());
|
||||
|
||||
$components = $display->getComponents();
|
||||
$this->assertArrayHasKey('body', $components);
|
||||
$this->assertArrayHasKey('field_link', $components);
|
||||
$this->assertArrayHasKey('field_image', $components);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that entity form displays are correctly masked.
|
||||
*/
|
||||
public function testFormDisplays() {
|
||||
EntityFormMode::create([
|
||||
'id' => 'block_content.foobar',
|
||||
'label' => $this->randomString(),
|
||||
'targetEntityType' => 'block_content',
|
||||
])->save();
|
||||
|
||||
$form_modes = $this->container
|
||||
->get('entity_display.repository')
|
||||
->getAllFormModes();
|
||||
$this->assertSame($form_modes['block_content'], $form_modes['fake_block_content']);
|
||||
|
||||
$storage = $this->container->get('entity_type.manager')->getStorage('entity_form_display');
|
||||
$display = $storage->create([
|
||||
'targetEntityType' => 'fake_block_content',
|
||||
'bundle' => 'basic',
|
||||
'mode' => 'default',
|
||||
'status' => TRUE,
|
||||
]);
|
||||
|
||||
$this->assertTrue($display->isNew());
|
||||
|
||||
$components = $display->getComponents();
|
||||
$this->assertArrayHasKey('body', $components);
|
||||
$this->assertArrayHasKey('field_link', $components);
|
||||
$this->assertArrayHasKey('field_image', $components);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that mask entity types define no tables.
|
||||
*/
|
||||
public function testNoTables() {
|
||||
/** @var \Drupal\Core\Entity\EntityTypeInterface $entity_type */
|
||||
$entity_type = $this->container
|
||||
->get('entity_type.manager')
|
||||
->getDefinition('fake_block_content');
|
||||
|
||||
$this->assertNull($entity_type->getBaseTable());
|
||||
$this->assertNull($entity_type->getDataTable());
|
||||
$this->assertNull($entity_type->getRevisionTable());
|
||||
$this->assertNull($entity_type->getRevisionDataTable());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that mask entity types are not exposed to Field UI.
|
||||
*/
|
||||
public function testNotExposedToFieldUI() {
|
||||
/** @var \Drupal\Core\Entity\EntityTypeInterface $entity_type */
|
||||
$entity_type = $this->container
|
||||
->get('entity_type.manager')
|
||||
->getDefinition('fake_block_content');
|
||||
|
||||
$this->assertNull($entity_type->get('field_ui_base_route'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that a mask entity can be serialized and de-serialized coherently.
|
||||
*
|
||||
* @depends testFields
|
||||
*/
|
||||
public function testSerialization() {
|
||||
$body = $this->getRandomGenerator()->paragraphs(2);
|
||||
$link = 'https://www.drupal.org/project/ctools';
|
||||
|
||||
/** @var \Drupal\Core\Entity\EntityInterface $block */
|
||||
$block = BlockContent::create([
|
||||
'type' => 'basic',
|
||||
'body' => $body,
|
||||
'field_link' => $link,
|
||||
]);
|
||||
|
||||
$block = serialize($block);
|
||||
$block = unserialize($block);
|
||||
|
||||
$this->assertSame($body, $block->body->value);
|
||||
$this->assertSame($link, $block->field_link->uri);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that mask entities' isNew() method behaves consistently.
|
||||
*/
|
||||
public function testIsNew() {
|
||||
$block = BlockContent::create(['type' => 'basic']);
|
||||
$this->assertTrue($block->isNew());
|
||||
$block->save();
|
||||
$this->assertFalse($block->isNew());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that mask entities' id() method returns the UUID.
|
||||
*/
|
||||
public function testId() {
|
||||
$block = BlockContent::create(['type' => 'basic']);
|
||||
$this->assertSame($block->id(), $block->uuid());
|
||||
$block->save();
|
||||
$this->assertSame($block->id(), $block->uuid());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that mask entities cannot be loaded.
|
||||
*
|
||||
* @depends testId
|
||||
*/
|
||||
public function testLoad() {
|
||||
$block = BlockContent::create(['type' => 'basic']);
|
||||
$block->save();
|
||||
|
||||
/** @var \Drupal\Core\Entity\EntityStorageInterface $storage */
|
||||
$storage = $this->container->get('entity_type.manager')->getStorage('fake_block_content');
|
||||
|
||||
$id = $block->id();
|
||||
$this->assertNull($storage->load($id));
|
||||
$this->assertEmpty($storage->loadMultiple([$id]));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that deleting a mask entity doesn't throw an exception or anything.
|
||||
*/
|
||||
public function testDelete() {
|
||||
$block = BlockContent::create(['type' => 'basic']);
|
||||
$block->save();
|
||||
|
||||
// Check we created a saved block.
|
||||
$id = $block->id();
|
||||
$this->assertNotEmpty($id);
|
||||
|
||||
$block->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that mask entities have field data after save.
|
||||
*
|
||||
* @depends testFields
|
||||
* @depends testNoTables
|
||||
*/
|
||||
public function testSave() {
|
||||
$body = $this->getRandomGenerator()->paragraphs(2);
|
||||
$link = 'https://www.drupal.org/project/ctools';
|
||||
|
||||
/** @var \Drupal\Core\Entity\EntityInterface $block */
|
||||
$block = BlockContent::create([
|
||||
'type' => 'basic',
|
||||
'body' => $body,
|
||||
'field_link' => $link,
|
||||
]);
|
||||
|
||||
// Ensure that the field values are preserved after save...
|
||||
$this->assertSame($body, $block->body->value);
|
||||
$this->assertSame($link, $block->field_link->uri);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
name: Chaos Tools Views
|
||||
type: module
|
||||
description: 'A set of improvements to the core Views code that allows for greater control over Blocks.'
|
||||
package: Chaos tool suite (Experimental)
|
||||
# version: 3.x
|
||||
core_version_requirement: ^8.8 || ^9
|
||||
dependencies:
|
||||
- drupal:block
|
||||
- drupal:views
|
||||
|
||||
# Information added by Drupal.org packaging script on 2021-06-16
|
||||
version: '8.x-3.7'
|
||||
project: 'ctools'
|
||||
datestamp: 1623822132
|
|
@ -0,0 +1,109 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Allows core Views to have greater control over Blocks.
|
||||
*/
|
||||
|
||||
use Drupal\views\Plugin\views\display\Block as CoreBlock;
|
||||
use Drupal\ctools_views\Plugin\Display\Block;
|
||||
|
||||
/**
|
||||
* Implements hook_views_plugins_display_alter().
|
||||
*/
|
||||
function ctools_views_views_plugins_display_alter(&$displays) {
|
||||
if (!empty($displays['block']['class']) && $displays['block']['class'] == CoreBlock::class) {
|
||||
$displays['block']['class'] = Block::class;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_config_schema_info_alter().
|
||||
*/
|
||||
function ctools_views_config_schema_info_alter(&$definitions) {
|
||||
// Add to the views block plugin schema.
|
||||
$definitions['views_block']['mapping']['pager'] = [
|
||||
'type' => 'string',
|
||||
'label' => 'Pager type',
|
||||
];
|
||||
$definitions['views_block']['mapping']['fields'] = [
|
||||
'type' => 'sequence',
|
||||
'label' => 'Fields settings',
|
||||
'sequence' => [
|
||||
[
|
||||
'type' => 'mapping',
|
||||
'label' => 'Field settings',
|
||||
'mapping' => [
|
||||
'hide' => [
|
||||
'type' => 'boolean',
|
||||
'label' => 'Hide field',
|
||||
],
|
||||
'weight' => [
|
||||
'type' => 'integer',
|
||||
'label' => 'Field weight',
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
$definitions['views_block']['mapping']['filter'] = [
|
||||
'type' => 'sequence',
|
||||
'label' => 'Filters settings',
|
||||
'sequence' => [
|
||||
[
|
||||
'type' => 'mapping',
|
||||
'label' => 'Filter settings',
|
||||
'mapping' => [
|
||||
'type' => [
|
||||
'type' => 'string',
|
||||
'label' => 'Plugin id',
|
||||
],
|
||||
'disable' => [
|
||||
'type' => 'boolean',
|
||||
'label' => 'Disable filter',
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
$definitions['views_block']['mapping']['sort'] = [
|
||||
'type' => 'sequence',
|
||||
'label' => 'Sort settings',
|
||||
'sequence' => [
|
||||
[
|
||||
'type' => 'string',
|
||||
'label' => 'Sort order value',
|
||||
],
|
||||
],
|
||||
];
|
||||
$definitions['views_block']['mapping']['pager_offset'] = [
|
||||
'type' => 'integer',
|
||||
'label' => 'Pager offset',
|
||||
];
|
||||
|
||||
// Add to the views block display plugin schema.
|
||||
$definitions['views.display.block']['mapping']['allow']['mapping']['offset'] = [
|
||||
'type' => 'string',
|
||||
'label' => 'Pager offset',
|
||||
];
|
||||
$definitions['views.display.block']['mapping']['allow']['mapping']['pager'] = [
|
||||
'type' => 'string',
|
||||
'label' => 'Pager type',
|
||||
];
|
||||
$definitions['views.display.block']['mapping']['allow']['mapping']['hide_fields'] = [
|
||||
'type' => 'string',
|
||||
'label' => 'Hide fields',
|
||||
];
|
||||
$definitions['views.display.block']['mapping']['allow']['mapping']['sort_fields'] = [
|
||||
'type' => 'string',
|
||||
'label' => 'Sort fields',
|
||||
];
|
||||
$definitions['views.display.block']['mapping']['allow']['mapping']['disable_filters'] = [
|
||||
'type' => 'string',
|
||||
'label' => 'Disable filters',
|
||||
];
|
||||
$definitions['views.display.block']['mapping']['allow']['mapping']['configure_sorts'] = [
|
||||
'type' => 'string',
|
||||
'label' => 'Configure sorts',
|
||||
];
|
||||
}
|
|
@ -0,0 +1,512 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\ctools_views\Plugin\Display;
|
||||
|
||||
use Drupal\Core\Block\BlockManagerInterface;
|
||||
use Drupal\Core\Entity\EntityTypeManagerInterface;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\views\Plugin\Block\ViewsBlock;
|
||||
use Drupal\views\Plugin\views\display\Block as CoreBlock;
|
||||
use Drupal\views\Plugin\ViewsHandlerManager;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
/**
|
||||
* Provides a Block display plugin.
|
||||
*
|
||||
* Allows for greater control over Views block settings.
|
||||
*/
|
||||
class Block extends CoreBlock {
|
||||
|
||||
/**
|
||||
* The views filter plugin manager.
|
||||
*
|
||||
* @var \Drupal\views\Plugin\ViewsHandlerManager
|
||||
*/
|
||||
protected $filterManager;
|
||||
|
||||
/**
|
||||
* The current request.
|
||||
*
|
||||
* @var \Symfony\Component\HttpFoundation\Request
|
||||
*/
|
||||
protected $request;
|
||||
|
||||
/**
|
||||
* Constructs a new Block instance.
|
||||
*
|
||||
* @param array $configuration
|
||||
* A configuration array containing information about the plugin instance.
|
||||
* @param string $plugin_id
|
||||
* The plugin_id for the plugin instance.
|
||||
* @param mixed $plugin_definition
|
||||
* The plugin implementation definition.
|
||||
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
|
||||
* The entity manager.
|
||||
* @param \Drupal\Core\Block\BlockManagerInterface $block_manager
|
||||
* The block manager.
|
||||
* @param \Drupal\views\Plugin\ViewsHandlerManager $filter_manager
|
||||
* The views filter plugin manager.
|
||||
* @param \Symfony\Component\HttpFoundation\Request $request
|
||||
* The current request.
|
||||
*/
|
||||
public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entity_type_manager, BlockManagerInterface $block_manager, ViewsHandlerManager $filter_manager, Request $request) {
|
||||
parent::__construct($configuration, $plugin_id, $plugin_definition, $entity_type_manager, $block_manager);
|
||||
|
||||
$this->filterManager = $filter_manager;
|
||||
$this->request = $request;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
|
||||
return new static(
|
||||
$configuration,
|
||||
$plugin_id,
|
||||
$plugin_definition,
|
||||
$container->get('entity_type.manager'),
|
||||
$container->get('plugin.manager.block'),
|
||||
$container->get('plugin.manager.views.filter'),
|
||||
$container->get('request_stack')->getCurrentRequest()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function optionsSummary(&$categories, &$options) {
|
||||
parent::optionsSummary($categories, $options);
|
||||
$filtered_allow = array_filter($this->getOption('allow'));
|
||||
$filter_options = [
|
||||
'items_per_page' => $this->t('Items per page'),
|
||||
'offset' => $this->t('Pager offset'),
|
||||
'pager' => $this->t('Pager type'),
|
||||
'hide_fields' => $this->t('Hide fields'),
|
||||
'sort_fields' => $this->t('Reorder fields'),
|
||||
'disable_filters' => $this->t('Disable filters'),
|
||||
'configure_sorts' => $this->t('Configure sorts'),
|
||||
];
|
||||
$filter_intersect = array_intersect_key($filter_options, $filtered_allow);
|
||||
|
||||
$options['allow'] = [
|
||||
'category' => 'block',
|
||||
'title' => $this->t('Allow settings'),
|
||||
'value' => empty($filtered_allow) ? $this->t('None') : implode(', ', $filter_intersect),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildOptionsForm(&$form, FormStateInterface $form_state) {
|
||||
parent::buildOptionsForm($form, $form_state);
|
||||
|
||||
$form['allow']['#options']['offset'] = $this->t('Pager offset');
|
||||
$form['allow']['#options']['pager'] = $this->t('Pager type');
|
||||
$form['allow']['#options']['hide_fields'] = $this->t('Hide fields');
|
||||
$form['allow']['#options']['sort_fields'] = $this->t('Reorder fields');
|
||||
$form['allow']['#options']['disable_filters'] = $this->t('Disable filters');
|
||||
$form['allow']['#options']['configure_sorts'] = $this->t('Configure sorts');
|
||||
|
||||
$defaults = [];
|
||||
if (!empty($form['allow']['#default_value'])) {
|
||||
$defaults = array_filter($form['allow']['#default_value']);
|
||||
if (!empty($defaults['items_per_page'])) {
|
||||
$defaults['items_per_page'] = 'items_per_page';
|
||||
}
|
||||
}
|
||||
|
||||
$form['allow']['#default_value'] = $defaults;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function blockForm(ViewsBlock $block, array &$form, FormStateInterface $form_state) {
|
||||
$form = parent::blockForm($block, $form, $form_state);
|
||||
|
||||
$allow_settings = array_filter($this->getOption('allow'));
|
||||
$block_configuration = $block->getConfiguration();
|
||||
|
||||
// Modify "Items per page" block settings form.
|
||||
if (!empty($allow_settings['items_per_page'])) {
|
||||
// Items per page.
|
||||
$form['override']['items_per_page']['#type'] = 'number';
|
||||
unset($form['override']['items_per_page']['#options']);
|
||||
}
|
||||
|
||||
// Provide "Pager offset" block settings form.
|
||||
if (!empty($allow_settings['offset'])) {
|
||||
$form['override']['pager_offset'] = [
|
||||
'#type' => 'number',
|
||||
'#title' => $this->t('Pager offset'),
|
||||
'#default_value' => isset($block_configuration['pager_offset']) ? $block_configuration['pager_offset'] : 0,
|
||||
'#description' => $this->t('For example, set this to 3 and the first 3 items will not be displayed.'),
|
||||
];
|
||||
}
|
||||
|
||||
// Provide "Pager type" block settings form.
|
||||
if (!empty($allow_settings['pager'])) {
|
||||
$pager_options = [
|
||||
'view' => $this->t('Inherit from view'),
|
||||
'some' => $this->t('Display a specified number of items'),
|
||||
'none' => $this->t('Display all items'),
|
||||
];
|
||||
$form['override']['pager'] = [
|
||||
'#type' => 'radios',
|
||||
'#title' => $this->t('Pager'),
|
||||
'#options' => $pager_options,
|
||||
'#default_value' => isset($block_configuration['pager']) ? $block_configuration['pager'] : 'view',
|
||||
];
|
||||
}
|
||||
|
||||
// Provide "Hide fields" / "Reorder fields" block settings form.
|
||||
if (!empty($allow_settings['hide_fields']) || !empty($allow_settings['sort_fields'])) {
|
||||
// Set up the configuration table for hiding / sorting fields.
|
||||
$fields = $this->getHandlers('field');
|
||||
$header = [];
|
||||
if (!empty($allow_settings['hide_fields'])) {
|
||||
$header['hide'] = $this->t('Hide');
|
||||
}
|
||||
$header['label'] = $this->t('Label');
|
||||
if (!empty($allow_settings['sort_fields'])) {
|
||||
$header['weight'] = $this->t('Weight');
|
||||
}
|
||||
$form['override']['order_fields'] = [
|
||||
'#type' => 'table',
|
||||
'#header' => $header,
|
||||
'#rows' => [],
|
||||
];
|
||||
if (!empty($allow_settings['sort_fields'])) {
|
||||
$form['override']['order_fields']['#tabledrag'] = [
|
||||
[
|
||||
'action' => 'order',
|
||||
'relationship' => 'sibling',
|
||||
'group' => 'field-weight',
|
||||
],
|
||||
];
|
||||
$form['override']['order_fields']['#attributes'] = ['id' => 'order-fields'];
|
||||
}
|
||||
|
||||
// Sort available field plugins by their currently configured weight.
|
||||
$sorted_fields = [];
|
||||
if (!empty($allow_settings['sort_fields']) && isset($block_configuration['fields'])) {
|
||||
uasort($block_configuration['fields'], '\Drupal\ctools_views\Plugin\Display\Block::sortFieldsByWeight');
|
||||
foreach (array_keys($block_configuration['fields']) as $field_name) {
|
||||
if (!empty($fields[$field_name])) {
|
||||
$sorted_fields[$field_name] = $fields[$field_name];
|
||||
unset($fields[$field_name]);
|
||||
}
|
||||
}
|
||||
if (!empty($fields)) {
|
||||
foreach ($fields as $field_name => $field_info) {
|
||||
$sorted_fields[$field_name] = $field_info;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
$sorted_fields = $fields;
|
||||
}
|
||||
|
||||
// Add each field to the configuration table.
|
||||
foreach ($sorted_fields as $field_name => $plugin) {
|
||||
$field_label = $plugin->adminLabel();
|
||||
if (!empty($plugin->options['label'])) {
|
||||
$field_label .= ' (' . $plugin->options['label'] . ')';
|
||||
}
|
||||
if (!empty($allow_settings['sort_fields'])) {
|
||||
$form['override']['order_fields'][$field_name]['#attributes']['class'][] = 'draggable';
|
||||
}
|
||||
$form['override']['order_fields'][$field_name]['#weight'] = !empty($block_configuration['fields'][$field_name]['weight']) ? $block_configuration['fields'][$field_name]['weight'] : 0;
|
||||
if (!empty($allow_settings['hide_fields'])) {
|
||||
$form['override']['order_fields'][$field_name]['hide'] = [
|
||||
'#type' => 'checkbox',
|
||||
'#default_value' => !empty($block_configuration['fields'][$field_name]['hide']) ? $block_configuration['fields'][$field_name]['hide'] : 0,
|
||||
];
|
||||
}
|
||||
$form['override']['order_fields'][$field_name]['label'] = [
|
||||
'#markup' => $field_label,
|
||||
];
|
||||
if (!empty($allow_settings['sort_fields'])) {
|
||||
$form['override']['order_fields'][$field_name]['weight'] = [
|
||||
'#type' => 'weight',
|
||||
'#title' => $this->t('Weight for @title', ['@title' => $field_label]),
|
||||
'#title_display' => 'invisible',
|
||||
'#delta' => 50,
|
||||
'#default_value' => !empty($block_configuration['fields'][$field_name]['weight']) ? $block_configuration['fields'][$field_name]['weight'] : 0,
|
||||
'#attributes' => ['class' => ['field-weight']],
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Provide "Configure filters" / "Disable filters" block settings form.
|
||||
if (!empty($allow_settings['disable_filters'])) {
|
||||
$items = [];
|
||||
foreach ((array) $this->getOption('filters') as $filter_name => $item) {
|
||||
$item['value'] = isset($block_configuration["filter"][$filter_name]['value']) ? $block_configuration["filter"][$filter_name]['value'] : '';
|
||||
$items[$filter_name] = $item;
|
||||
}
|
||||
$this->setOption('filters', $items);
|
||||
$filters = $this->getHandlers('filter');
|
||||
|
||||
// Add a settings form for each exposed filter to configure or hide it.
|
||||
foreach ($filters as $filter_name => $plugin) {
|
||||
if ($plugin->isExposed() && $exposed_info = $plugin->exposedInfo()) {
|
||||
$form['override']['filters'][$filter_name] = [
|
||||
'#type' => 'details',
|
||||
'#title' => $exposed_info['label'],
|
||||
];
|
||||
$form['override']['filters'][$filter_name]['plugin'] = [
|
||||
'#type' => 'value',
|
||||
'#value' => $plugin,
|
||||
];
|
||||
// Render "Disable filters" settings form.
|
||||
if (!empty($allow_settings['disable_filters'])) {
|
||||
$form['override']['filters'][$filter_name]['disable'] = [
|
||||
'#type' => 'checkbox',
|
||||
'#title' => $this->t('Disable'),
|
||||
'#default_value' => !empty($block_configuration['filter'][$filter_name]['disable']) ? $block_configuration['filter'][$filter_name]['disable'] : 0,
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Provide "Configure sorts" block settings form.
|
||||
if (!empty($allow_settings['configure_sorts'])) {
|
||||
$sorts = $this->getHandlers('sort');
|
||||
$options = [
|
||||
'ASC' => $this->t('Sort ascending'),
|
||||
'DESC' => $this->t('Sort descending'),
|
||||
];
|
||||
foreach ($sorts as $sort_name => $plugin) {
|
||||
$form['override']['sort'][$sort_name] = [
|
||||
'#type' => 'details',
|
||||
'#title' => $plugin->adminLabel(),
|
||||
];
|
||||
$form['override']['sort'][$sort_name]['plugin'] = [
|
||||
'#type' => 'value',
|
||||
'#value' => $plugin,
|
||||
];
|
||||
$form['override']['sort'][$sort_name]['order'] = [
|
||||
'#title' => $this->t('Order'),
|
||||
'#type' => 'radios',
|
||||
'#options' => $options,
|
||||
'#default_value' => $plugin->options['order'],
|
||||
];
|
||||
|
||||
// Set default values for sorts for this block.
|
||||
if (!empty($block_configuration["sort"][$sort_name])) {
|
||||
$form['override']['sort'][$sort_name]['order']['#default_value'] = $block_configuration["sort"][$sort_name];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function blockSubmit(ViewsBlock $block, $form, FormStateInterface $form_state) {
|
||||
// Set default value for items_per_page if left blank.
|
||||
if (empty($form_state->getValue(['override', 'items_per_page']))) {
|
||||
$form_state->setValue(['override', 'items_per_page'], "none");
|
||||
}
|
||||
|
||||
parent::blockSubmit($block, $form, $form_state);
|
||||
$configuration = $block->getConfiguration();
|
||||
$allow_settings = array_filter($this->getOption('allow'));
|
||||
|
||||
// Save "Pager type" settings to block configuration.
|
||||
if (!empty($allow_settings['pager'])) {
|
||||
if ($pager = $form_state->getValue(['override', 'pager'])) {
|
||||
$configuration['pager'] = $pager;
|
||||
}
|
||||
}
|
||||
|
||||
// Save "Pager offset" settings to block configuration.
|
||||
if (!empty($allow_settings['offset'])) {
|
||||
$configuration['pager_offset'] = $form_state->getValue(['override', 'pager_offset']);
|
||||
}
|
||||
|
||||
// Save "Hide fields" / "Reorder fields" settings to block configuration.
|
||||
if (!empty($allow_settings['hide_fields']) || !empty($allow_settings['sort_fields'])) {
|
||||
if ($fields = array_filter($form_state->getValue(['override', 'order_fields']))) {
|
||||
uasort($fields, '\Drupal\ctools_views\Plugin\Display\Block::sortFieldsByWeight');
|
||||
$configuration['fields'] = $fields;
|
||||
}
|
||||
}
|
||||
|
||||
// Save "Configure filters" / "Disable filters" settings to block
|
||||
// configuration.
|
||||
unset($configuration['filter']);
|
||||
if (!empty($allow_settings['disable_filters'])) {
|
||||
if ($filters = $form_state->getValue(['override', 'filters'])) {
|
||||
foreach ($filters as $filter_name => $filter) {
|
||||
/** @var \Drupal\views\Plugin\views\filter\FilterPluginBase $plugin */
|
||||
$plugin = $form_state->getValue([
|
||||
'override', 'filters', $filter_name, 'plugin',
|
||||
]);
|
||||
$configuration["filter"][$filter_name]['type'] = $plugin->getPluginId();
|
||||
|
||||
// Check if we want to disable this filter.
|
||||
if (!empty($allow_settings['disable_filters'])) {
|
||||
$disable = $form_state->getValue([
|
||||
'override', 'filters', $filter_name, 'disable',
|
||||
]);
|
||||
// If marked disabled, we don't really care about other stuff.
|
||||
if ($disable) {
|
||||
$configuration["filter"][$filter_name]['disable'] = $disable;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Save "Configure sorts" settings to block configuration.
|
||||
if (!empty($allow_settings['configure_sorts'])) {
|
||||
$sorts = $form_state->getValue(['override', 'sort']);
|
||||
foreach ($sorts as $sort_name => $sort) {
|
||||
$plugin = $sort['plugin'];
|
||||
// Check if we want to override the default sort order.
|
||||
if ($plugin->options['order'] != $sort['order']) {
|
||||
$configuration['sort'][$sort_name] = $sort['order'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$block->setConfiguration($configuration);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function preBlockBuild(ViewsBlock $block) {
|
||||
parent::preBlockBuild($block);
|
||||
|
||||
$allow_settings = array_filter($this->getOption('allow'));
|
||||
$config = $block->getConfiguration();
|
||||
list(, $display_id) = explode('-', $block->getDerivativeId(), 2);
|
||||
|
||||
// Change pager offset settings based on block configuration.
|
||||
if (!empty($allow_settings['offset']) && isset($config['pager_offset'])) {
|
||||
$this->view->setOffset($config['pager_offset']);
|
||||
}
|
||||
|
||||
// Change pager style settings based on block configuration.
|
||||
if (!empty($allow_settings['pager'])) {
|
||||
$pager = $this->view->display_handler->getOption('pager');
|
||||
if (!empty($config['pager']) && $config['pager'] != 'view') {
|
||||
$pager['type'] = $config['pager'];
|
||||
}
|
||||
$this->view->display_handler->setOption('pager', $pager);
|
||||
}
|
||||
|
||||
// Change fields output based on block configuration.
|
||||
if (!empty($allow_settings['hide_fields']) || !empty($allow_settings['sort_fields'])) {
|
||||
if (!empty($config['fields']) && $this->view->getStyle()->usesFields()) {
|
||||
$fields = $this->view->getHandlers('field');
|
||||
uasort($config['fields'], '\Drupal\ctools_views\Plugin\Display\Block::sortFieldsByWeight');
|
||||
$iterate_fields = !empty($allow_settings['sort_fields']) ? $config['fields'] : $fields;
|
||||
foreach (array_keys($iterate_fields) as $field_name) {
|
||||
// Remove each field in sequence and re-add them to sort
|
||||
// appropriately or hide if disabled.
|
||||
$this->view->removeHandler($display_id, 'field', $field_name);
|
||||
if (empty($allow_settings['hide_fields']) || (!empty($allow_settings['hide_fields']) && empty($config['fields'][$field_name]['hide']))) {
|
||||
$this->view->addHandler($display_id, 'field', $fields[$field_name]['table'], $fields[$field_name]['field'], $fields[$field_name], $field_name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Change filters output based on block configuration.
|
||||
if (!empty($allow_settings['disable_filters'])) {
|
||||
$filters = $this->view->getHandlers('filter', $display_id);
|
||||
foreach ($filters as $filter_name => $filter) {
|
||||
// If we allow disabled filters and this filter is disabled, disable it
|
||||
// and continue.
|
||||
if (!empty($allow_settings['disable_filters']) && !empty($config["filter"][$filter_name]['disable'])) {
|
||||
$this->view->removeHandler($display_id, 'filter', $filter_name);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Change sorts based on block configuration.
|
||||
if (!empty($allow_settings['configure_sorts'])) {
|
||||
$sorts = $this->view->getHandlers('sort', $display_id);
|
||||
foreach ($sorts as $sort_name => $sort) {
|
||||
if (!empty($config["sort"][$sort_name])) {
|
||||
$sort['order'] = $config["sort"][$sort_name];
|
||||
$this->view->setHandler($display_id, 'sort', $sort_name, $sort);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter options value.
|
||||
*/
|
||||
protected function getFilterOptionsValue(array $filter, array $config) {
|
||||
$plugin_definition = $this->filterManager->getDefinition($config['type']);
|
||||
if (is_subclass_of($plugin_definition['class'], '\Drupal\views\Plugin\views\filter\InOperator')) {
|
||||
return array_values($config['value']);
|
||||
}
|
||||
return $config['value'][$filter['expose']['identifier']];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function usesExposed() {
|
||||
$filters = $this->getHandlers('filter');
|
||||
foreach ($filters as $filter) {
|
||||
if ($filter->isExposed() && !empty($filter->exposedInfo())) {
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Exposed widgets.
|
||||
*
|
||||
* Exposed widgets typically only work with ajax in Drupal core, however
|
||||
* #2605218 totally breaks the rest of the functionality in this display and
|
||||
* in Core's Block display as well, so we allow non-ajax block views to use
|
||||
* exposed filters and manually set the #action to the current request uri.
|
||||
*/
|
||||
public function elementPreRender(array $element) {
|
||||
/** @var \Drupal\views\ViewExecutable $view */
|
||||
$view = $element['#view'];
|
||||
if (!empty($view->exposed_widgets['#action']) && !$view->ajaxEnabled()) {
|
||||
$view->exposed_widgets['#action'] = $this->request->getRequestUri();
|
||||
}
|
||||
return parent::elementPreRender($element);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sort field config array by weight.
|
||||
*
|
||||
* @param int $a
|
||||
* The field a.
|
||||
* @param int $b
|
||||
* The field b.
|
||||
*
|
||||
* @return int
|
||||
* Return the more weight
|
||||
*/
|
||||
public static function sortFieldsByWeight($a, $b) {
|
||||
$a_weight = isset($a['weight']) ? $a['weight'] : 0;
|
||||
$b_weight = isset($b['weight']) ? $b['weight'] : 0;
|
||||
if ($a_weight == $b_weight) {
|
||||
return 0;
|
||||
}
|
||||
return ($a_weight < $b_weight) ? -1 : 1;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
name: 'CTools Views test views'
|
||||
type: module
|
||||
description: 'Provides default views for CTools Views tests.'
|
||||
package: Testing
|
||||
dependencies:
|
||||
- drupal:views
|
||||
- drupal:block
|
||||
- entity_test:entity_test
|
||||
- ctools_views:ctools_views
|
||||
- drupal:text
|
||||
- drupal:user
|
||||
- drupal:node
|
||||
- drupal:taxonomy
|
||||
|
||||
# Information added by Drupal.org packaging script on 2021-06-16
|
||||
version: '8.x-3.7'
|
||||
project: 'ctools'
|
||||
datestamp: 1623822132
|
|
@ -0,0 +1,543 @@
|
|||
langcode: en
|
||||
status: true
|
||||
dependencies:
|
||||
config:
|
||||
- node.type.ctools_views
|
||||
- taxonomy.vocabulary.tags
|
||||
module:
|
||||
- datetime
|
||||
- node
|
||||
- options
|
||||
- taxonomy
|
||||
- user
|
||||
id: ctools_views_entity_test
|
||||
label: 'CTools Views Entity Test View'
|
||||
module: views
|
||||
description: ''
|
||||
tag: ''
|
||||
base_table: node_field_data
|
||||
base_field: nid
|
||||
core: 8.x
|
||||
display:
|
||||
default:
|
||||
display_plugin: default
|
||||
id: default
|
||||
display_title: Master
|
||||
position: 0
|
||||
display_options:
|
||||
access:
|
||||
type: perm
|
||||
options:
|
||||
perm: 'access content'
|
||||
cache:
|
||||
type: tag
|
||||
options: { }
|
||||
query:
|
||||
type: views_query
|
||||
options:
|
||||
disable_sql_rewrite: false
|
||||
distinct: false
|
||||
replica: false
|
||||
query_comment: ''
|
||||
query_tags: { }
|
||||
exposed_form:
|
||||
type: basic
|
||||
options:
|
||||
submit_button: Apply
|
||||
reset_button: false
|
||||
reset_button_label: Reset
|
||||
exposed_sorts_label: 'Sort by'
|
||||
expose_sort_order: true
|
||||
sort_asc_label: Asc
|
||||
sort_desc_label: Desc
|
||||
pager:
|
||||
type: none
|
||||
options:
|
||||
offset: 0
|
||||
style:
|
||||
type: table
|
||||
row:
|
||||
type: fields
|
||||
fields:
|
||||
title:
|
||||
id: title
|
||||
table: node_field_data
|
||||
field: title
|
||||
entity_type: node
|
||||
entity_field: title
|
||||
alter:
|
||||
alter_text: false
|
||||
make_link: false
|
||||
absolute: false
|
||||
trim: false
|
||||
word_boundary: false
|
||||
ellipsis: false
|
||||
strip_tags: false
|
||||
html: false
|
||||
hide_empty: false
|
||||
empty_zero: false
|
||||
settings:
|
||||
link_to_entity: true
|
||||
plugin_id: field
|
||||
relationship: none
|
||||
group_type: group
|
||||
admin_label: ''
|
||||
label: Title
|
||||
exclude: false
|
||||
element_type: ''
|
||||
element_class: ''
|
||||
element_label_type: ''
|
||||
element_label_class: ''
|
||||
element_label_colon: true
|
||||
element_wrapper_type: ''
|
||||
element_wrapper_class: ''
|
||||
element_default_classes: true
|
||||
empty: ''
|
||||
hide_alter_empty: true
|
||||
click_sort_column: value
|
||||
type: string
|
||||
group_column: value
|
||||
group_columns: { }
|
||||
group_rows: true
|
||||
delta_limit: 0
|
||||
delta_offset: 0
|
||||
delta_reversed: false
|
||||
delta_first_last: false
|
||||
multi_type: separator
|
||||
separator: ', '
|
||||
field_api_classes: false
|
||||
filters:
|
||||
status:
|
||||
value: '1'
|
||||
table: node_field_data
|
||||
field: status
|
||||
plugin_id: boolean
|
||||
entity_type: node
|
||||
entity_field: status
|
||||
id: status
|
||||
expose:
|
||||
operator: ''
|
||||
group: 1
|
||||
type:
|
||||
id: type
|
||||
table: node_field_data
|
||||
field: type
|
||||
value:
|
||||
ctools_views: ctools_views
|
||||
entity_type: node
|
||||
entity_field: type
|
||||
plugin_id: bundle
|
||||
sorts:
|
||||
created:
|
||||
id: created
|
||||
table: node_field_data
|
||||
field: created
|
||||
order: DESC
|
||||
entity_type: node
|
||||
entity_field: created
|
||||
plugin_id: date
|
||||
relationship: none
|
||||
group_type: group
|
||||
admin_label: ''
|
||||
exposed: false
|
||||
expose:
|
||||
label: ''
|
||||
granularity: second
|
||||
title: 'CTools Views Entity Test View'
|
||||
header: { }
|
||||
footer: { }
|
||||
empty: { }
|
||||
relationships: { }
|
||||
arguments: { }
|
||||
display_extenders: { }
|
||||
cache_metadata:
|
||||
max-age: 0
|
||||
contexts:
|
||||
- 'languages:language_content'
|
||||
- 'languages:language_interface'
|
||||
- 'user.node_grants:view'
|
||||
- user.permissions
|
||||
tags: { }
|
||||
block_filter_date:
|
||||
display_plugin: block
|
||||
id: block_filter_date
|
||||
display_title: 'Date filter'
|
||||
position: 4
|
||||
display_options:
|
||||
display_extenders: { }
|
||||
display_description: ''
|
||||
title: 'Date filter'
|
||||
defaults:
|
||||
title: false
|
||||
filters: false
|
||||
filter_groups: false
|
||||
filters:
|
||||
status:
|
||||
value: '1'
|
||||
table: node_field_data
|
||||
field: status
|
||||
plugin_id: boolean
|
||||
entity_type: node
|
||||
entity_field: status
|
||||
id: status
|
||||
expose:
|
||||
operator: ''
|
||||
group: 1
|
||||
type:
|
||||
id: type
|
||||
table: node_field_data
|
||||
field: type
|
||||
value:
|
||||
ctools_views: ctools_views
|
||||
entity_type: node
|
||||
entity_field: type
|
||||
plugin_id: bundle
|
||||
group: 1
|
||||
field_ctools_views_date_value:
|
||||
id: field_ctools_views_date_value
|
||||
table: node__field_ctools_views_date
|
||||
field: field_ctools_views_date_value
|
||||
relationship: none
|
||||
group_type: group
|
||||
admin_label: ''
|
||||
operator: between
|
||||
group: 1
|
||||
exposed: true
|
||||
expose:
|
||||
operator_id: field_ctools_views_date_value_op
|
||||
label: 'CTools Views Date (field_ctools_views_date)'
|
||||
description: ''
|
||||
use_operator: false
|
||||
operator: field_ctools_views_date_value_op
|
||||
identifier: field_ctools_views_date_value
|
||||
required: false
|
||||
remember: false
|
||||
multiple: false
|
||||
remember_roles:
|
||||
authenticated: authenticated
|
||||
anonymous: '0'
|
||||
administrator1: '0'
|
||||
administrator: '0'
|
||||
is_grouped: false
|
||||
group_info:
|
||||
label: ''
|
||||
description: ''
|
||||
identifier: ''
|
||||
optional: true
|
||||
widget: select
|
||||
multiple: false
|
||||
remember: false
|
||||
default_group: All
|
||||
default_group_multiple: { }
|
||||
group_items: { }
|
||||
plugin_id: datetime
|
||||
filter_groups:
|
||||
operator: AND
|
||||
groups:
|
||||
1: AND
|
||||
allow:
|
||||
items_per_page: false
|
||||
offset: '0'
|
||||
pager: '0'
|
||||
hide_fields: '0'
|
||||
sort_fields: '0'
|
||||
disable_filters: '0'
|
||||
cache_metadata:
|
||||
max-age: 0
|
||||
contexts:
|
||||
- 'languages:language_content'
|
||||
- 'languages:language_interface'
|
||||
- url
|
||||
- 'user.node_grants:view'
|
||||
- user.permissions
|
||||
tags: { }
|
||||
block_filter_list:
|
||||
display_plugin: block
|
||||
id: block_filter_list
|
||||
display_title: 'List filter'
|
||||
position: 3
|
||||
display_options:
|
||||
display_extenders: { }
|
||||
display_description: ''
|
||||
title: 'List filter'
|
||||
defaults:
|
||||
title: false
|
||||
filters: false
|
||||
filter_groups: false
|
||||
filters:
|
||||
status:
|
||||
value: '1'
|
||||
table: node_field_data
|
||||
field: status
|
||||
plugin_id: boolean
|
||||
entity_type: node
|
||||
entity_field: status
|
||||
id: status
|
||||
expose:
|
||||
operator: ''
|
||||
group: 1
|
||||
type:
|
||||
id: type
|
||||
table: node_field_data
|
||||
field: type
|
||||
value:
|
||||
ctools_views: ctools_views
|
||||
entity_type: node
|
||||
entity_field: type
|
||||
plugin_id: bundle
|
||||
field_ctools_views_list_value:
|
||||
id: field_ctools_views_list_value
|
||||
table: node__field_ctools_views_list
|
||||
field: field_ctools_views_list_value
|
||||
relationship: none
|
||||
group_type: group
|
||||
admin_label: ''
|
||||
operator: or
|
||||
value: { }
|
||||
group: 1
|
||||
exposed: true
|
||||
expose:
|
||||
operator_id: field_ctools_views_list_value_op
|
||||
label: 'Ctools Views List (field_ctools_views_list)'
|
||||
description: ''
|
||||
use_operator: false
|
||||
operator: field_ctools_views_list_value_op
|
||||
identifier: field_ctools_views_list_value
|
||||
required: false
|
||||
remember: false
|
||||
multiple: false
|
||||
remember_roles:
|
||||
authenticated: authenticated
|
||||
anonymous: '0'
|
||||
administrator1: '0'
|
||||
administrator: '0'
|
||||
reduce: false
|
||||
is_grouped: false
|
||||
group_info:
|
||||
label: ''
|
||||
description: ''
|
||||
identifier: ''
|
||||
optional: true
|
||||
widget: select
|
||||
multiple: false
|
||||
remember: false
|
||||
default_group: All
|
||||
default_group_multiple: { }
|
||||
group_items: { }
|
||||
reduce_duplicates: false
|
||||
plugin_id: list_field
|
||||
filter_groups:
|
||||
operator: AND
|
||||
groups:
|
||||
1: AND
|
||||
allow:
|
||||
items_per_page: false
|
||||
offset: '0'
|
||||
pager: '0'
|
||||
hide_fields: '0'
|
||||
sort_fields: '0'
|
||||
disable_filters: '0'
|
||||
cache_metadata:
|
||||
max-age: 0
|
||||
contexts:
|
||||
- 'languages:language_content'
|
||||
- 'languages:language_interface'
|
||||
- url
|
||||
- 'user.node_grants:view'
|
||||
- user.permissions
|
||||
tags: { }
|
||||
block_filter_tax:
|
||||
display_plugin: block
|
||||
id: block_filter_tax
|
||||
display_title: 'Taxonomy filter'
|
||||
position: 2
|
||||
display_options:
|
||||
display_extenders: { }
|
||||
display_description: ''
|
||||
title: 'Taxonomy filter'
|
||||
defaults:
|
||||
title: false
|
||||
filters: false
|
||||
filter_groups: false
|
||||
filters:
|
||||
status:
|
||||
value: '1'
|
||||
table: node_field_data
|
||||
field: status
|
||||
plugin_id: boolean
|
||||
entity_type: node
|
||||
entity_field: status
|
||||
id: status
|
||||
expose:
|
||||
operator: ''
|
||||
group: 1
|
||||
type:
|
||||
id: type
|
||||
table: node_field_data
|
||||
field: type
|
||||
value:
|
||||
ctools_views: ctools_views
|
||||
entity_type: node
|
||||
entity_field: type
|
||||
plugin_id: bundle
|
||||
group: 1
|
||||
field_ctools_views_tags_target_id:
|
||||
id: field_ctools_views_tags_target_id
|
||||
table: node__field_ctools_views_tags
|
||||
field: field_ctools_views_tags_target_id
|
||||
relationship: none
|
||||
group_type: group
|
||||
admin_label: ''
|
||||
operator: or
|
||||
value: { }
|
||||
group: 1
|
||||
exposed: true
|
||||
expose:
|
||||
operator_id: field_ctools_views_tags_target_id_op
|
||||
label: 'Tags (field_ctools_views_tags)'
|
||||
description: ''
|
||||
use_operator: false
|
||||
operator: field_ctools_views_tags_target_id_op
|
||||
identifier: field_ctools_views_tags_target_id
|
||||
required: false
|
||||
remember: false
|
||||
multiple: false
|
||||
remember_roles:
|
||||
authenticated: authenticated
|
||||
anonymous: '0'
|
||||
administrator1: '0'
|
||||
administrator: '0'
|
||||
reduce: false
|
||||
is_grouped: false
|
||||
group_info:
|
||||
label: ''
|
||||
description: ''
|
||||
identifier: ''
|
||||
optional: true
|
||||
widget: select
|
||||
multiple: false
|
||||
remember: false
|
||||
default_group: All
|
||||
default_group_multiple: { }
|
||||
group_items: { }
|
||||
reduce_duplicates: false
|
||||
type: select
|
||||
limit: true
|
||||
vid: tags
|
||||
hierarchy: false
|
||||
error_message: true
|
||||
plugin_id: taxonomy_index_tid
|
||||
filter_groups:
|
||||
operator: AND
|
||||
groups:
|
||||
1: AND
|
||||
allow:
|
||||
items_per_page: false
|
||||
offset: '0'
|
||||
pager: '0'
|
||||
hide_fields: '0'
|
||||
sort_fields: '0'
|
||||
disable_filters: '0'
|
||||
cache_metadata:
|
||||
max-age: 0
|
||||
contexts:
|
||||
- 'languages:language_content'
|
||||
- 'languages:language_interface'
|
||||
- url
|
||||
- user
|
||||
- 'user.node_grants:view'
|
||||
- user.permissions
|
||||
tags: { }
|
||||
block_filter_text:
|
||||
display_plugin: block
|
||||
id: block_filter_text
|
||||
display_title: 'Textfield filter'
|
||||
position: 1
|
||||
display_options:
|
||||
display_extenders: { }
|
||||
display_description: ''
|
||||
title: 'Textfield filter'
|
||||
defaults:
|
||||
title: false
|
||||
filters: false
|
||||
filter_groups: false
|
||||
filters:
|
||||
status:
|
||||
value: '1'
|
||||
table: node_field_data
|
||||
field: status
|
||||
plugin_id: boolean
|
||||
entity_type: node
|
||||
entity_field: status
|
||||
id: status
|
||||
expose:
|
||||
operator: ''
|
||||
group: 1
|
||||
type:
|
||||
id: type
|
||||
table: node_field_data
|
||||
field: type
|
||||
value:
|
||||
ctools_views: ctools_views
|
||||
entity_type: node
|
||||
entity_field: type
|
||||
plugin_id: bundle
|
||||
field_ctools_views_text_value:
|
||||
id: field_ctools_views_text_value
|
||||
table: node__field_ctools_views_text
|
||||
field: field_ctools_views_text_value
|
||||
relationship: none
|
||||
group_type: group
|
||||
admin_label: ''
|
||||
operator: '='
|
||||
value: ''
|
||||
group: 1
|
||||
exposed: true
|
||||
expose:
|
||||
operator_id: field_ctools_views_text_value_op
|
||||
label: 'Text (field_ctools_views_text)'
|
||||
description: ''
|
||||
use_operator: false
|
||||
operator: field_ctools_views_text_value_op
|
||||
identifier: field_ctools_views_text_value
|
||||
required: false
|
||||
remember: false
|
||||
multiple: false
|
||||
remember_roles:
|
||||
authenticated: authenticated
|
||||
anonymous: '0'
|
||||
administrator1: '0'
|
||||
administrator: '0'
|
||||
is_grouped: false
|
||||
group_info:
|
||||
label: ''
|
||||
description: ''
|
||||
identifier: ''
|
||||
optional: true
|
||||
widget: select
|
||||
multiple: false
|
||||
remember: false
|
||||
default_group: All
|
||||
default_group_multiple: { }
|
||||
group_items: { }
|
||||
plugin_id: string
|
||||
filter_groups:
|
||||
operator: AND
|
||||
groups:
|
||||
1: AND
|
||||
allow:
|
||||
items_per_page: false
|
||||
offset: '0'
|
||||
pager: '0'
|
||||
hide_fields: '0'
|
||||
sort_fields: '0'
|
||||
disable_filters: '0'
|
||||
cache_metadata:
|
||||
max-age: 0
|
||||
contexts:
|
||||
- 'languages:language_content'
|
||||
- 'languages:language_interface'
|
||||
- url
|
||||
- 'user.node_grants:view'
|
||||
- user.permissions
|
||||
tags: { }
|
|
@ -0,0 +1,949 @@
|
|||
langcode: en
|
||||
status: true
|
||||
dependencies: { }
|
||||
id: ctools_views_test_view
|
||||
label: 'CTools Views Test View'
|
||||
module: views
|
||||
description: ''
|
||||
tag: ''
|
||||
base_table: views_test_data
|
||||
base_field: id
|
||||
core: 8.x
|
||||
display:
|
||||
default:
|
||||
display_plugin: default
|
||||
id: default
|
||||
display_title: Master
|
||||
position: 0
|
||||
display_options:
|
||||
access:
|
||||
type: none
|
||||
options: { }
|
||||
cache:
|
||||
type: tag
|
||||
options: { }
|
||||
query:
|
||||
type: views_query
|
||||
options:
|
||||
disable_sql_rewrite: false
|
||||
distinct: false
|
||||
replica: false
|
||||
query_comment: ''
|
||||
query_tags: { }
|
||||
exposed_form:
|
||||
type: basic
|
||||
options:
|
||||
submit_button: Apply
|
||||
reset_button: false
|
||||
reset_button_label: Reset
|
||||
exposed_sorts_label: 'Sort by'
|
||||
expose_sort_order: true
|
||||
sort_asc_label: Asc
|
||||
sort_desc_label: Desc
|
||||
pager:
|
||||
type: none
|
||||
options:
|
||||
offset: 0
|
||||
style:
|
||||
type: table
|
||||
options:
|
||||
grouping: { }
|
||||
row_class: ''
|
||||
default_row_class: true
|
||||
override: true
|
||||
sticky: false
|
||||
caption: ''
|
||||
summary: ''
|
||||
description: ''
|
||||
columns:
|
||||
id: id
|
||||
age: age
|
||||
created: created
|
||||
id_1: id_1
|
||||
job: job
|
||||
name: name
|
||||
info:
|
||||
id:
|
||||
sortable: false
|
||||
default_sort_order: asc
|
||||
align: ''
|
||||
separator: ''
|
||||
empty_column: false
|
||||
responsive: ''
|
||||
age:
|
||||
sortable: false
|
||||
default_sort_order: asc
|
||||
align: ''
|
||||
separator: ''
|
||||
empty_column: false
|
||||
responsive: ''
|
||||
created:
|
||||
sortable: false
|
||||
default_sort_order: asc
|
||||
align: ''
|
||||
separator: ''
|
||||
empty_column: false
|
||||
responsive: ''
|
||||
id_1:
|
||||
sortable: false
|
||||
default_sort_order: asc
|
||||
align: ''
|
||||
separator: ''
|
||||
empty_column: false
|
||||
responsive: ''
|
||||
job:
|
||||
sortable: false
|
||||
default_sort_order: asc
|
||||
align: ''
|
||||
separator: ''
|
||||
empty_column: false
|
||||
responsive: ''
|
||||
name:
|
||||
sortable: false
|
||||
default_sort_order: asc
|
||||
align: ''
|
||||
separator: ''
|
||||
empty_column: false
|
||||
responsive: ''
|
||||
default: '-1'
|
||||
empty_table: false
|
||||
row:
|
||||
type: fields
|
||||
fields:
|
||||
id:
|
||||
id: id
|
||||
table: views_test_data
|
||||
field: id
|
||||
relationship: none
|
||||
group_type: group
|
||||
admin_label: ''
|
||||
label: ID
|
||||
exclude: false
|
||||
alter:
|
||||
alter_text: false
|
||||
text: ''
|
||||
make_link: false
|
||||
path: ''
|
||||
absolute: false
|
||||
external: false
|
||||
replace_spaces: false
|
||||
path_case: none
|
||||
trim_whitespace: false
|
||||
alt: ''
|
||||
rel: ''
|
||||
link_class: ''
|
||||
prefix: ''
|
||||
suffix: ''
|
||||
target: ''
|
||||
nl2br: false
|
||||
max_length: 0
|
||||
word_boundary: true
|
||||
ellipsis: true
|
||||
more_link: false
|
||||
more_link_text: ''
|
||||
more_link_path: ''
|
||||
strip_tags: false
|
||||
trim: false
|
||||
preserve_tags: ''
|
||||
html: false
|
||||
element_type: ''
|
||||
element_class: ''
|
||||
element_label_type: ''
|
||||
element_label_class: ''
|
||||
element_label_colon: false
|
||||
element_wrapper_type: ''
|
||||
element_wrapper_class: ''
|
||||
element_default_classes: true
|
||||
empty: ''
|
||||
hide_empty: false
|
||||
empty_zero: false
|
||||
hide_alter_empty: true
|
||||
set_precision: false
|
||||
precision: 0
|
||||
decimal: .
|
||||
separator: ''
|
||||
format_plural: false
|
||||
format_plural_string: "1\x03@count"
|
||||
prefix: ''
|
||||
suffix: ''
|
||||
entity_type: null
|
||||
entity_field: null
|
||||
plugin_id: numeric
|
||||
name:
|
||||
id: name
|
||||
table: views_test_data
|
||||
field: name
|
||||
relationship: none
|
||||
group_type: group
|
||||
admin_label: ''
|
||||
label: Name
|
||||
exclude: false
|
||||
alter:
|
||||
alter_text: false
|
||||
text: ''
|
||||
make_link: false
|
||||
path: ''
|
||||
absolute: false
|
||||
external: false
|
||||
replace_spaces: false
|
||||
path_case: none
|
||||
trim_whitespace: false
|
||||
alt: ''
|
||||
rel: ''
|
||||
link_class: ''
|
||||
prefix: ''
|
||||
suffix: ''
|
||||
target: ''
|
||||
nl2br: false
|
||||
max_length: 0
|
||||
word_boundary: true
|
||||
ellipsis: true
|
||||
more_link: false
|
||||
more_link_text: ''
|
||||
more_link_path: ''
|
||||
strip_tags: false
|
||||
trim: false
|
||||
preserve_tags: ''
|
||||
html: false
|
||||
element_type: ''
|
||||
element_class: ''
|
||||
element_label_type: ''
|
||||
element_label_class: ''
|
||||
element_label_colon: false
|
||||
element_wrapper_type: ''
|
||||
element_wrapper_class: ''
|
||||
element_default_classes: true
|
||||
empty: ''
|
||||
hide_empty: false
|
||||
empty_zero: false
|
||||
hide_alter_empty: true
|
||||
plugin_id: standard
|
||||
age:
|
||||
id: age
|
||||
table: views_test_data
|
||||
field: age
|
||||
relationship: none
|
||||
group_type: group
|
||||
admin_label: ''
|
||||
label: Age
|
||||
exclude: false
|
||||
alter:
|
||||
alter_text: false
|
||||
text: ''
|
||||
make_link: false
|
||||
path: ''
|
||||
absolute: false
|
||||
external: false
|
||||
replace_spaces: false
|
||||
path_case: none
|
||||
trim_whitespace: false
|
||||
alt: ''
|
||||
rel: ''
|
||||
link_class: ''
|
||||
prefix: ''
|
||||
suffix: ''
|
||||
target: ''
|
||||
nl2br: false
|
||||
max_length: 0
|
||||
word_boundary: true
|
||||
ellipsis: true
|
||||
more_link: false
|
||||
more_link_text: ''
|
||||
more_link_path: ''
|
||||
strip_tags: false
|
||||
trim: false
|
||||
preserve_tags: ''
|
||||
html: false
|
||||
element_type: ''
|
||||
element_class: ''
|
||||
element_label_type: ''
|
||||
element_label_class: ''
|
||||
element_label_colon: false
|
||||
element_wrapper_type: ''
|
||||
element_wrapper_class: ''
|
||||
element_default_classes: true
|
||||
empty: ''
|
||||
hide_empty: false
|
||||
empty_zero: false
|
||||
hide_alter_empty: true
|
||||
set_precision: false
|
||||
precision: 0
|
||||
decimal: .
|
||||
separator: ''
|
||||
format_plural: false
|
||||
format_plural_string: "1\x03@count"
|
||||
prefix: ''
|
||||
suffix: ''
|
||||
plugin_id: numeric
|
||||
job:
|
||||
id: job
|
||||
table: views_test_data
|
||||
field: job
|
||||
relationship: none
|
||||
group_type: group
|
||||
admin_label: ''
|
||||
label: Job
|
||||
exclude: false
|
||||
alter:
|
||||
alter_text: false
|
||||
text: ''
|
||||
make_link: false
|
||||
path: ''
|
||||
absolute: false
|
||||
external: false
|
||||
replace_spaces: false
|
||||
path_case: none
|
||||
trim_whitespace: false
|
||||
alt: ''
|
||||
rel: ''
|
||||
link_class: ''
|
||||
prefix: ''
|
||||
suffix: ''
|
||||
target: ''
|
||||
nl2br: false
|
||||
max_length: 0
|
||||
word_boundary: true
|
||||
ellipsis: true
|
||||
more_link: false
|
||||
more_link_text: ''
|
||||
more_link_path: ''
|
||||
strip_tags: false
|
||||
trim: false
|
||||
preserve_tags: ''
|
||||
html: false
|
||||
element_type: ''
|
||||
element_class: ''
|
||||
element_label_type: ''
|
||||
element_label_class: ''
|
||||
element_label_colon: false
|
||||
element_wrapper_type: ''
|
||||
element_wrapper_class: ''
|
||||
element_default_classes: true
|
||||
empty: ''
|
||||
hide_empty: false
|
||||
empty_zero: false
|
||||
hide_alter_empty: true
|
||||
plugin_id: standard
|
||||
created:
|
||||
id: created
|
||||
table: views_test_data
|
||||
field: created
|
||||
relationship: none
|
||||
group_type: group
|
||||
admin_label: ''
|
||||
label: Created
|
||||
exclude: false
|
||||
alter:
|
||||
alter_text: false
|
||||
text: ''
|
||||
make_link: false
|
||||
path: ''
|
||||
absolute: false
|
||||
external: false
|
||||
replace_spaces: false
|
||||
path_case: none
|
||||
trim_whitespace: false
|
||||
alt: ''
|
||||
rel: ''
|
||||
link_class: ''
|
||||
prefix: ''
|
||||
suffix: ''
|
||||
target: ''
|
||||
nl2br: false
|
||||
max_length: 0
|
||||
word_boundary: true
|
||||
ellipsis: true
|
||||
more_link: false
|
||||
more_link_text: ''
|
||||
more_link_path: ''
|
||||
strip_tags: false
|
||||
trim: false
|
||||
preserve_tags: ''
|
||||
html: false
|
||||
element_type: ''
|
||||
element_class: ''
|
||||
element_label_type: ''
|
||||
element_label_class: ''
|
||||
element_label_colon: false
|
||||
element_wrapper_type: ''
|
||||
element_wrapper_class: ''
|
||||
element_default_classes: true
|
||||
empty: ''
|
||||
hide_empty: false
|
||||
empty_zero: false
|
||||
hide_alter_empty: true
|
||||
date_format: fallback
|
||||
custom_date_format: ''
|
||||
timezone: ''
|
||||
plugin_id: date
|
||||
filters: { }
|
||||
sorts:
|
||||
id:
|
||||
id: id
|
||||
table: views_test_data
|
||||
field: id
|
||||
relationship: none
|
||||
group_type: group
|
||||
admin_label: ''
|
||||
order: ASC
|
||||
exposed: false
|
||||
expose:
|
||||
label: ''
|
||||
plugin_id: standard
|
||||
title: 'CTools Views Test View'
|
||||
header: { }
|
||||
footer: { }
|
||||
empty: { }
|
||||
relationships: { }
|
||||
arguments: { }
|
||||
display_extenders: { }
|
||||
use_ajax: false
|
||||
filter_groups:
|
||||
operator: AND
|
||||
groups: { }
|
||||
cache_metadata:
|
||||
max-age: 0
|
||||
contexts:
|
||||
- 'languages:language_interface'
|
||||
tags: { }
|
||||
block_fields:
|
||||
display_plugin: block
|
||||
id: block_fields
|
||||
display_title: 'CTools Views Fields Block'
|
||||
position: 2
|
||||
display_options:
|
||||
display_extenders: { }
|
||||
block_category: 'CTools Views'
|
||||
allow:
|
||||
hide_fields: hide_fields
|
||||
sort_fields: sort_fields
|
||||
items_per_page: false
|
||||
offset: '0'
|
||||
pager: '0'
|
||||
disable_filters: '0'
|
||||
block_description: 'CTools Views Fields Block'
|
||||
display_description: ''
|
||||
pager:
|
||||
type: none
|
||||
options:
|
||||
offset: 0
|
||||
defaults:
|
||||
pager: false
|
||||
title: false
|
||||
fields: false
|
||||
title: 'CTools Views Fields Block'
|
||||
fields:
|
||||
id:
|
||||
id: id
|
||||
table: views_test_data
|
||||
field: id
|
||||
relationship: none
|
||||
group_type: group
|
||||
admin_label: ''
|
||||
label: ID
|
||||
exclude: false
|
||||
alter:
|
||||
alter_text: false
|
||||
text: ''
|
||||
make_link: false
|
||||
path: ''
|
||||
absolute: false
|
||||
external: false
|
||||
replace_spaces: false
|
||||
path_case: none
|
||||
trim_whitespace: false
|
||||
alt: ''
|
||||
rel: ''
|
||||
link_class: ''
|
||||
prefix: ''
|
||||
suffix: ''
|
||||
target: ''
|
||||
nl2br: false
|
||||
max_length: 0
|
||||
word_boundary: true
|
||||
ellipsis: true
|
||||
more_link: false
|
||||
more_link_text: ''
|
||||
more_link_path: ''
|
||||
strip_tags: false
|
||||
trim: false
|
||||
preserve_tags: ''
|
||||
html: false
|
||||
element_type: ''
|
||||
element_class: ''
|
||||
element_label_type: ''
|
||||
element_label_class: ''
|
||||
element_label_colon: false
|
||||
element_wrapper_type: ''
|
||||
element_wrapper_class: ''
|
||||
element_default_classes: true
|
||||
empty: ''
|
||||
hide_empty: false
|
||||
empty_zero: false
|
||||
hide_alter_empty: true
|
||||
set_precision: false
|
||||
precision: 0
|
||||
decimal: .
|
||||
separator: ''
|
||||
format_plural: false
|
||||
format_plural_string: "1\x03@count"
|
||||
prefix: ''
|
||||
suffix: ''
|
||||
entity_type: null
|
||||
entity_field: null
|
||||
plugin_id: numeric
|
||||
name:
|
||||
id: name
|
||||
table: views_test_data
|
||||
field: name
|
||||
relationship: none
|
||||
group_type: group
|
||||
admin_label: ''
|
||||
label: Name
|
||||
exclude: false
|
||||
alter:
|
||||
alter_text: false
|
||||
text: ''
|
||||
make_link: false
|
||||
path: ''
|
||||
absolute: false
|
||||
external: false
|
||||
replace_spaces: false
|
||||
path_case: none
|
||||
trim_whitespace: false
|
||||
alt: ''
|
||||
rel: ''
|
||||
link_class: ''
|
||||
prefix: ''
|
||||
suffix: ''
|
||||
target: ''
|
||||
nl2br: false
|
||||
max_length: 0
|
||||
word_boundary: true
|
||||
ellipsis: true
|
||||
more_link: false
|
||||
more_link_text: ''
|
||||
more_link_path: ''
|
||||
strip_tags: false
|
||||
trim: false
|
||||
preserve_tags: ''
|
||||
html: false
|
||||
element_type: ''
|
||||
element_class: ''
|
||||
element_label_type: ''
|
||||
element_label_class: ''
|
||||
element_label_colon: false
|
||||
element_wrapper_type: ''
|
||||
element_wrapper_class: ''
|
||||
element_default_classes: true
|
||||
empty: ''
|
||||
hide_empty: false
|
||||
empty_zero: false
|
||||
hide_alter_empty: true
|
||||
plugin_id: standard
|
||||
age:
|
||||
id: age
|
||||
table: views_test_data
|
||||
field: age
|
||||
relationship: none
|
||||
group_type: group
|
||||
admin_label: ''
|
||||
label: Age
|
||||
exclude: false
|
||||
alter:
|
||||
alter_text: false
|
||||
text: ''
|
||||
make_link: false
|
||||
path: ''
|
||||
absolute: false
|
||||
external: false
|
||||
replace_spaces: false
|
||||
path_case: none
|
||||
trim_whitespace: false
|
||||
alt: ''
|
||||
rel: ''
|
||||
link_class: ''
|
||||
prefix: ''
|
||||
suffix: ''
|
||||
target: ''
|
||||
nl2br: false
|
||||
max_length: 0
|
||||
word_boundary: true
|
||||
ellipsis: true
|
||||
more_link: false
|
||||
more_link_text: ''
|
||||
more_link_path: ''
|
||||
strip_tags: false
|
||||
trim: false
|
||||
preserve_tags: ''
|
||||
html: false
|
||||
element_type: ''
|
||||
element_class: ''
|
||||
element_label_type: ''
|
||||
element_label_class: ''
|
||||
element_label_colon: false
|
||||
element_wrapper_type: ''
|
||||
element_wrapper_class: ''
|
||||
element_default_classes: true
|
||||
empty: ''
|
||||
hide_empty: false
|
||||
empty_zero: false
|
||||
hide_alter_empty: true
|
||||
set_precision: false
|
||||
precision: 0
|
||||
decimal: .
|
||||
separator: ''
|
||||
format_plural: false
|
||||
format_plural_string: "1\x03@count"
|
||||
prefix: ''
|
||||
suffix: ''
|
||||
plugin_id: numeric
|
||||
job:
|
||||
id: job
|
||||
table: views_test_data
|
||||
field: job
|
||||
relationship: none
|
||||
group_type: group
|
||||
admin_label: ''
|
||||
label: Job
|
||||
exclude: false
|
||||
alter:
|
||||
alter_text: false
|
||||
text: ''
|
||||
make_link: false
|
||||
path: ''
|
||||
absolute: false
|
||||
external: false
|
||||
replace_spaces: false
|
||||
path_case: none
|
||||
trim_whitespace: false
|
||||
alt: ''
|
||||
rel: ''
|
||||
link_class: ''
|
||||
prefix: ''
|
||||
suffix: ''
|
||||
target: ''
|
||||
nl2br: false
|
||||
max_length: 0
|
||||
word_boundary: true
|
||||
ellipsis: true
|
||||
more_link: false
|
||||
more_link_text: ''
|
||||
more_link_path: ''
|
||||
strip_tags: false
|
||||
trim: false
|
||||
preserve_tags: ''
|
||||
html: false
|
||||
element_type: ''
|
||||
element_class: ''
|
||||
element_label_type: ''
|
||||
element_label_class: ''
|
||||
element_label_colon: false
|
||||
element_wrapper_type: ''
|
||||
element_wrapper_class: ''
|
||||
element_default_classes: true
|
||||
empty: ''
|
||||
hide_empty: false
|
||||
empty_zero: false
|
||||
hide_alter_empty: true
|
||||
plugin_id: standard
|
||||
created:
|
||||
id: created
|
||||
table: views_test_data
|
||||
field: created
|
||||
relationship: none
|
||||
group_type: group
|
||||
admin_label: ''
|
||||
label: Created
|
||||
exclude: false
|
||||
alter:
|
||||
alter_text: false
|
||||
text: ''
|
||||
make_link: false
|
||||
path: ''
|
||||
absolute: false
|
||||
external: false
|
||||
replace_spaces: false
|
||||
path_case: none
|
||||
trim_whitespace: false
|
||||
alt: ''
|
||||
rel: ''
|
||||
link_class: ''
|
||||
prefix: ''
|
||||
suffix: ''
|
||||
target: ''
|
||||
nl2br: false
|
||||
max_length: 0
|
||||
word_boundary: true
|
||||
ellipsis: true
|
||||
more_link: false
|
||||
more_link_text: ''
|
||||
more_link_path: ''
|
||||
strip_tags: false
|
||||
trim: false
|
||||
preserve_tags: ''
|
||||
html: false
|
||||
element_type: ''
|
||||
element_class: ''
|
||||
element_label_type: ''
|
||||
element_label_class: ''
|
||||
element_label_colon: false
|
||||
element_wrapper_type: ''
|
||||
element_wrapper_class: ''
|
||||
element_default_classes: true
|
||||
empty: ''
|
||||
hide_empty: false
|
||||
empty_zero: false
|
||||
hide_alter_empty: true
|
||||
date_format: fallback
|
||||
custom_date_format: ''
|
||||
timezone: ''
|
||||
plugin_id: date
|
||||
name_1:
|
||||
id: name_1
|
||||
table: views_test_data
|
||||
field: name
|
||||
relationship: none
|
||||
group_type: group
|
||||
admin_label: ''
|
||||
label: '2nd name field'
|
||||
exclude: false
|
||||
alter:
|
||||
alter_text: false
|
||||
text: ''
|
||||
make_link: false
|
||||
path: ''
|
||||
absolute: false
|
||||
external: false
|
||||
replace_spaces: false
|
||||
path_case: none
|
||||
trim_whitespace: false
|
||||
alt: ''
|
||||
rel: ''
|
||||
link_class: ''
|
||||
prefix: ''
|
||||
suffix: ''
|
||||
target: ''
|
||||
nl2br: false
|
||||
max_length: 0
|
||||
word_boundary: true
|
||||
ellipsis: true
|
||||
more_link: false
|
||||
more_link_text: ''
|
||||
more_link_path: ''
|
||||
strip_tags: false
|
||||
trim: false
|
||||
preserve_tags: ''
|
||||
html: false
|
||||
element_type: ''
|
||||
element_class: ''
|
||||
element_label_type: ''
|
||||
element_label_class: ''
|
||||
element_label_colon: false
|
||||
element_wrapper_type: ''
|
||||
element_wrapper_class: ''
|
||||
element_default_classes: true
|
||||
empty: ''
|
||||
hide_empty: false
|
||||
empty_zero: false
|
||||
hide_alter_empty: true
|
||||
plugin_id: standard
|
||||
cache_metadata:
|
||||
max-age: 0
|
||||
contexts:
|
||||
- 'languages:language_interface'
|
||||
tags: { }
|
||||
block_filter:
|
||||
display_plugin: block
|
||||
id: block_filter
|
||||
display_title: 'CTools Views Filter Block'
|
||||
position: 3
|
||||
display_options:
|
||||
display_extenders: { }
|
||||
display_description: ''
|
||||
block_category: 'CTools Views'
|
||||
block_description: 'CTools Views Filter Block'
|
||||
allow:
|
||||
disable_filters: disable_filters
|
||||
items_per_page: false
|
||||
offset: '0'
|
||||
pager: '0'
|
||||
hide_fields: '0'
|
||||
sort_fields: '0'
|
||||
filters:
|
||||
status:
|
||||
id: status
|
||||
table: views_test_data
|
||||
field: status
|
||||
relationship: none
|
||||
group_type: group
|
||||
admin_label: ''
|
||||
operator: '='
|
||||
value: true
|
||||
group: 1
|
||||
exposed: true
|
||||
expose:
|
||||
operator_id: ''
|
||||
label: Status
|
||||
description: ''
|
||||
use_operator: false
|
||||
operator: status_op
|
||||
identifier: status
|
||||
required: false
|
||||
remember: false
|
||||
multiple: false
|
||||
remember_roles:
|
||||
authenticated: authenticated
|
||||
anonymous: '0'
|
||||
administrator1: '0'
|
||||
administrator: '0'
|
||||
is_grouped: false
|
||||
group_info:
|
||||
label: ''
|
||||
description: ''
|
||||
identifier: ''
|
||||
optional: true
|
||||
widget: select
|
||||
multiple: false
|
||||
remember: false
|
||||
default_group: All
|
||||
default_group_multiple: { }
|
||||
group_items: { }
|
||||
plugin_id: boolean
|
||||
job:
|
||||
id: job
|
||||
table: views_test_data
|
||||
field: job
|
||||
relationship: none
|
||||
group_type: group
|
||||
admin_label: ''
|
||||
operator: '='
|
||||
value: ''
|
||||
group: 1
|
||||
exposed: true
|
||||
expose:
|
||||
operator_id: job_op
|
||||
label: Job
|
||||
description: ''
|
||||
use_operator: false
|
||||
operator: job_op
|
||||
identifier: job
|
||||
required: false
|
||||
remember: false
|
||||
multiple: false
|
||||
remember_roles:
|
||||
authenticated: authenticated
|
||||
anonymous: '0'
|
||||
administrator1: '0'
|
||||
administrator: '0'
|
||||
is_grouped: false
|
||||
group_info:
|
||||
label: ''
|
||||
description: ''
|
||||
identifier: ''
|
||||
optional: true
|
||||
widget: select
|
||||
multiple: false
|
||||
remember: false
|
||||
default_group: All
|
||||
default_group_multiple: { }
|
||||
group_items: { }
|
||||
plugin_id: string
|
||||
defaults:
|
||||
filters: false
|
||||
filter_groups: false
|
||||
title: false
|
||||
filter_groups:
|
||||
operator: AND
|
||||
groups:
|
||||
1: AND
|
||||
title: 'CTools Views Filter Block'
|
||||
cache_metadata:
|
||||
max-age: 0
|
||||
contexts:
|
||||
- 'languages:language_interface'
|
||||
- url
|
||||
tags: { }
|
||||
block_pager:
|
||||
display_plugin: block
|
||||
id: block_pager
|
||||
display_title: 'CTools Views Pager Block'
|
||||
position: 1
|
||||
display_options:
|
||||
display_extenders: { }
|
||||
block_description: 'CTools Views Pager Block'
|
||||
block_category: 'CTools Views'
|
||||
allow:
|
||||
items_per_page: true
|
||||
offset: offset
|
||||
pager: pager
|
||||
hide_fields: '0'
|
||||
sort_fields: '0'
|
||||
disable_filters: '0'
|
||||
display_description: ''
|
||||
header:
|
||||
result:
|
||||
id: result
|
||||
table: views
|
||||
field: result
|
||||
relationship: none
|
||||
group_type: group
|
||||
admin_label: ''
|
||||
empty: false
|
||||
content: "Displaying @start - @end of @total\nShowing @current_record_count records on page @current_page"
|
||||
plugin_id: result
|
||||
defaults:
|
||||
header: false
|
||||
pager: false
|
||||
title: false
|
||||
pager:
|
||||
type: mini
|
||||
options:
|
||||
items_per_page: 3
|
||||
offset: 0
|
||||
id: 0
|
||||
total_pages: null
|
||||
tags:
|
||||
previous: '‹ Previous'
|
||||
next: 'Next ›'
|
||||
expose:
|
||||
items_per_page: false
|
||||
items_per_page_label: 'Items per page'
|
||||
items_per_page_options: '5, 10, 25, 50'
|
||||
items_per_page_options_all: false
|
||||
items_per_page_options_all_label: '- All -'
|
||||
offset: false
|
||||
offset_label: Offset
|
||||
title: 'CTools Views Pager Block'
|
||||
cache_metadata:
|
||||
max-age: 0
|
||||
contexts:
|
||||
- 'languages:language_interface'
|
||||
- url.query_args
|
||||
tags: { }
|
||||
block_sort:
|
||||
display_plugin: block
|
||||
id: block_sort
|
||||
display_title: 'CTools Views Sort Block'
|
||||
position: 4
|
||||
display_options:
|
||||
display_extenders: { }
|
||||
display_description: ''
|
||||
title: 'CTools Views Sort Block'
|
||||
defaults:
|
||||
title: false
|
||||
block_description: 'CTools Views Sort Block'
|
||||
block_category: 'CTools Views'
|
||||
allow:
|
||||
configure_sorts: configure_sorts
|
||||
items_per_page: false
|
||||
offset: '0'
|
||||
pager: '0'
|
||||
hide_fields: '0'
|
||||
sort_fields: '0'
|
||||
disable_filters: '0'
|
||||
cache_metadata:
|
||||
max-age: 0
|
||||
contexts:
|
||||
- 'languages:language_interface'
|
||||
tags: { }
|
|
@ -0,0 +1,367 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\ctools_views\Functional;
|
||||
|
||||
use Drupal\Tests\views_ui\Functional\UITestBase;
|
||||
use Drupal\views\Tests\ViewTestData;
|
||||
use Drupal\Core\StringTranslation\StringTranslationTrait;
|
||||
|
||||
/**
|
||||
* Tests ctools_views block display plugin overrides settings from a basic View.
|
||||
*
|
||||
* @group ctools_views
|
||||
* @see \Drupal\ctools_views\Plugin\Display\Block
|
||||
*/
|
||||
class CToolsViewsBasicViewBlockTest extends UITestBase {
|
||||
|
||||
use StringTranslationTrait;
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = ['ctools_views', 'ctools_views_test_views'];
|
||||
|
||||
/**
|
||||
* Views used by this test.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $testViews = ['ctools_views_test_view'];
|
||||
|
||||
/**
|
||||
* The block storage.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityStorageInterface
|
||||
*/
|
||||
protected $storage;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected $defaultTheme = 'classy';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp($import_test_views = TRUE) {
|
||||
parent::setUp($import_test_views);
|
||||
|
||||
ViewTestData::createTestViews(get_class($this), ['ctools_views_test_views']);
|
||||
$this->storage = $this->container->get('entity_type.manager')->getStorage('block');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test ctools_views "items_per_page" configuration.
|
||||
*/
|
||||
public function testItemsPerPage() {
|
||||
$default_theme = $this->config('system.theme')->get('default');
|
||||
|
||||
// Get the "Configure block" form for our Views block.
|
||||
$this->drupalGet('admin/structure/block/add/views_block:ctools_views_test_view-block_pager/' . $default_theme);
|
||||
$this->assertNotEmpty($this->xpath('//input[@type="number" and @name="settings[override][items_per_page]"]'), 'items_per_page setting is a number field');
|
||||
// Add block to sidebar_first region with default settings.
|
||||
$edit = [];
|
||||
$edit['region'] = 'sidebar_first';
|
||||
$edit['settings[override][items_per_page]'] = 0;
|
||||
$this->drupalPostForm('admin/structure/block/add/views_block:ctools_views_test_view-block_pager/' . $default_theme, $edit, $this->t('Save block'));
|
||||
|
||||
// Assert items per page default settings.
|
||||
$this->drupalGet('<front>');
|
||||
$result = $this->xpath('//div[contains(@class, "region-sidebar-first")]/div[contains(@class, "block-views")]/h2');
|
||||
$this->assertEquals('CTools Views Pager Block', $result[0]->getText());
|
||||
$this->assertSession()->pageTextContains('Showing 3 records on page 1');
|
||||
$this->assertEquals(3, count($this->xpath('//div[contains(@class, "view-display-id-block_pager")]//table/tbody/tr')));
|
||||
|
||||
// Override items per page settings.
|
||||
$edit = [];
|
||||
$edit['region'] = 'sidebar_first';
|
||||
$edit['settings[override][items_per_page]'] = 2;
|
||||
$this->drupalPostForm('admin/structure/block/manage/views_block__ctools_views_test_view_block_pager', $edit, $this->t('Save block'));
|
||||
|
||||
$block = $this->storage->load('views_block__ctools_views_test_view_block_pager');
|
||||
$config = $block->getPlugin()->getConfiguration();
|
||||
$this->assertEquals(2, $config['items_per_page'], "'Items per page' is properly saved.");
|
||||
|
||||
// Assert items per page overridden settings.
|
||||
$this->drupalGet('<front>');
|
||||
$result = $this->xpath('//div[contains(@class, "region-sidebar-first")]/div[contains(@class, "block-views")]/h2');
|
||||
$this->assertEquals('CTools Views Pager Block', $result[0]->getText());
|
||||
$this->assertSession()->pageTextContains('Showing 2 records on page 1');
|
||||
$this->assertEquals(2, count($this->xpath('//div[contains(@class, "view-display-id-block_pager")]//table/tbody/tr')));
|
||||
$elements = $this->xpath('//div[contains(@class, "view-display-id-block_pager")]//table//tr//td[contains(@class, "views-field-id")]');
|
||||
$results = array_map(function ($element) {
|
||||
return $element->getText();
|
||||
}, $elements);
|
||||
$this->assertEquals([1, 2], $results);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test ctools_views "offset" configuration.
|
||||
*/
|
||||
public function testOffset() {
|
||||
$default_theme = $this->config('system.theme')->get('default');
|
||||
|
||||
// Get the "Configure block" form for our Views block.
|
||||
$this->drupalGet('admin/structure/block/add/views_block:ctools_views_test_view-block_pager/' . $default_theme);
|
||||
$this->assertNotEmpty($this->xpath('//input[@type="number" and @name="settings[override][pager_offset]"]'), 'items_per_page setting is a number field');
|
||||
// Add block to sidebar_first region with default settings.
|
||||
$edit = [];
|
||||
$edit['region'] = 'sidebar_first';
|
||||
$edit['settings[override][items_per_page]'] = 0;
|
||||
$this->drupalPostForm('admin/structure/block/add/views_block:ctools_views_test_view-block_pager/' . $default_theme, $edit, $this->t('Save block'));
|
||||
|
||||
// Assert pager offset default settings.
|
||||
$this->drupalGet('<front>');
|
||||
$elements = $this->xpath('//div[contains(@class, "view-display-id-block_pager")]//table//tr//td[contains(@class, "views-field-id")]');
|
||||
$results = array_map(function ($element) {
|
||||
return $element->getText();
|
||||
}, $elements);
|
||||
$this->assertEquals([1, 2, 3], $results);
|
||||
|
||||
// Override pager offset settings.
|
||||
$edit = [];
|
||||
$edit['region'] = 'sidebar_first';
|
||||
$edit['settings[override][items_per_page]'] = 0;
|
||||
$edit['settings[override][pager_offset]'] = 1;
|
||||
$this->drupalPostForm('admin/structure/block/manage/views_block__ctools_views_test_view_block_pager', $edit, $this->t('Save block'));
|
||||
|
||||
$block = $this->storage->load('views_block__ctools_views_test_view_block_pager');
|
||||
$config = $block->getPlugin()->getConfiguration();
|
||||
$this->assertEquals(1, $config['pager_offset'], "'Pager offset' is properly saved.");
|
||||
|
||||
// Assert pager offset overridden settings.
|
||||
$this->drupalGet('<front>');
|
||||
$elements = $this->xpath('//div[contains(@class, "view-display-id-block_pager")]//table//tr//td[contains(@class, "views-field-id")]');
|
||||
$results = array_map(function ($element) {
|
||||
return $element->getText();
|
||||
}, $elements);
|
||||
$this->assertEquals([2, 3, 4], $results);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test ctools_views "pager" configuration.
|
||||
*/
|
||||
public function testPager() {
|
||||
$default_theme = $this->config('system.theme')->get('default');
|
||||
|
||||
// Get the "Configure block" form for our Views block.
|
||||
$this->drupalGet('admin/structure/block/add/views_block:ctools_views_test_view-block_pager/' . $default_theme);
|
||||
$this->assertSession()->fieldValueEquals('edit-settings-override-pager-view', 'view');
|
||||
$this->assertSession()->fieldExists('edit-settings-override-pager-some');
|
||||
$this->assertSession()->fieldExists('edit-settings-override-pager-none');
|
||||
|
||||
// Add block to sidebar_first region with default settings.
|
||||
$edit = [];
|
||||
$edit['region'] = 'sidebar_first';
|
||||
$edit['settings[override][items_per_page]'] = 0;
|
||||
$this->drupalPostForm('admin/structure/block/add/views_block:ctools_views_test_view-block_pager/' . $default_theme, $edit, $this->t('Save block'));
|
||||
|
||||
// Assert pager default settings.
|
||||
$this->drupalGet('<front>');
|
||||
$this->assertSession()->pageTextContains('Page 1');
|
||||
$this->assertSession()->pageTextContains('Next ›');
|
||||
|
||||
// Override pager settings to 'some'.
|
||||
$edit = [];
|
||||
$edit['region'] = 'sidebar_first';
|
||||
$edit['settings[override][items_per_page]'] = 0;
|
||||
$edit['settings[override][pager]'] = 'some';
|
||||
$this->drupalPostForm('admin/structure/block/manage/views_block__ctools_views_test_view_block_pager', $edit, $this->t('Save block'));
|
||||
|
||||
$block = $this->storage->load('views_block__ctools_views_test_view_block_pager');
|
||||
$config = $block->getPlugin()->getConfiguration();
|
||||
$this->assertEquals('some', $config['pager'], "'Pager' setting is properly saved.");
|
||||
|
||||
// Assert pager overridden settings to 'some', showing no pager.
|
||||
$this->drupalGet('<front>');
|
||||
$this->assertEquals(3, count($this->xpath('//div[contains(@class, "view-display-id-block_pager")]//table/tbody/tr')));
|
||||
$this->assertSession()->elementNotExists('css', '#block-views-block-ctools-views-test-view-block-pager .pager');
|
||||
|
||||
// Override pager settings to 'none'.
|
||||
$edit = [];
|
||||
$edit['region'] = 'sidebar_first';
|
||||
$edit['settings[override][items_per_page]'] = 0;
|
||||
$edit['settings[override][pager]'] = 'none';
|
||||
$this->drupalPostForm('admin/structure/block/manage/views_block__ctools_views_test_view_block_pager', $edit, $this->t('Save block'));
|
||||
|
||||
$block = $this->storage->load('views_block__ctools_views_test_view_block_pager');
|
||||
$config = $block->getPlugin()->getConfiguration();
|
||||
$this->assertEquals('none', $config['pager'], "'Pager' setting is properly saved.");
|
||||
|
||||
// Assert pager overridden settings to 'some', showing no pager.
|
||||
$this->drupalGet('<front>');
|
||||
$this->assertEquals(5, count($this->xpath('//div[contains(@class, "view-display-id-block_pager")]//table/tbody/tr')));
|
||||
$this->assertSession()->elementNotExists('css', '#block-views-block-ctools-views-test-view-block-pager .pager');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test ctools_views 'hide_fields' configuration.
|
||||
*/
|
||||
public function testHideFields() {
|
||||
$default_theme = $this->config('system.theme')->get('default');
|
||||
|
||||
// Get the "Configure block" form for our Views block.
|
||||
$this->drupalGet('admin/structure/block/add/views_block:ctools_views_test_view-block_fields/' . $default_theme);
|
||||
$this->assertSession()->fieldExists('edit-settings-override-order-fields-id-hide');
|
||||
|
||||
// Add block to sidebar_first region with default settings.
|
||||
$edit = [];
|
||||
$edit['region'] = 'sidebar_first';
|
||||
$this->drupalPostForm('admin/structure/block/add/views_block:ctools_views_test_view-block_fields/' . $default_theme, $edit, $this->t('Save block'));
|
||||
|
||||
// Assert hide_fields default settings.
|
||||
$this->drupalGet('<front>');
|
||||
$this->assertEquals(5, count($this->xpath('//div[contains(@class, "view-display-id-block_fields")]//table//td[contains(@class, "views-field-id")]')));
|
||||
|
||||
// Override hide_fields settings.
|
||||
$edit = [];
|
||||
$edit['region'] = 'sidebar_first';
|
||||
$edit['settings[override][order_fields][id][hide]'] = 1;
|
||||
$this->drupalPostForm('admin/structure/block/manage/views_block__ctools_views_test_view_block_fields', $edit, $this->t('Save block'));
|
||||
|
||||
$block = $this->storage->load('views_block__ctools_views_test_view_block_fields');
|
||||
$config = $block->getPlugin()->getConfiguration();
|
||||
$this->assertEquals(1, $config['fields']['id']['hide'], "'hide_fields' setting is properly saved.");
|
||||
$this->assertEquals(0, $config['fields']['name']['hide'], "'hide_fields' setting is properly saved.");
|
||||
|
||||
// Assert hide_fields overridden settings.
|
||||
$this->drupalGet('<front>');
|
||||
$this->assertEquals(0, count($this->xpath('//div[contains(@class, "view-display-id-block_fields")]//table//td[contains(@class, "views-field-id")]')));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test ctools_views 'sort_fields' configuration.
|
||||
*/
|
||||
public function testOrderFields() {
|
||||
$default_theme = $this->config('system.theme')->get('default');
|
||||
|
||||
// Get the "Configure block" form for our Views block.
|
||||
$this->drupalGet('admin/structure/block/add/views_block:ctools_views_test_view-block_fields/' . $default_theme);
|
||||
$this->assertSession()->fieldValueEquals('edit-settings-override-order-fields-id-weight', 0);
|
||||
|
||||
// Add block to sidebar_first region with default settings.
|
||||
$edit = [];
|
||||
$edit['region'] = 'sidebar_first';
|
||||
$this->drupalPostForm('admin/structure/block/add/views_block:ctools_views_test_view-block_fields/' . $default_theme, $edit, $this->t('Save block'));
|
||||
|
||||
// Assert sort_fields default settings.
|
||||
$this->drupalGet('<front>');
|
||||
// Check that the td with class "views-field-id" is the first td in the
|
||||
// first tr element.
|
||||
$this->assertEquals(0, count($this->xpath('//div[contains(@class, "view-display-id-block_fields")]//table//tr[1]//td[contains(@class, "views-field-id")]/preceding-sibling::td')));
|
||||
|
||||
// Override sort_fields settings.
|
||||
$edit = [];
|
||||
$edit['region'] = 'sidebar_first';
|
||||
$edit['settings[override][order_fields][name][weight]'] = -50;
|
||||
$edit['settings[override][order_fields][age][weight]'] = -49;
|
||||
$edit['settings[override][order_fields][job][weight]'] = -48;
|
||||
$edit['settings[override][order_fields][created][weight]'] = -47;
|
||||
$edit['settings[override][order_fields][id][weight]'] = -46;
|
||||
$edit['settings[override][order_fields][name_1][weight]'] = -45;
|
||||
$this->drupalPostForm('admin/structure/block/manage/views_block__ctools_views_test_view_block_fields', $edit, $this->t('Save block'));
|
||||
|
||||
$block = $this->storage->load('views_block__ctools_views_test_view_block_fields');
|
||||
$config = $block->getPlugin()->getConfiguration();
|
||||
$this->assertEquals(-46, $config['fields']['id']['weight'], "'sort_fields' setting is properly saved.");
|
||||
$this->assertEquals(-50, $config['fields']['name']['weight'], "'sort_fields' setting is properly saved.");
|
||||
|
||||
// Assert sort_fields overridden settings.
|
||||
$this->drupalGet('<front>');
|
||||
|
||||
// Check that the td with class "views-field-id" is the 5th td in the first
|
||||
// tr element.
|
||||
$this->assertEquals(4, count($this->xpath('//div[contains(@class, "view-display-id-block_fields")]//table//tr[1]//td[contains(@class, "views-field-id")]/preceding-sibling::td')));
|
||||
|
||||
// Check that duplicate fields in the View produce expected output.
|
||||
$name1_element = $this->xpath('//div[contains(@class, "view-display-id-block_fields")]//table//tr[1]/td[contains(@class, "views-field-name")]');
|
||||
$name1 = $name1_element[0]->getText();
|
||||
$this->assertEquals('John', trim($name1));
|
||||
$name2_element = $this->xpath('//div[contains(@class, "view-display-id-block_fields")]//table//tr[1]/td[contains(@class, "views-field-name-1")]');
|
||||
$name2 = $name2_element[0]->getText();
|
||||
$this->assertEquals('John', trim($name2));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test ctools_views 'disable_filters' configuration.
|
||||
*/
|
||||
public function testDisableFilters() {
|
||||
$default_theme = $this->config('system.theme')->get('default');
|
||||
|
||||
// Get the "Configure block" form for our Views block.
|
||||
$this->drupalGet('admin/structure/block/add/views_block:ctools_views_test_view-block_filter/' . $default_theme);
|
||||
$this->assertSession()->fieldExists('edit-settings-override-filters-status-disable');
|
||||
$this->assertSession()->fieldExists('edit-settings-override-filters-job-disable');
|
||||
|
||||
// Add block to sidebar_first region with default settings.
|
||||
$edit = [];
|
||||
$edit['region'] = 'sidebar_first';
|
||||
$this->drupalPostForm('admin/structure/block/add/views_block:ctools_views_test_view-block_filter/' . $default_theme, $edit, $this->t('Save block'));
|
||||
|
||||
// Assert disable_filters default settings.
|
||||
$this->drupalGet('<front>');
|
||||
// Check that the default settings show both filters.
|
||||
$this->assertSession()->fieldExists('status');
|
||||
$this->assertSession()->fieldExists('job');
|
||||
|
||||
// Override disable_filters settings.
|
||||
$edit = [];
|
||||
$edit['region'] = 'sidebar_first';
|
||||
$edit['settings[override][filters][status][disable]'] = 1;
|
||||
$edit['settings[override][filters][job][disable]'] = 1;
|
||||
$this->drupalPostForm('admin/structure/block/manage/views_block__ctools_views_test_view_block_filter', $edit, $this->t('Save block'));
|
||||
|
||||
$block = $this->storage->load('views_block__ctools_views_test_view_block_filter');
|
||||
$config = $block->getPlugin()->getConfiguration();
|
||||
$this->assertEquals(1, $config['filter']['status']['disable'], "'disable_filters' setting is properly saved.");
|
||||
$this->assertEquals(1, $config['filter']['job']['disable'], "'disable_filters' setting is properly saved.");
|
||||
|
||||
// Assert disable_filters overridden settings.
|
||||
$this->drupalGet('<front>');
|
||||
$this->assertSession()->fieldNotExists('status');
|
||||
$this->assertSession()->fieldNotExists('job');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test ctools_views 'configure_sorts' configuration.
|
||||
*/
|
||||
public function testConfigureSorts() {
|
||||
$default_theme = $this->config('system.theme')->get('default');
|
||||
|
||||
// Get the "Configure block" form for our Views block.
|
||||
$this->drupalGet('admin/structure/block/add/views_block:ctools_views_test_view-block_sort/' . $default_theme);
|
||||
$this->assertSession()->fieldExists('settings[override][sort][id][order]');
|
||||
|
||||
// Add block to sidebar_first region with default settings.
|
||||
$edit = [];
|
||||
$edit['region'] = 'sidebar_first';
|
||||
$this->drupalPostForm('admin/structure/block/add/views_block:ctools_views_test_view-block_sort/' . $default_theme, $edit, $this->t('Save block'));
|
||||
|
||||
// Assert configure_sorts default settings.
|
||||
$this->drupalGet('<front>');
|
||||
// Check that the results are sorted ASC.
|
||||
$element = $this->xpath('//div[contains(@class, "view-display-id-block_sort")]//table//tr[1]/td[1]');
|
||||
$value = $element[0]->getText();
|
||||
$this->assertEquals('1', trim($value));
|
||||
|
||||
// Override configure_sorts settings.
|
||||
$edit = [];
|
||||
$edit['region'] = 'sidebar_first';
|
||||
$edit['settings[override][sort][id][order]'] = 'DESC';
|
||||
$this->drupalPostForm('admin/structure/block/manage/views_block__ctools_views_test_view_block_sort', $edit, $this->t('Save block'));
|
||||
|
||||
$block = $this->storage->load('views_block__ctools_views_test_view_block_sort');
|
||||
$config = $block->getPlugin()->getConfiguration();
|
||||
$this->assertEquals('DESC', $config['sort']['id'], "'configure_sorts' setting is properly saved.");
|
||||
|
||||
// Assert configure_sorts overridden settings.
|
||||
// Check that the results are sorted DESC.
|
||||
$this->drupalGet('<front>');
|
||||
$element = $this->xpath('//div[contains(@class, "view-display-id-block_sort")]//table//tr[1]/td[1]');
|
||||
$value = $element[0]->getText();
|
||||
$this->assertEquals('5', trim($value));
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Plugin to provide access control based on node.
|
||||
*/
|
|
@ -0,0 +1,9 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\ctools\Access;
|
||||
|
||||
use Drupal\Core\Session\AccountInterface;
|
||||
|
||||
interface AccessInterface {
|
||||
public function access(AccountInterface $account);
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\ctools\Access;
|
||||
|
||||
use Drupal\Core\Access\AccessResult;
|
||||
use Drupal\Core\Routing\Access\AccessInterface as CoreAccessInterface;
|
||||
use Drupal\Core\Routing\RouteMatchInterface;
|
||||
use Drupal\Core\Session\AccountInterface;
|
||||
use Drupal\ctools\Access\AccessInterface as CToolsAccessInterface;
|
||||
use Drupal\Core\TempStore\SharedTempStoreFactory;
|
||||
use Symfony\Component\Routing\Route;
|
||||
|
||||
|
||||
class TempstoreAccess implements CoreAccessInterface {
|
||||
|
||||
/**
|
||||
* The shared tempstore factory.
|
||||
*
|
||||
* @var \Drupal\Core\TempStore\SharedTempStoreFactory
|
||||
*/
|
||||
protected $tempstore;
|
||||
|
||||
|
||||
public function __construct(SharedTempStoreFactory $tempstore) {
|
||||
$this->tempstore = $tempstore;
|
||||
}
|
||||
|
||||
|
||||
protected function getTempstore() {
|
||||
return $this->tempstore;
|
||||
}
|
||||
|
||||
|
||||
public function access(Route $route, RouteMatchInterface $match, AccountInterface $account) {
|
||||
$tempstore_id = $match->getParameter('tempstore_id') ? $match->getParameter('tempstore_id') : $route->getDefault('tempstore_id');
|
||||
$id = $match->getParameter($route->getRequirement('_ctools_access'));
|
||||
if ($tempstore_id && $id) {
|
||||
$cached_values = $this->getTempstore()->get($tempstore_id)->get($id);
|
||||
if (!empty($cached_values['access']) && ($cached_values['access'] instanceof CToolsAccessInterface)) {
|
||||
$access = $cached_values['access']->access($account);
|
||||
}
|
||||
else {
|
||||
$access = AccessResult::allowed();
|
||||
}
|
||||
}
|
||||
else {
|
||||
$access = AccessResult::forbidden();
|
||||
}
|
||||
// The different wizards will have different tempstore ids and adding this
|
||||
// cache context allows us to nuance the access per wizard.
|
||||
$access->addCacheContexts(['url.query_args:tempstore_id']);
|
||||
return $access;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\ctools\Ajax;
|
||||
|
||||
use Drupal\Core\Ajax\OpenModalDialogCommand;
|
||||
|
||||
|
||||
class OpenModalWizardCommand extends OpenModalDialogCommand {
|
||||
|
||||
|
||||
public function __construct($object, $tempstore_id, array $parameters = [], array $dialog_options = [], $settings = NULL) {
|
||||
// Instantiate the wizard class properly.
|
||||
$parameters += [
|
||||
'tempstore_id' => $tempstore_id,
|
||||
'machine_name' => NULL,
|
||||
'step' => NULL,
|
||||
];
|
||||
$form = \Drupal::service('ctools.wizard.factory')->getWizardForm($object, $parameters, TRUE);
|
||||
$title = isset($form['#title']) ? $form['#title'] : '';
|
||||
$content = $form;
|
||||
|
||||
parent::__construct($title, $content, $dialog_options, $settings);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,54 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\ctools\Annotation;
|
||||
|
||||
use Drupal\Component\Annotation\Plugin;
|
||||
|
||||
/**
|
||||
* Defines a Relationship item annotation object.
|
||||
*
|
||||
* @see \Drupal\ctools\Plugin\RelationshipManager
|
||||
* @see plugin_api
|
||||
*
|
||||
* @Annotation
|
||||
*/
|
||||
class Relationship extends Plugin {
|
||||
|
||||
/**
|
||||
* The plugin ID.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $id;
|
||||
|
||||
/**
|
||||
* The label of the plugin.
|
||||
*
|
||||
* @var \Drupal\Core\Annotation\Translation
|
||||
*
|
||||
* @ingroup plugin_translatable
|
||||
*/
|
||||
public $label;
|
||||
|
||||
/**
|
||||
* The returned data type of this relationship.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $data_type;
|
||||
|
||||
/**
|
||||
* The name of the property from which this relationship is derived.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $property_name;
|
||||
|
||||
/**
|
||||
* The array of contexts requires or optional for this plugin.
|
||||
*
|
||||
* @var \Drupal\Core\Plugin\Context\ContextInterface[]
|
||||
*/
|
||||
public $context;
|
||||
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\ctools;
|
||||
|
||||
|
||||
interface ConstraintConditionInterface {
|
||||
|
||||
/**
|
||||
* Applies relevant constraints for this condition to the injected contexts.
|
||||
*
|
||||
* @param \Drupal\Core\Plugin\Context\ContextInterface[] $contexts
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
public function applyConstraints(array $contexts = []);
|
||||
|
||||
/**
|
||||
* Removes constraints for this condition from the injected contexts.
|
||||
*
|
||||
* @param \Drupal\Core\Plugin\Context\ContextInterface[] $contexts
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
public function removeConstraints(array $contexts = []);
|
||||
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\ctools\Context;
|
||||
|
||||
use Drupal\Core\Plugin\Context\Context;
|
||||
|
||||
/**
|
||||
* Provides a class to indicate that this context is always present.
|
||||
*
|
||||
* @internal
|
||||
*
|
||||
* @todo Move into core.
|
||||
*/
|
||||
class AutomaticContext extends Context {
|
||||
|
||||
/**
|
||||
* Returns TRUE if this context is automatic and always available.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isAutomatic() {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,66 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\ctools\Context;
|
||||
|
||||
use Drupal\Core\Entity\EntityRepositoryInterface;
|
||||
use Drupal\Core\Plugin\Context\Context;
|
||||
use Drupal\Core\Plugin\Context\ContextDefinitionInterface;
|
||||
|
||||
/**
|
||||
* Defines context that loads entity on demand.
|
||||
*/
|
||||
class EntityLazyLoadContext extends Context {
|
||||
|
||||
/**
|
||||
* The entity UUID.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $uuid;
|
||||
|
||||
/**
|
||||
* The entity repository.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityRepositoryInterface
|
||||
*/
|
||||
protected $entityRepository;
|
||||
|
||||
/**
|
||||
* Construct an EntityLazyLoadContext object.
|
||||
*
|
||||
* @param \Drupal\Core\Plugin\Context\ContextDefinitionInterface $context_definition
|
||||
* The context definition.
|
||||
* @param \Drupal\Core\Entity\EntityRepositoryInterface $entity_repository
|
||||
* The entity repository.
|
||||
* @param string $uuid
|
||||
* The UUID of the entity.
|
||||
*/
|
||||
public function __construct(ContextDefinitionInterface $context_definition, EntityRepositoryInterface $entity_repository, $uuid) {
|
||||
parent::__construct($context_definition);
|
||||
$this->entityRepository = $entity_repository;
|
||||
$this->uuid = $uuid;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getContextValue() {
|
||||
if (!$this->contextData) {
|
||||
$entity_type_id = substr($this->contextDefinition->getDataType(), 7);
|
||||
$this->setContextValue($this->entityRepository->loadEntityByUuid($entity_type_id, $this->uuid));
|
||||
}
|
||||
return parent::getContextValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function hasContextValue() {
|
||||
// Ensure that the entity is loaded before checking if it exists.
|
||||
if (!$this->contextData) {
|
||||
$this->getContextValue();
|
||||
}
|
||||
return parent::hasContextValue();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\ctools;
|
||||
|
||||
use Drupal\Core\Entity\EntityRepositoryInterface;
|
||||
use Drupal\Core\Plugin\Context\Context;
|
||||
use Drupal\Core\Plugin\Context\ContextDefinition;
|
||||
use Drupal\Core\Plugin\Context\EntityContextDefinition;
|
||||
use Drupal\ctools\Context\EntityLazyLoadContext;
|
||||
|
||||
/**
|
||||
* Maps context configurations to context objects.
|
||||
*/
|
||||
class ContextMapper implements ContextMapperInterface {
|
||||
|
||||
/**
|
||||
* The entity repository.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityRepositoryInterface
|
||||
*/
|
||||
protected $entityRepository;
|
||||
|
||||
/**
|
||||
* Constructs a new ContextMapper.
|
||||
*
|
||||
* @param \Drupal\Core\Entity\EntityRepositoryInterface $entity_repository
|
||||
* The entity repository.
|
||||
*/
|
||||
public function __construct(EntityRepositoryInterface $entity_repository) {
|
||||
$this->entityRepository = $entity_repository;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getContextValues(array $context_configurations) {
|
||||
$contexts = [];
|
||||
foreach ($context_configurations as $name => $context_configuration) {
|
||||
if (strpos($context_configuration['type'], 'entity:') === 0) {
|
||||
$context_definition = new EntityContextDefinition($context_configuration['type'], $context_configuration['label'], TRUE, FALSE, $context_configuration['description']);
|
||||
$context = new EntityLazyLoadContext($context_definition, $this->entityRepository, $context_configuration['value']);
|
||||
}
|
||||
else {
|
||||
$context_definition = new ContextDefinition($context_configuration['type'], $context_configuration['label'], TRUE, FALSE, $context_configuration['description']);
|
||||
$context = new Context($context_definition, $context_configuration['value']);
|
||||
}
|
||||
$contexts[$name] = $context;
|
||||
}
|
||||
return $contexts;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\ctools;
|
||||
|
||||
/**
|
||||
* Provides an interface for mapping context configurations to context objects.
|
||||
*/
|
||||
interface ContextMapperInterface {
|
||||
|
||||
/**
|
||||
* Gathers the static context values.
|
||||
*
|
||||
* @param array[] $static_context_configurations
|
||||
* An array of static context configurations.
|
||||
*
|
||||
* @return \Drupal\Component\Plugin\Context\ContextInterface[]
|
||||
* An array of set context values, keyed by context name.
|
||||
*/
|
||||
public function getContextValues(array $static_context_configurations);
|
||||
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\ctools;
|
||||
|
||||
|
||||
class ContextNotFoundException extends \Exception {}
|
|
@ -0,0 +1,52 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\ctools\Controller;
|
||||
|
||||
use Drupal\Core\Entity\EntityTypeManagerInterface;
|
||||
use Drupal\Core\Form\FormBuilderInterface;
|
||||
use Drupal\Core\Routing\RouteMatchInterface;
|
||||
use Drupal\ctools\Wizard\WizardFactoryInterface;
|
||||
use Symfony\Component\HttpKernel\Controller\ArgumentResolverInterface;
|
||||
|
||||
/**
|
||||
* Wrapping controller for wizard forms that serve as the main page body.
|
||||
*/
|
||||
class WizardEntityFormController extends WizardFormController {
|
||||
|
||||
/**
|
||||
* The entity type manager.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
|
||||
*/
|
||||
protected $entityTypeManager;
|
||||
|
||||
/**
|
||||
* @param \Symfony\Component\HttpKernel\Controller\ArgumentResolverInterface $argument_resolver
|
||||
* The argument resolver.
|
||||
* @param \Drupal\Core\Form\FormBuilderInterface $form_builder
|
||||
* The form builder.
|
||||
* @param \Drupal\ctools\Wizard\WizardFactoryInterface $wizard_factory
|
||||
* The wizard factory.
|
||||
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
|
||||
* The entity type manager.
|
||||
*/
|
||||
public function __construct(ArgumentResolverInterface $argument_resolver, FormBuilderInterface $form_builder, WizardFactoryInterface $wizard_factory, EntityTypeManagerInterface $entity_type_manager) {
|
||||
parent::__construct($argument_resolver, $form_builder, $wizard_factory);
|
||||
$this->entityTypeManager = $entity_type_manager;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getFormArgument(RouteMatchInterface $route_match) {
|
||||
$form_arg = $route_match->getRouteObject()->getDefault('_entity_wizard');
|
||||
list($entity_type_id, $operation) = explode('.', $form_arg);
|
||||
$definition = $this->entityTypeManager->getDefinition($entity_type_id);
|
||||
$handlers = $definition->getHandlerClasses();
|
||||
if (empty($handlers['wizard'][$operation])) {
|
||||
throw new \Exception(sprintf('Unsupported wizard operation %s', $operation));
|
||||
}
|
||||
return $handlers['wizard'][$operation];
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,81 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\ctools\Controller;
|
||||
|
||||
use Drupal\Core\Controller\FormController;
|
||||
use Drupal\Core\Form\FormBuilderInterface;
|
||||
use Drupal\Core\Routing\RouteMatchInterface;
|
||||
use Drupal\ctools\Wizard\WizardFactoryInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpKernel\Controller\ArgumentResolverInterface;
|
||||
|
||||
/**
|
||||
* Wrapping controller for wizard forms that serve as the main page body.
|
||||
*/
|
||||
class WizardFormController extends FormController {
|
||||
|
||||
/**
|
||||
* The class resolver.
|
||||
*
|
||||
* @var \Drupal\Core\DependencyInjection\ClassResolverInterface
|
||||
*/
|
||||
protected $classResolver;
|
||||
|
||||
/**
|
||||
* Tempstore Factory for keeping track of values in each step of the wizard.
|
||||
*
|
||||
* @var \Drupal\Core\TempStore\SharedTempStoreFactory
|
||||
*/
|
||||
protected $tempstore;
|
||||
|
||||
/**
|
||||
* The event dispatcher.
|
||||
*
|
||||
* @var \Symfony\Component\EventDispatcher\EventDispatcherInterface
|
||||
*/
|
||||
protected $dispatcher;
|
||||
|
||||
/**
|
||||
* @param \Symfony\Component\HttpKernel\Controller\ArgumentResolverInterface $argument_resolver
|
||||
* The argument resolver.
|
||||
* @param \Drupal\Core\Form\FormBuilderInterface $form_builder
|
||||
* The form builder.
|
||||
* @param \Drupal\ctools\Wizard\WizardFactoryInterface $wizard_factory
|
||||
* The wizard factory.
|
||||
*/
|
||||
public function __construct(ArgumentResolverInterface $argument_resolver, FormBuilderInterface $form_builder, WizardFactoryInterface $wizard_factory) {
|
||||
parent::__construct($argument_resolver, $form_builder);
|
||||
$this->wizardFactory = $wizard_factory;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getFormArgument(RouteMatchInterface $route_match) {
|
||||
return $route_match->getRouteObject()->getDefault('_wizard');
|
||||
}
|
||||
|
||||
/**
|
||||
* Wizards are not instantiated as simply as forms, so this method is unused.
|
||||
*/
|
||||
protected function getFormObject(RouteMatchInterface $route_match, $form_arg) {
|
||||
if (!is_subclass_of($form_arg, '\Drupal\ctools\Wizard\FormWizardInterface')) {
|
||||
throw new \Exception("The _wizard default must reference a class instance of \\Drupal\\ctools\\Wizard\\FormWizardInterface.");
|
||||
}
|
||||
$parameters = $route_match->getParameters()->all();
|
||||
$parameters += $form_arg::getParameters();
|
||||
$parameters['route_match'] = $route_match;
|
||||
return $this->wizardFactory->createWizard($form_arg, $parameters);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getContentResult(Request $request, RouteMatchInterface $route_match) {
|
||||
$wizard = $this->getFormObject($route_match, $this->getFormArgument($route_match));
|
||||
$ajax = $request->attributes->get('js') == 'ajax' ? TRUE : FALSE;
|
||||
|
||||
return $this->wizardFactory->getWizardForm($wizard, $request->attributes->all(), $ajax);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\ctools\Event;
|
||||
|
||||
use Drupal\Core\Block\BlockPluginInterface;
|
||||
use Drupal\ctools\Plugin\BlockVariantInterface;
|
||||
use Symfony\Component\EventDispatcher\Event;
|
||||
|
||||
class BlockVariantEvent extends Event {
|
||||
|
||||
/**
|
||||
* The block being acted upon.
|
||||
*
|
||||
* @var \Drupal\Core\Block\BlockPluginInterface
|
||||
*/
|
||||
protected $block;
|
||||
|
||||
/**
|
||||
* The variant acting on the block.
|
||||
*
|
||||
* @var \Drupal\ctools\Plugin\BlockVariantInterface
|
||||
*/
|
||||
protected $variant;
|
||||
|
||||
/**
|
||||
* BlockVariantEvent constructor.
|
||||
*
|
||||
* @param \Drupal\Core\Block\BlockPluginInterface $block
|
||||
* The block plugin.
|
||||
* @param \Drupal\ctools\Plugin\BlockVariantInterface $variant
|
||||
* The variant plugin.
|
||||
*/
|
||||
public function __construct(BlockPluginInterface $block, BlockVariantInterface $variant) {
|
||||
$this->block = $block;
|
||||
$this->variant = $variant;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the block plugin.
|
||||
*
|
||||
* @return \Drupal\Core\Block\BlockPluginInterface
|
||||
*/
|
||||
public function getBlock() {
|
||||
return $this->block;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the variant plugin.
|
||||
*
|
||||
* @return \Drupal\ctools\Plugin\BlockVariantInterface
|
||||
*/
|
||||
public function getVariant() {
|
||||
return $this->variant;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\ctools\Event;
|
||||
|
||||
/**
|
||||
* Contains all events dispatched while manipulating blocks in a variant.
|
||||
*/
|
||||
final class BlockVariantEvents {
|
||||
|
||||
/**
|
||||
* The name of the event triggered when a block is added to a variant.
|
||||
*
|
||||
* This event allows modules to react to a block being added to a variant. The
|
||||
* event listener method receives a \Drupal\ctools\Event\BlockVariantEvent
|
||||
* instance.
|
||||
*
|
||||
* @Event
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const ADD_BLOCK = 'block.add';
|
||||
|
||||
/**
|
||||
* The name of the event triggered when a block is modified in a variant.
|
||||
*
|
||||
* This event allows modules to react to a block being modified in a variant.
|
||||
* The event listener method receives a \Drupal\ctools\Event\BlockVariantEvent
|
||||
* instance.
|
||||
*
|
||||
* @Event
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const UPDATE_BLOCK = 'block.update';
|
||||
|
||||
/**
|
||||
* The name of the event triggered when a block is removed from a variant.
|
||||
*
|
||||
* This event allows modules to react to a block being removed from a variant.
|
||||
* The event listener method receives a \Drupal\ctools\Event\BlockVariantEvent
|
||||
* instance.
|
||||
*
|
||||
* @Event
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const DELETE_BLOCK = 'block.delete';
|
||||
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\ctools\Event;
|
||||
|
||||
use Drupal\ctools\Wizard\FormWizardInterface;
|
||||
use Symfony\Component\EventDispatcher\Event;
|
||||
|
||||
/**
|
||||
* An event for altering form wizard values.
|
||||
*/
|
||||
class WizardEvent extends Event {
|
||||
|
||||
/**
|
||||
* @var \Drupal\ctools\Wizard\FormWizardInterface
|
||||
*/
|
||||
protected $wizard;
|
||||
|
||||
/**
|
||||
* @var mixed
|
||||
*/
|
||||
protected $values;
|
||||
|
||||
|
||||
public function __construct(FormWizardInterface $wizard, $values) {
|
||||
$this->wizard = $wizard;
|
||||
$this->values = $values;
|
||||
}
|
||||
|
||||
|
||||
public function getWizard() {
|
||||
return $this->wizard;
|
||||
}
|
||||
|
||||
|
||||
public function getValues() {
|
||||
return $this->values;
|
||||
}
|
||||
|
||||
|
||||
public function setValues($values) {
|
||||
$this->values = $values;
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\ctools\Form;
|
||||
|
||||
use Drupal\Component\Serialization\Json;
|
||||
use Drupal\Component\Utility\NestedArray;
|
||||
|
||||
/**
|
||||
* Provides helper methods for using an AJAX modal.
|
||||
*/
|
||||
trait AjaxFormTrait {
|
||||
|
||||
/**
|
||||
* Gets attributes for use with an AJAX modal.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getAjaxAttributes() {
|
||||
return [
|
||||
'class' => ['use-ajax'],
|
||||
'data-dialog-type' => 'modal',
|
||||
'data-dialog-options' => Json::encode([
|
||||
'width' => 'auto',
|
||||
]),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets attributes for use with an add button AJAX modal.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getAjaxButtonAttributes() {
|
||||
return NestedArray::mergeDeep(AjaxFormTrait::getAjaxAttributes(), [
|
||||
'class' => [
|
||||
'button',
|
||||
'button--small',
|
||||
'button-action',
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,185 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\ctools\Form;
|
||||
|
||||
use Drupal\Component\Plugin\PluginManagerInterface;
|
||||
use Drupal\Component\Uuid\Uuid;
|
||||
use Drupal\Core\Ajax\AjaxResponse;
|
||||
use Drupal\Core\Ajax\CloseModalDialogCommand;
|
||||
use Drupal\Core\Ajax\RedirectCommand;
|
||||
use Drupal\Core\Form\FormBase;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\Core\Plugin\ContextAwarePluginInterface;
|
||||
use Drupal\ctools\ConstraintConditionInterface;
|
||||
use Drupal\Core\TempStore\SharedTempStoreFactory;
|
||||
use Drupal\Core\Url;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
/**
|
||||
* Base class for condition configur operations.
|
||||
*/
|
||||
abstract class ConditionConfigure extends FormBase {
|
||||
|
||||
/**
|
||||
* @var \Drupal\Core\TempStore\SharedTempStoreFactory
|
||||
*/
|
||||
protected $tempstore;
|
||||
|
||||
/**
|
||||
* @var \Drupal\Core\Condition\ConditionManager
|
||||
*/
|
||||
protected $manager;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $tempstore_id;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $machine_name;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function create(ContainerInterface $container) {
|
||||
return new static($container->get('tempstore.shared'), $container->get('plugin.manager.condition'));
|
||||
}
|
||||
|
||||
|
||||
public function __construct(SharedTempStoreFactory $tempstore, PluginManagerInterface $manager) {
|
||||
$this->tempstore = $tempstore;
|
||||
$this->manager = $manager;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFormId() {
|
||||
return 'ctools_condition_configure';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildForm(array $form, FormStateInterface $form_state, $condition = NULL, $tempstore_id = NULL, $machine_name = NULL) {
|
||||
$this->tempstore_id = $tempstore_id;
|
||||
$this->machine_name = $machine_name;
|
||||
$cached_values = $this->tempstore->get($this->tempstore_id)->get($this->machine_name);
|
||||
if (is_numeric($condition) || Uuid::isValid($condition)) {
|
||||
$id = $condition;
|
||||
$condition = $this->getConditions($cached_values)[$id];
|
||||
$instance = $this->manager->createInstance($condition['id'], $condition);
|
||||
}
|
||||
else {
|
||||
$instance = $this->manager->createInstance($condition, []);
|
||||
}
|
||||
$form_state->setTemporaryValue('gathered_contexts', $this->getContexts($cached_values));
|
||||
/** @var $instance \Drupal\Core\Condition\ConditionInterface */
|
||||
$form = $instance->buildConfigurationForm($form, $form_state);
|
||||
if (isset($id)) {
|
||||
// Conditionally set this form element so that we can update or add.
|
||||
$form['id'] = [
|
||||
'#type' => 'value',
|
||||
'#value' => $id,
|
||||
];
|
||||
}
|
||||
$form['instance'] = [
|
||||
'#type' => 'value',
|
||||
'#value' => $instance,
|
||||
];
|
||||
$form['submit'] = [
|
||||
'#type' => 'submit',
|
||||
'#value' => $this->t('Save'),
|
||||
'#ajax' => [
|
||||
'callback' => [$this, 'ajaxSave'],
|
||||
],
|
||||
];
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function submitForm(array &$form, FormStateInterface $form_state) {
|
||||
$cached_values = $this->tempstore->get($this->tempstore_id)->get($this->machine_name);
|
||||
/** @var $instance \Drupal\Core\Condition\ConditionInterface */
|
||||
$instance = $form_state->getValue('instance');
|
||||
$instance->submitConfigurationForm($form, $form_state);
|
||||
$conditions = $this->getConditions($cached_values);
|
||||
if ($instance instanceof ContextAwarePluginInterface) {
|
||||
/** @var $instance \Drupal\Core\Plugin\ContextAwarePluginInterface */
|
||||
$context_mapping = $form_state->hasValue('context_mapping') ? $form_state->getValue('context_mapping') : [];
|
||||
$instance->setContextMapping($context_mapping);
|
||||
}
|
||||
if ($instance instanceof ConstraintConditionInterface) {
|
||||
/** @var $instance \Drupal\ctools\ConstraintConditionInterface */
|
||||
$instance->applyConstraints($this->getContexts($cached_values));
|
||||
}
|
||||
if ($form_state->hasValue('id')) {
|
||||
$conditions[$form_state->getValue('id')] = $instance->getConfiguration();
|
||||
}
|
||||
else {
|
||||
$conditions[] = $instance->getConfiguration();
|
||||
}
|
||||
$cached_values = $this->setConditions($cached_values, $conditions);
|
||||
$this->tempstore->get($this->tempstore_id)->set($this->machine_name, $cached_values);
|
||||
list($route_name, $route_parameters) = $this->getParentRouteInfo($cached_values);
|
||||
$form_state->setRedirect($route_name, $route_parameters);
|
||||
}
|
||||
|
||||
|
||||
public function ajaxSave(array &$form, FormStateInterface $form_state) {
|
||||
$response = new AjaxResponse();
|
||||
$cached_values = $this->tempstore->get($this->tempstore_id)->get($this->machine_name);
|
||||
list($route_name, $route_parameters) = $this->getParentRouteInfo($cached_values);
|
||||
$url = Url::fromRoute($route_name, $route_parameters);
|
||||
$response->addCommand(new RedirectCommand($url->toString()));
|
||||
$response->addCommand(new CloseModalDialogCommand());
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Document the route name and parameters for redirect after submission.
|
||||
*
|
||||
* @param $cached_values
|
||||
*
|
||||
* @return array
|
||||
* In the format of
|
||||
* return ['route.name', ['machine_name' => $this->machine_name, 'step' => 'step_name']];
|
||||
*/
|
||||
abstract protected function getParentRouteInfo($cached_values);
|
||||
|
||||
/**
|
||||
* Custom logic for retrieving the conditions array from cached_values.
|
||||
*
|
||||
* @param $cached_values
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
abstract protected function getConditions($cached_values);
|
||||
|
||||
/**
|
||||
* Custom logic for setting the conditions array in cached_values.
|
||||
*
|
||||
* @param $cached_values
|
||||
*
|
||||
* @param $conditions
|
||||
* The conditions to set within the cached values.
|
||||
*
|
||||
* @return mixed
|
||||
* Return the $cached_values
|
||||
*/
|
||||
abstract protected function setConditions($cached_values, $conditions);
|
||||
|
||||
/**
|
||||
* Custom logic for retrieving the contexts array from cached_values.
|
||||
*
|
||||
* @param $cached_values
|
||||
*
|
||||
* @return \Drupal\Core\Plugin\Context\ContextInterface[]
|
||||
*/
|
||||
abstract protected function getContexts($cached_values);
|
||||
|
||||
}
|
|
@ -0,0 +1,213 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\ctools\Form;
|
||||
|
||||
use Drupal\Component\Plugin\PluginManagerInterface;
|
||||
use Drupal\Core\Form\ConfirmFormBase;
|
||||
use Drupal\Core\Form\ConfirmFormHelper;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\Core\Url;
|
||||
use Drupal\ctools\ConstraintConditionInterface;
|
||||
use Drupal\Core\TempStore\SharedTempStoreFactory;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
|
||||
abstract class ConditionDelete extends ConfirmFormBase {
|
||||
|
||||
/**
|
||||
* @var \Drupal\Core\TempStore\SharedTempStoreFactory
|
||||
*/
|
||||
protected $tempstore;
|
||||
|
||||
/**
|
||||
* @var \Drupal\Core\Condition\ConditionManager
|
||||
*/
|
||||
protected $manager;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $tempstore_id;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $machine_name;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $id;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function create(ContainerInterface $container) {
|
||||
return new static($container->get('tempstore.shared'), $container->get('plugin.manager.condition'));
|
||||
}
|
||||
|
||||
|
||||
public function __construct(SharedTempStoreFactory $tempstore, PluginManagerInterface $manager) {
|
||||
$this->tempstore = $tempstore;
|
||||
$this->manager = $manager;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFormId() {
|
||||
return 'ctools_condition_delete';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildForm(array $form, FormStateInterface $form_state, $id = NULL, $tempstore_id = NULL, $machine_name = NULL) {
|
||||
$this->tempstore_id = $tempstore_id;
|
||||
$this->machine_name = $machine_name;
|
||||
$this->id = $id;
|
||||
|
||||
$cached_values = $this->tempstore->get($this->tempstore_id)->get($this->machine_name);
|
||||
$form['#title'] = $this->getQuestion($id, $cached_values);
|
||||
|
||||
$form['#attributes']['class'][] = 'confirmation';
|
||||
$form['description'] = ['#markup' => $this->getDescription()];
|
||||
$form[$this->getFormName()] = ['#type' => 'hidden', '#value' => 1];
|
||||
|
||||
// By default, render the form using theme_confirm_form().
|
||||
if (!isset($form['#theme'])) {
|
||||
$form['#theme'] = 'confirm_form';
|
||||
}
|
||||
$form['actions'] = ['#type' => 'actions'];
|
||||
$form['actions'] += $this->actions($form, $form_state);
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function submitForm(array &$form, FormStateInterface $form_state) {
|
||||
$cached_values = $this->tempstore->get($this->tempstore_id)->get($this->machine_name);
|
||||
$conditions = $this->getConditions($cached_values);
|
||||
/** @var $instance \Drupal\ctools\ConstraintConditionInterface */
|
||||
$instance = $this->manager->createInstance($conditions[$this->id]['id'], $conditions[$this->id]);
|
||||
if ($instance instanceof ConstraintConditionInterface) {
|
||||
$instance->removeConstraints($this->getContexts($cached_values));
|
||||
}
|
||||
unset($conditions[$this->id]);
|
||||
$cached_values = $this->setConditions($cached_values, $conditions);
|
||||
$this->tempstore->get($this->tempstore_id)->set($this->machine_name, $cached_values);
|
||||
list($route_name, $route_parameters) = $this->getParentRouteInfo($cached_values);
|
||||
$form_state->setRedirect($route_name, $route_parameters);
|
||||
}
|
||||
|
||||
|
||||
public function getQuestion($id = NULL, $cached_values = NULL) {
|
||||
$condition = $this->getConditions($cached_values)[$id];
|
||||
return $this->t('Are you sure you want to delete the @label condition?', [
|
||||
'@label' => $condition['id'],
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getDescription() {
|
||||
return $this->t('This action cannot be undone.');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFormName() {
|
||||
return 'confirm';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function actions(array $form, FormStateInterface $form_state) {
|
||||
return [
|
||||
'submit' => [
|
||||
'#type' => 'submit',
|
||||
'#value' => $this->getConfirmText(),
|
||||
'#validate' => [
|
||||
[$this, 'validateForm'],
|
||||
],
|
||||
'#submit' => [
|
||||
[$this, 'submitForm'],
|
||||
],
|
||||
],
|
||||
'cancel' => ConfirmFormHelper::buildCancelLink($this, $this->getRequest()),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the route to go to if the user cancels the action.
|
||||
*
|
||||
* @return \Drupal\Core\Url
|
||||
* A URL object.
|
||||
*/
|
||||
public function getCancelUrl() {
|
||||
$cached_values = $this->tempstore->get($this->tempstore_id)->get($this->machine_name);
|
||||
list($route_name, $route_parameters) = $this->getParentRouteInfo($cached_values);
|
||||
return new Url($route_name, $route_parameters);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getConfirmText() {
|
||||
return $this->t('Delete');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getCancelText() {
|
||||
return $this->t('Cancel');
|
||||
}
|
||||
|
||||
/**
|
||||
* Document the route name and parameters for redirect after submission.
|
||||
*
|
||||
* @param $cached_values
|
||||
*
|
||||
* @return array
|
||||
* In the format of
|
||||
* return ['route.name', ['machine_name' => $this->machine_name, 'step' => 'step_name]];
|
||||
*/
|
||||
abstract protected function getParentRouteInfo($cached_values);
|
||||
|
||||
/**
|
||||
* Custom logic for retrieving the conditions array from cached_values.
|
||||
*
|
||||
* @param $cached_values
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
abstract protected function getConditions($cached_values);
|
||||
|
||||
/**
|
||||
* Custom logic for setting the conditions array in cached_values.
|
||||
*
|
||||
* @param $cached_values
|
||||
*
|
||||
* @param $conditions
|
||||
* The conditions to set within the cached values.
|
||||
*
|
||||
* @return mixed
|
||||
* Return the $cached_values
|
||||
*/
|
||||
abstract protected function setConditions($cached_values, $conditions);
|
||||
|
||||
/**
|
||||
* Custom logic for retrieving the contexts array from cached_values.
|
||||
*
|
||||
* @param $cached_values
|
||||
*
|
||||
* @return \Drupal\Core\Plugin\Context\ContextInterface[]
|
||||
*/
|
||||
abstract protected function getContexts($cached_values);
|
||||
|
||||
}
|
|
@ -0,0 +1,277 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\ctools\Form;
|
||||
|
||||
use Drupal\Core\Ajax\AjaxResponse;
|
||||
use Drupal\Core\Ajax\CloseModalDialogCommand;
|
||||
use Drupal\Core\Ajax\RedirectCommand;
|
||||
use Drupal\Core\Entity\EntityTypeManagerInterface;
|
||||
use Drupal\Core\Form\FormBase;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\Core\Plugin\Context\Context;
|
||||
use Drupal\Core\Plugin\Context\ContextDefinition;
|
||||
use Drupal\Core\Plugin\Context\ContextInterface;
|
||||
use Drupal\Core\Plugin\Context\EntityContextDefinition;
|
||||
use Drupal\Core\TempStore\SharedTempStoreFactory;
|
||||
use Drupal\Core\Url;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
|
||||
abstract class ContextConfigure extends FormBase {
|
||||
|
||||
/**
|
||||
* @var \Drupal\Core\TempStore\SharedTempStoreFactory
|
||||
*/
|
||||
protected $tempstore;
|
||||
|
||||
/**
|
||||
* Object EntityTypeManager.
|
||||
*
|
||||
* @var Drupal\Core\Entity\EntityTypeManagerInterface
|
||||
*/
|
||||
protected $entityTypeManager;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $tempstore_id;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $machine_name;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function create(ContainerInterface $container) {
|
||||
return new static(
|
||||
$container->get('tempstore.shared'),
|
||||
$container->get('entity_type.manager')
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
public function __construct(SharedTempStoreFactory $tempstore, EntityTypeManagerInterface $entity_type_manager) {
|
||||
$this->tempstore = $tempstore;
|
||||
$this->entityTypeManager = $entity_type_manager;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFormId() {
|
||||
return 'ctools_context_configure';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildForm(array $form, FormStateInterface $form_state, $context_id = NULL, $tempstore_id = NULL, $machine_name = NULL) {
|
||||
$this->tempstore_id = $tempstore_id;
|
||||
$this->machine_name = $machine_name;
|
||||
$cached_values = $this->tempstore->get($this->tempstore_id)->get($this->machine_name);
|
||||
$contexts = $this->getContexts($cached_values);
|
||||
$edit = FALSE;
|
||||
if (!empty($contexts[$context_id])) {
|
||||
$context = $contexts[$context_id];
|
||||
$machine_name = $context_id;
|
||||
$edit = TRUE;
|
||||
}
|
||||
else {
|
||||
if (strpos($context_id, 'entity:') === 0) {
|
||||
$context_definition = new EntityContextDefinition($context_id);
|
||||
}
|
||||
else {
|
||||
$context_definition = new ContextDefinition($context_id);
|
||||
}
|
||||
$context = new Context($context_definition);
|
||||
$machine_name = '';
|
||||
}
|
||||
$label = $context->getContextDefinition()->getLabel();
|
||||
$description = $context->getContextDefinition()->getDescription();
|
||||
$data_type = $context->getContextDefinition()->getDataType();
|
||||
$form['#attached']['library'][] = 'core/drupal.dialog.ajax';
|
||||
$form['context_id'] = [
|
||||
'#type' => 'value',
|
||||
'#value' => $context_id,
|
||||
];
|
||||
$form['label'] = [
|
||||
'#type' => 'textfield',
|
||||
'#title' => $this->t('Label'),
|
||||
'#default_value' => $label,
|
||||
'#required' => TRUE,
|
||||
];
|
||||
$form['machine_name'] = [
|
||||
'#type' => 'machine_name',
|
||||
'#title' => $this->t('Machine Name'),
|
||||
'#default_value' => $machine_name,
|
||||
'#required' => TRUE,
|
||||
'#maxlength' => 128,
|
||||
'#machine_name' => [
|
||||
'source' => ['label'],
|
||||
'exists' => [$this, 'contextExists'],
|
||||
],
|
||||
'#disabled' => $this->disableMachineName($cached_values, $machine_name),
|
||||
];
|
||||
$form['description'] = [
|
||||
'#type' => 'textarea',
|
||||
'#title' => $this->t('Description'),
|
||||
'#default_value' => $description,
|
||||
];
|
||||
if (strpos($data_type, 'entity:') === 0) {
|
||||
list(, $entity_type) = explode(':', $data_type);
|
||||
/** @var \Drupal\Core\Entity\Plugin\DataType\EntityAdapter $entity */
|
||||
$entity = $edit ? $context->getContextValue() : NULL;
|
||||
$form['context_value'] = [
|
||||
'#type' => 'entity_autocomplete',
|
||||
'#required' => TRUE,
|
||||
'#target_type' => $entity_type,
|
||||
'#default_value' => $entity,
|
||||
'#title' => $this->t('Select entity'),
|
||||
];
|
||||
}
|
||||
else {
|
||||
$value = $context->getContextData()->getValue();
|
||||
$form['context_value'] = [
|
||||
'#title' => $this->t('Set a context value'),
|
||||
'#type' => 'textfield',
|
||||
'#required' => TRUE,
|
||||
'#default_value' => $value,
|
||||
];
|
||||
}
|
||||
$form['submit'] = [
|
||||
'#type' => 'submit',
|
||||
'#value' => $this->t('Save'),
|
||||
'#ajax' => [
|
||||
'callback' => [$this, 'ajaxSave'],
|
||||
],
|
||||
];
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function validateForm(array &$form, FormStateInterface $form_state) {
|
||||
// If these are not equal, then we're adding a new context and should not override an existing context.
|
||||
if ($form_state->getValue('machine_name') != $form_state->getValue('context_id')) {
|
||||
$machine_name = $form_state->getValue('machine_name');
|
||||
$cached_values = $this->tempstore->get($this->tempstore_id)->get($this->machine_name);
|
||||
if (!empty($this->getContexts($cached_values)[$machine_name])) {
|
||||
$form_state->setError($form['machine_name'], $this->t('That machine name is in use by another context definition.'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function submitForm(array &$form, FormStateInterface $form_state) {
|
||||
$cached_values = $this->tempstore->get($this->tempstore_id)->get($this->machine_name);
|
||||
$contexts = $this->getContexts($cached_values);
|
||||
if ($form_state->getValue('machine_name') != $form_state->getValue('context_id')) {
|
||||
$data_type = $form_state->getValue('context_id');
|
||||
if (strpos($data_type, 'entity:') === 0) {
|
||||
$context_definition = new EntityContextDefinition($data_type, $form_state->getValue('label'), TRUE, FALSE, $form_state->getValue('description'));
|
||||
}
|
||||
else {
|
||||
$context_definition = new ContextDefinition($data_type, $form_state->getValue('label'), TRUE, FALSE, $form_state->getValue('description'));
|
||||
}
|
||||
}
|
||||
else {
|
||||
$context = $contexts[$form_state->getValue('machine_name')];
|
||||
$context_definition = $context->getContextDefinition();
|
||||
$context_definition->setLabel($form_state->getValue('label'));
|
||||
$context_definition->setDescription($form_state->getValue('description'));
|
||||
}
|
||||
// We're dealing with an entity and should make sure it's loaded.
|
||||
if (strpos($context_definition->getDataType(), 'entity:') === 0) {
|
||||
list(, $entity_type) = explode(':', $context_definition->getDataType());
|
||||
if (is_numeric($form_state->getValue('context_value'))) {
|
||||
$value = $this->entityTypeManager->getStorage($entity_type)->load($form_state->getValue('context_value'));
|
||||
}
|
||||
}
|
||||
// No loading required for non-entity values.
|
||||
else {
|
||||
$value = $form_state->getValue('context_value');
|
||||
}
|
||||
$context = new Context($context_definition, $value);
|
||||
|
||||
$cached_values = $this->addContext($cached_values, $form_state->getValue('machine_name'), $context);
|
||||
$this->tempstore->get($this->tempstore_id)->set($this->machine_name, $cached_values);
|
||||
list($route_name, $route_parameters) = $this->getParentRouteInfo($cached_values);
|
||||
$form_state->setRedirect($route_name, $route_parameters);
|
||||
}
|
||||
|
||||
|
||||
public function ajaxSave(array &$form, FormStateInterface $form_state) {
|
||||
$response = new AjaxResponse();
|
||||
$cached_values = $this->tempstore->get($this->tempstore_id)->get($this->machine_name);
|
||||
list($route_name, $route_parameters) = $this->getParentRouteInfo($cached_values);
|
||||
$url = new Url($route_name, $route_parameters);
|
||||
$response->addCommand(new RedirectCommand($url->toString()));
|
||||
$response->addCommand(new CloseModalDialogCommand());
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Document the route name and parameters for redirect after submission.
|
||||
*
|
||||
* @param $cached_values
|
||||
*
|
||||
* @return array
|
||||
* In the format of
|
||||
* return ['route.name', ['machine_name' => $this->machine_name, 'step' => 'step_name]];
|
||||
*/
|
||||
abstract protected function getParentRouteInfo($cached_values);
|
||||
|
||||
/**
|
||||
* Custom logic for retrieving the contexts array from cached_values.
|
||||
*
|
||||
* @param $cached_values
|
||||
*
|
||||
* @return \Drupal\Core\Plugin\Context\ContextInterface[]
|
||||
*/
|
||||
abstract protected function getContexts($cached_values);
|
||||
|
||||
/**
|
||||
* Custom logic for adding a context to the cached_values contexts array.
|
||||
*
|
||||
* @param array $cached_values
|
||||
* The cached_values currently in use.
|
||||
* @param string $context_id
|
||||
* The context identifier.
|
||||
* @param \Drupal\Core\Plugin\Context\ContextInterface $context
|
||||
* The context to add or update within the cached values.
|
||||
*
|
||||
* @return mixed
|
||||
* Return the $cached_values
|
||||
*/
|
||||
abstract protected function addContext($cached_values, $context_id, ContextInterface $context);
|
||||
|
||||
/**
|
||||
* Custom "exists" logic for the context to be created.
|
||||
*
|
||||
* @param string $value
|
||||
* The name of the context.
|
||||
* @param $element
|
||||
* The machine_name element
|
||||
* @param \Drupal\Core\Form\FormStateInterface $form_state
|
||||
* The form state.
|
||||
*
|
||||
* @return bool
|
||||
* Return true if a context of this name exists.
|
||||
*/
|
||||
abstract public function contextExists($value, $element, $form_state);
|
||||
|
||||
/**
|
||||
* Determines if the machine_name should be disabled.
|
||||
*
|
||||
* @param $cached_values
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
abstract protected function disableMachineName($cached_values, $machine_name);
|
||||
|
||||
}
|
|
@ -0,0 +1,88 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\ctools\Form;
|
||||
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\Core\Form\ConfirmFormBase;
|
||||
use Drupal\Core\TempStore\SharedTempStoreFactory;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
/**
|
||||
* Provides a form for deleting an contexts and relationships.
|
||||
*/
|
||||
abstract class ContextDelete extends ConfirmFormBase {
|
||||
|
||||
/**
|
||||
* @var \Drupal\Core\TempStore\SharedTempStoreFactory
|
||||
*/
|
||||
protected $tempstore;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $tempstore_id;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $machine_name;
|
||||
|
||||
/**
|
||||
* The static context's machine name.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $context_id;
|
||||
|
||||
|
||||
public static function create(ContainerInterface $container) {
|
||||
return new static($container->get('tempstore.shared'));
|
||||
}
|
||||
|
||||
|
||||
public function __construct(SharedTempStoreFactory $tempstore) {
|
||||
$this->tempstore = $tempstore;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFormId() {
|
||||
return 'ctools_context_delete_form';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getConfirmText() {
|
||||
return $this->t('Delete');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildForm(array $form, FormStateInterface $form_state, $tempstore_id = NULL, $machine_name = NULL, $context_id = NULL) {
|
||||
$this->tempstore_id = $tempstore_id;
|
||||
$this->machine_name = $machine_name;
|
||||
$this->context_id = $context_id;
|
||||
return parent::buildForm($form, $form_state);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function submitForm(array &$form, FormStateInterface $form_state) {
|
||||
$form_state->setRedirectUrl($this->getCancelUrl());
|
||||
}
|
||||
|
||||
|
||||
protected function getTempstore() {
|
||||
return $this->tempstore->get($this->tempstore_id)->get($this->machine_name);
|
||||
}
|
||||
|
||||
|
||||
protected function setTempstore($cached_values) {
|
||||
$this->tempstore->get($this->tempstore_id)->set($this->machine_name, $cached_values);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,246 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\ctools\Form;
|
||||
|
||||
use Drupal\Component\Plugin\PluginManagerInterface;
|
||||
use Drupal\Component\Serialization\Json;
|
||||
use Drupal\Core\Ajax\AjaxResponse;
|
||||
use Drupal\Core\Ajax\OpenModalDialogCommand;
|
||||
use Drupal\Core\Form\FormBase;
|
||||
use Drupal\Core\Form\FormBuilderInterface;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\Core\Url;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
|
||||
abstract class ManageConditions extends FormBase {
|
||||
|
||||
/**
|
||||
* @var \Drupal\Core\Condition\ConditionManager
|
||||
*/
|
||||
protected $manager;
|
||||
|
||||
/**
|
||||
* The builder of form.
|
||||
*
|
||||
* @var \Drupal\Core\Form\FormBuilder
|
||||
*/
|
||||
protected $formBuilder;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $machine_name;
|
||||
|
||||
|
||||
public static function create(ContainerInterface $container) {
|
||||
return new static(
|
||||
$container->get('plugin.manager.condition'),
|
||||
$container->get('form_builder')
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
public function __construct(PluginManagerInterface $manager, FormBuilderInterface $form_builder) {
|
||||
$this->manager = $manager;
|
||||
$this->formBuilder = $form_builder;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFormId() {
|
||||
return 'ctools_manage_conditions_form';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildForm(array $form, FormStateInterface $form_state) {
|
||||
$cached_values = $form_state->getTemporaryValue('wizard');
|
||||
$this->machine_name = $cached_values['id'];
|
||||
$form['#attached']['library'][] = 'core/drupal.dialog.ajax';
|
||||
$options = [];
|
||||
$contexts = $this->getContexts($cached_values);
|
||||
foreach ($this->manager->getDefinitionsForContexts($contexts) as $plugin_id => $definition) {
|
||||
$options[$plugin_id] = (string) $definition['label'];
|
||||
}
|
||||
$form['items'] = [
|
||||
'#type' => 'markup',
|
||||
'#prefix' => '<div id="configured-conditions">',
|
||||
'#suffix' => '</div>',
|
||||
'#theme' => 'table',
|
||||
'#header' => [$this->t('Plugin Id'), $this->t('Summary'), $this->t('Operations')],
|
||||
'#rows' => $this->renderRows($cached_values),
|
||||
'#empty' => $this->t('No required conditions have been configured.'),
|
||||
];
|
||||
$form['conditions'] = [
|
||||
'#type' => 'select',
|
||||
'#options' => $options,
|
||||
];
|
||||
$form['add'] = [
|
||||
'#type' => 'submit',
|
||||
'#name' => 'add',
|
||||
'#value' => $this->t('Add Condition'),
|
||||
'#ajax' => [
|
||||
'callback' => [$this, 'add'],
|
||||
'event' => 'click',
|
||||
],
|
||||
'#submit' => [
|
||||
'callback' => [$this, 'submitForm'],
|
||||
],
|
||||
];
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function submitForm(array &$form, FormStateInterface $form_state) {
|
||||
$cached_values = $form_state->getTemporaryValue('wizard');
|
||||
list(, $route_parameters) = $this->getOperationsRouteInfo($cached_values, $this->machine_name, $form_state->getValue('conditions'));
|
||||
$form_state->setRedirect($this->getAddRoute($cached_values), $route_parameters);
|
||||
}
|
||||
|
||||
|
||||
public function add(array &$form, FormStateInterface $form_state) {
|
||||
$condition = $form_state->getValue('conditions');
|
||||
$content = $this->formBuilder->getForm($this->getConditionClass(), $condition, $this->getTempstoreId(), $this->machine_name);
|
||||
$content['#attached']['library'][] = 'core/drupal.dialog.ajax';
|
||||
$cached_values = $form_state->getTemporaryValue('wizard');
|
||||
list(, $route_parameters) = $this->getOperationsRouteInfo($cached_values, $this->machine_name, $form_state->getValue('conditions'));
|
||||
$route_name = $this->getAddRoute($cached_values);
|
||||
$route_options = [
|
||||
'query' => [
|
||||
FormBuilderInterface::AJAX_FORM_REQUEST => TRUE,
|
||||
],
|
||||
];
|
||||
$url = Url::fromRoute($route_name, $route_parameters, $route_options);
|
||||
$content['submit']['#attached']['drupalSettings']['ajax'][$content['submit']['#id']]['url'] = $url->toString();
|
||||
$response = new AjaxResponse();
|
||||
$response->addCommand(new OpenModalDialogCommand($this->t('Configure Required Context'), $content, ['width' => '700']));
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $cached_values
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function renderRows($cached_values) {
|
||||
$configured_conditions = [];
|
||||
foreach ($this->getConditions($cached_values) as $row => $condition) {
|
||||
/** @var $instance \Drupal\Core\Condition\ConditionInterface */
|
||||
$instance = $this->manager->createInstance($condition['id'], $condition);
|
||||
list($route_name, $route_parameters) = $this->getOperationsRouteInfo($cached_values, $cached_values['id'], $row);
|
||||
$build = [
|
||||
'#type' => 'operations',
|
||||
'#links' => $this->getOperations($route_name, $route_parameters),
|
||||
];
|
||||
$configured_conditions[] = [
|
||||
$instance->getPluginId(),
|
||||
$instance->summary(),
|
||||
'operations' => [
|
||||
'data' => $build,
|
||||
],
|
||||
];
|
||||
}
|
||||
return $configured_conditions;
|
||||
}
|
||||
|
||||
|
||||
protected function getOperations($route_name_base, array $route_parameters = []) {
|
||||
$operations['edit'] = [
|
||||
'title' => $this->t('Edit'),
|
||||
'url' => new Url($route_name_base . '.edit', $route_parameters),
|
||||
'weight' => 10,
|
||||
'attributes' => [
|
||||
'class' => ['use-ajax'],
|
||||
'data-dialog-type' => 'modal',
|
||||
'data-dialog-options' => Json::encode([
|
||||
'width' => 700,
|
||||
]),
|
||||
],
|
||||
];
|
||||
$route_parameters['id'] = $route_parameters['condition'];
|
||||
$operations['delete'] = [
|
||||
'title' => $this->t('Delete'),
|
||||
'url' => new Url($route_name_base . '.delete', $route_parameters),
|
||||
'weight' => 100,
|
||||
'attributes' => [
|
||||
'class' => ['use-ajax'],
|
||||
'data-dialog-type' => 'modal',
|
||||
'data-dialog-options' => Json::encode([
|
||||
'width' => 700,
|
||||
]),
|
||||
],
|
||||
];
|
||||
return $operations;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a subclass of '\Drupal\ctools\Form\ConditionConfigure'.
|
||||
*
|
||||
* The ConditionConfigure class is designed to be subclassed with custom
|
||||
* route information to control the modal/redirect needs of your use case.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
abstract protected function getConditionClass();
|
||||
|
||||
/**
|
||||
* The route to which condition 'add' actions should submit.
|
||||
*
|
||||
* @param mixed $cached_values
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
abstract protected function getAddRoute($cached_values);
|
||||
|
||||
/**
|
||||
* Provide the tempstore id for your specified use case.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
abstract protected function getTempstoreId();
|
||||
|
||||
/**
|
||||
* Document the route name and parameters for edit/delete context operations.
|
||||
*
|
||||
* The route name returned from this method is used as a "base" to which
|
||||
* ".edit" and ".delete" are appended in the getOperations() method.
|
||||
* Subclassing '\Drupal\ctools\Form\ConditionConfigure' and
|
||||
* '\Drupal\ctools\Form\ConditionDelete' should set you up for using this
|
||||
* approach quite seamlessly.
|
||||
*
|
||||
* @param mixed $cached_values
|
||||
*
|
||||
* @param string $machine_name
|
||||
*
|
||||
* @param string $row
|
||||
*
|
||||
* @return array
|
||||
* In the format of
|
||||
* return ['route.base.name', ['machine_name' => $machine_name, 'context' => $row]];
|
||||
*/
|
||||
abstract protected function getOperationsRouteInfo($cached_values, $machine_name, $row);
|
||||
|
||||
/**
|
||||
* Custom logic for retrieving the conditions array from cached_values.
|
||||
*
|
||||
* @param $cached_values
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
abstract protected function getConditions($cached_values);
|
||||
|
||||
/**
|
||||
* Custom logic for retrieving the contexts array from cached_values.
|
||||
*
|
||||
* @param $cached_values
|
||||
*
|
||||
* @return \Drupal\Core\Plugin\Context\ContextInterface[]
|
||||
*/
|
||||
abstract protected function getContexts($cached_values);
|
||||
|
||||
}
|
|
@ -0,0 +1,359 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\ctools\Form;
|
||||
|
||||
use Drupal\Component\Serialization\Json;
|
||||
use Drupal\Core\Ajax\AjaxResponse;
|
||||
use Drupal\Core\Ajax\OpenModalDialogCommand;
|
||||
use Drupal\Core\Form\FormBase;
|
||||
use Drupal\Core\Form\FormBuilderInterface;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\Core\TypedData\TypedDataManagerInterface;
|
||||
use Drupal\Core\Url;
|
||||
use Drupal\ctools\TypedDataResolver;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
|
||||
abstract class ManageContext extends FormBase {
|
||||
|
||||
/**
|
||||
* The machine name of the wizard we're working with.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $machine_name;
|
||||
|
||||
/**
|
||||
* The typed data manager.
|
||||
*
|
||||
* @var \Drupal\Core\TypedData\TypedDataManagerInterface
|
||||
*/
|
||||
protected $typedDataManager;
|
||||
|
||||
/**
|
||||
* The form builder.
|
||||
*
|
||||
* @var \Drupal\Core\Form\FormBuilderInterface
|
||||
*/
|
||||
protected $formBuilder;
|
||||
|
||||
/**
|
||||
* The typed data resolver.
|
||||
*
|
||||
* @var \Drupal\ctools\TypedDataResolver
|
||||
*/
|
||||
protected $typedDataResolver;
|
||||
|
||||
/**
|
||||
* An array of property types that are eligible as relationships.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $property_types = [];
|
||||
|
||||
/**
|
||||
* A property for controlling usage of relationships in an implementation.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $relationships = TRUE;
|
||||
|
||||
/**
|
||||
* ManageContext constructor.
|
||||
*
|
||||
* @param \Drupal\Core\TypedData\TypedDataManagerInterface $typed_data_manager
|
||||
* The typed data manager.
|
||||
* @param \Drupal\Core\Form\FormBuilderInterface $form_builder
|
||||
* The form builder.
|
||||
* @param \Drupal\ctools\TypedDataResolver $ctools_typed_data_resolver
|
||||
* The typed data resolver.
|
||||
*/
|
||||
public function __construct(TypedDataManagerInterface $typed_data_manager, FormBuilderInterface $form_builder, TypedDataResolver $ctools_typed_data_resolver) {
|
||||
$this->typedDataManager = $typed_data_manager;
|
||||
$this->formBuilder = $form_builder;
|
||||
$this->typedDataResolver = $ctools_typed_data_resolver;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function create(ContainerInterface $container) {
|
||||
return new static(
|
||||
$container->get('typed_data_manager'),
|
||||
$container->get('form_builder'),
|
||||
$container->get('ctools.typed_data.resolver')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFormId() {
|
||||
return 'ctools_manage_context_form';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildForm(array $form, FormStateInterface $form_state) {
|
||||
$cached_values = $form_state->getTemporaryValue('wizard');
|
||||
$this->machine_name = $cached_values['id'];
|
||||
$form['items'] = [
|
||||
'#type' => 'markup',
|
||||
'#prefix' => '<div id="configured-contexts">',
|
||||
'#suffix' => '</div>',
|
||||
'#theme' => 'table',
|
||||
'#header' => [$this->t('Context ID'), $this->t('Label'), $this->t('Data Type'), $this->t('Options')],
|
||||
'#rows' => $this->renderRows($cached_values),
|
||||
'#empty' => $this->t('No contexts or relationships have been added.'),
|
||||
];
|
||||
foreach ($this->typedDataManager->getDefinitions() as $type => $definition) {
|
||||
$types[$type] = $definition['label'];
|
||||
}
|
||||
if (isset($types['entity'])) {
|
||||
unset($types['entity']);
|
||||
}
|
||||
asort($types);
|
||||
$form['context'] = [
|
||||
'#type' => 'select',
|
||||
'#options' => $types,
|
||||
];
|
||||
$form['add'] = [
|
||||
'#type' => 'submit',
|
||||
'#name' => 'add',
|
||||
'#value' => $this->t('Add new context'),
|
||||
'#ajax' => [
|
||||
'callback' => [$this, 'addContext'],
|
||||
'event' => 'click',
|
||||
],
|
||||
'#submit' => [
|
||||
'callback' => [$this, 'submitForm'],
|
||||
],
|
||||
];
|
||||
|
||||
$form['relationships'] = [
|
||||
'#type' => 'select',
|
||||
'#title' => $this->t('Add a relationship'),
|
||||
'#options' => $this->getAvailableRelationships($cached_values),
|
||||
'#access' => $this->relationships,
|
||||
];
|
||||
$form['add_relationship'] = [
|
||||
'#type' => 'submit',
|
||||
'#name' => 'add_relationship',
|
||||
'#value' => $this->t('Add Relationship'),
|
||||
'#ajax' => [
|
||||
'callback' => [$this, 'addRelationship'],
|
||||
'event' => 'click',
|
||||
],
|
||||
'#submit' => [
|
||||
'callback' => [$this, 'submitForm'],
|
||||
],
|
||||
'#access' => $this->relationships,
|
||||
];
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function submitForm(array &$form, FormStateInterface $form_state) {
|
||||
if ($form_state->getTriggeringElement()['#name'] == 'add') {
|
||||
$cached_values = $form_state->getTemporaryValue('wizard');
|
||||
list(, $route_parameters) = $this->getContextOperationsRouteInfo($cached_values, $this->machine_name, $form_state->getValue('context'));
|
||||
$form_state->setRedirect($this->getContextAddRoute($cached_values), $route_parameters);
|
||||
}
|
||||
if ($form_state->getTriggeringElement()['#name'] == 'add_relationship') {
|
||||
$cached_values = $form_state->getTemporaryValue('wizard');
|
||||
list(, $route_parameters) = $this->getRelationshipOperationsRouteInfo($cached_values, $this->machine_name, $form_state->getValue('relationships'));
|
||||
$form_state->setRedirect($this->getRelationshipAddRoute($cached_values), $route_parameters);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function addContext(array &$form, FormStateInterface $form_state) {
|
||||
$context = $form_state->getValue('context');
|
||||
$content = $this->formBuilder->getForm($this->getContextClass(), $context, $this->getTempstoreId(), $this->machine_name);
|
||||
$content['#attached']['library'][] = 'core/drupal.dialog.ajax';
|
||||
$cached_values = $form_state->getTemporaryValue('wizard');
|
||||
list(, $route_parameters) = $this->getContextOperationsRouteInfo($cached_values, $this->machine_name, $context);
|
||||
$route_name = $this->getContextAddRoute($cached_values);
|
||||
$route_options = [
|
||||
'query' => [
|
||||
FormBuilderInterface::AJAX_FORM_REQUEST => TRUE,
|
||||
],
|
||||
];
|
||||
$url = Url::fromRoute($route_name, $route_parameters, $route_options);
|
||||
$content['submit']['#attached']['drupalSettings']['ajax'][$content['submit']['#id']]['url'] = $url->toString();
|
||||
$response = new AjaxResponse();
|
||||
$response->addCommand(new OpenModalDialogCommand($this->t('Add new context'), $content, ['width' => '700']));
|
||||
return $response;
|
||||
}
|
||||
|
||||
|
||||
public function addRelationship(array &$form, FormStateInterface $form_state) {
|
||||
$relationship = $form_state->getValue('relationships');
|
||||
$content = $this->formBuilder->getForm($this->getRelationshipClass(), $relationship, $this->getTempstoreId(), $this->machine_name);
|
||||
$content['#attached']['library'][] = 'core/drupal.dialog.ajax';
|
||||
$cached_values = $form_state->getTemporaryValue('wizard');
|
||||
list(, $route_parameters) = $this->getRelationshipOperationsRouteInfo($cached_values, $this->machine_name, $relationship);
|
||||
$route_name = $this->getRelationshipAddRoute($cached_values);
|
||||
$route_options = [
|
||||
'query' => [
|
||||
FormBuilderInterface::AJAX_FORM_REQUEST => TRUE,
|
||||
],
|
||||
];
|
||||
$url = Url::fromRoute($route_name, $route_parameters, $route_options);
|
||||
$content['submit']['#attached']['drupalSettings']['ajax'][$content['submit']['#id']]['url'] = $url->toString();
|
||||
$response = new AjaxResponse();
|
||||
$response->addCommand(new OpenModalDialogCommand($this->t('Configure Relationship'), $content, ['width' => '700']));
|
||||
return $response;
|
||||
}
|
||||
|
||||
|
||||
protected function getAvailableRelationships($cached_values) {
|
||||
/** @var \Drupal\ctools\TypedDataResolver $resolver */
|
||||
$resolver = $this->typedDataResolver;
|
||||
return $resolver->getTokensForContexts($this->getContexts($cached_values));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $cached_values
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function renderRows($cached_values) {
|
||||
$contexts = [];
|
||||
foreach ($this->getContexts($cached_values) as $row => $context) {
|
||||
list($route_name, $route_parameters) = $this->getContextOperationsRouteInfo($cached_values, $this->machine_name, $row);
|
||||
$build = [
|
||||
'#type' => 'operations',
|
||||
'#links' => $this->getOperations($cached_values, $row, $route_name, $route_parameters),
|
||||
];
|
||||
$contexts[$row] = [
|
||||
$row,
|
||||
$context->getContextDefinition()->getLabel(),
|
||||
$context->getContextDefinition()->getDataType(),
|
||||
'operations' => [
|
||||
'data' => $build,
|
||||
],
|
||||
];
|
||||
}
|
||||
return $contexts;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $cached_values
|
||||
* @param string $row
|
||||
* @param string $route_name_base
|
||||
* @param array $route_parameters
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
protected function getOperations($cached_values, $row, $route_name_base, array $route_parameters = []) {
|
||||
$operations = [];
|
||||
if ($this->isEditableContext($cached_values, $row)) {
|
||||
$operations['edit'] = [
|
||||
'title' => $this->t('Edit'),
|
||||
'url' => new Url($route_name_base . '.edit', $route_parameters),
|
||||
'weight' => 10,
|
||||
'attributes' => [
|
||||
'class' => ['use-ajax'],
|
||||
'data-dialog-type' => 'modal',
|
||||
'data-dialog-options' => Json::encode([
|
||||
'width' => 700,
|
||||
]),
|
||||
],
|
||||
];
|
||||
$operations['delete'] = [
|
||||
'title' => $this->t('Delete'),
|
||||
'url' => new Url($route_name_base . '.delete', $route_parameters),
|
||||
'weight' => 100,
|
||||
'attributes' => [
|
||||
'class' => ['use-ajax'],
|
||||
'data-dialog-type' => 'modal',
|
||||
'data-dialog-options' => Json::encode([
|
||||
'width' => 700,
|
||||
]),
|
||||
],
|
||||
];
|
||||
}
|
||||
return $operations;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a subclass of '\Drupal\ctools\Form\ContextConfigure'.
|
||||
*
|
||||
* The ContextConfigure class is designed to be subclassed with custom
|
||||
* route information to control the modal/redirect needs of your use case.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
abstract protected function getContextClass($cached_values);
|
||||
|
||||
/**
|
||||
* Return a subclass of '\Drupal\ctools\Form\RelationshipConfigure'.
|
||||
*
|
||||
* The RelationshipConfigure class is designed to be subclassed with custom
|
||||
* route information to control the modal/redirect needs of your use case.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
abstract protected function getRelationshipClass($cached_values);
|
||||
|
||||
/**
|
||||
* The route to which context 'add' actions should submit.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
abstract protected function getContextAddRoute($cached_values);
|
||||
|
||||
/**
|
||||
* The route to which relationship 'add' actions should submit.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
abstract protected function getRelationshipAddRoute($cached_values);
|
||||
|
||||
/**
|
||||
* Provide the tempstore id for your specified use case.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
abstract protected function getTempstoreId();
|
||||
|
||||
/**
|
||||
* Returns the contexts already available in the wizard.
|
||||
*
|
||||
* @param mixed $cached_values
|
||||
*
|
||||
* @return \Drupal\Core\Plugin\Context\ContextInterface[]
|
||||
*/
|
||||
abstract protected function getContexts($cached_values);
|
||||
|
||||
/**
|
||||
* @param mixed $cached_values
|
||||
* @param string $machine_name
|
||||
* @param string $row
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
abstract protected function getContextOperationsRouteInfo($cached_values, $machine_name, $row);
|
||||
|
||||
/**
|
||||
* @param mixed $cached_values
|
||||
* @param string $machine_name
|
||||
* @param string $row
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
abstract protected function getRelationshipOperationsRouteInfo($cached_values, $machine_name, $row);
|
||||
|
||||
/**
|
||||
* @param mixed $cached_values
|
||||
* @param string $row
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
abstract protected function isEditableContext($cached_values, $row);
|
||||
|
||||
}
|
|
@ -0,0 +1,301 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\ctools\Form;
|
||||
|
||||
use Drupal\Component\Serialization\Json;
|
||||
use Drupal\Core\Ajax\AjaxResponse;
|
||||
use Drupal\Core\Ajax\OpenModalDialogCommand;
|
||||
use Drupal\Core\Form\FormBase;
|
||||
use Drupal\Core\Form\FormBuilderInterface;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\Core\Url;
|
||||
use Drupal\ctools\TypedDataResolver;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
/**
|
||||
* Provider manage resolver relationships.
|
||||
*/
|
||||
abstract class ManageResolverRelationships extends FormBase {
|
||||
|
||||
/**
|
||||
* The machine name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $machine_name;
|
||||
|
||||
/**
|
||||
* An array of property types that are eligible as relationships.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $property_types = [];
|
||||
|
||||
/**
|
||||
* The typed data resolver.
|
||||
*
|
||||
* @var \Drupal\ctools\TypedDataResolver
|
||||
*/
|
||||
protected $typedDataResolver;
|
||||
|
||||
/**
|
||||
* The form builder.
|
||||
*
|
||||
* @var \Drupal\Core\Form\FormBuilder
|
||||
*/
|
||||
protected $formBuilder;
|
||||
|
||||
/**
|
||||
* Constructs a new ManageResolverRelationships object.
|
||||
*
|
||||
* @param \Drupal\ctools\TypedDataResolver $ctools_typed_data_resolver
|
||||
* The typed data resolver.
|
||||
* @param \Drupal\Core\Form\FormBuilderInterface $form_builder
|
||||
* The form builder.
|
||||
*/
|
||||
public function __construct(TypedDataResolver $ctools_typed_data_resolver, FormBuilderInterface $form_builder) {
|
||||
$this->typedDataResolver = $ctools_typed_data_resolver;
|
||||
$this->formBuilder = $form_builder;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function create(ContainerInterface $container) {
|
||||
return new static(
|
||||
$container->get('ctools.typed_data.resolver'),
|
||||
$container->get('form_builder')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFormId() {
|
||||
return 'ctools_manage_resolver_relationships_form';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildForm(array $form, FormStateInterface $form_state) {
|
||||
$cached_values = $form_state->getTemporaryValue('wizard');
|
||||
$this->machine_name = $cached_values['id'];
|
||||
$form['items'] = [
|
||||
'#type' => 'markup',
|
||||
'#prefix' => '<div id="configured-relationships">',
|
||||
'#suffix' => '</div>',
|
||||
'#theme' => 'table',
|
||||
'#header' => [
|
||||
$this->t('Context ID'), $this->t('Label'), $this->t('Data Type'), $this->t('Options'),
|
||||
],
|
||||
'#rows' => $this->renderRows($cached_values),
|
||||
'#empty' => $this->t('No relationships have been added.'),
|
||||
];
|
||||
|
||||
$form['relationships'] = [
|
||||
'#type' => 'select',
|
||||
'#title' => $this->t('Add a relationship'),
|
||||
'#options' => $this->getAvailableRelationships($cached_values),
|
||||
];
|
||||
$form['add_relationship'] = [
|
||||
'#type' => 'submit',
|
||||
'#name' => 'add',
|
||||
'#value' => $this->t('Add Relationship'),
|
||||
'#ajax' => [
|
||||
'callback' => [$this, 'addRelationship'],
|
||||
'event' => 'click',
|
||||
],
|
||||
'#submit' => [
|
||||
'callback' => [$this, 'submitForm'],
|
||||
],
|
||||
];
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function submitForm(array &$form, FormStateInterface $form_state) {
|
||||
if ($form_state->getTriggeringElement()['#name'] == 'add') {
|
||||
$cached_values = $form_state->getTemporaryValue('wizard');
|
||||
list(, $route_parameters) = $this->getRelationshipOperationsRouteInfo($cached_values, $this->machine_name, $form_state->getValue('relationships'));
|
||||
$form_state->setRedirect($this->getAddRoute($cached_values), $route_parameters);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add relationship.
|
||||
*
|
||||
* @param array $form
|
||||
* The form.
|
||||
* @param \Drupal\Core\Form\FormStateInterface $form_state
|
||||
* Stores information about the state of a form.
|
||||
*/
|
||||
public function addRelationship(array &$form, FormStateInterface $form_state) {
|
||||
$relationship = $form_state->getValue('relationships');
|
||||
$content = $this->formBuilder->getForm($this->getContextClass(), $relationship, $this->getTempstoreId(), $this->machine_name);
|
||||
$content['#attached']['library'][] = 'core/drupal.dialog.ajax';
|
||||
$cached_values = $form_state->getTemporaryValue('wizard');
|
||||
list(, $route_parameters) = $this->getRelationshipOperationsRouteInfo($cached_values, $this->machine_name, $relationship);
|
||||
$route_name = $this->getAddRoute($cached_values);
|
||||
$route_options = [
|
||||
'query' => [
|
||||
FormBuilderInterface::AJAX_FORM_REQUEST => TRUE,
|
||||
],
|
||||
];
|
||||
$url = Url::fromRoute($route_name, $route_parameters, $route_options);
|
||||
$content['submit']['#attached']['drupalSettings']['ajax'][$content['submit']['#id']]['url'] = $url->toString();
|
||||
$response = new AjaxResponse();
|
||||
$response->addCommand(new OpenModalDialogCommand($this->t('Configure Relationship'), $content, ['width' => '700']));
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the accesssible relationships.
|
||||
*
|
||||
* @param mixed $cached_values
|
||||
* The arbitrary value from temporary storage.
|
||||
*/
|
||||
protected function getAvailableRelationships($cached_values) {
|
||||
/** @var \Drupal\ctools\TypedDataResolver $resolver */
|
||||
$resolver = $this->typedDataResolver;
|
||||
return $resolver->getTokensForContexts($this->getContexts($cached_values));
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the rows.
|
||||
*
|
||||
* @param mixed $cached_values
|
||||
* The arbitrary value from temporary storage.
|
||||
*
|
||||
* @return array
|
||||
* The array context.
|
||||
*/
|
||||
protected function renderRows($cached_values) {
|
||||
$contexts = [];
|
||||
foreach ($this->getContexts($cached_values) as $row => $context) {
|
||||
list($route_name, $route_parameters) = $this->getRelationshipOperationsRouteInfo($cached_values, $this->machine_name, $row);
|
||||
$build = [
|
||||
'#type' => 'operations',
|
||||
'#links' => $this->getOperations($cached_values, $row, $route_name, $route_parameters),
|
||||
];
|
||||
$contexts[$row] = [
|
||||
$row,
|
||||
$context->getContextDefinition()->getLabel(),
|
||||
$context->getContextDefinition()->getDataType(),
|
||||
'operations' => [
|
||||
'data' => $build,
|
||||
],
|
||||
];
|
||||
}
|
||||
return $contexts;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the operations.
|
||||
*
|
||||
* @param mixed $cached_values
|
||||
* The arbitrary value from temporary storage.
|
||||
* @param string $row
|
||||
* The row.
|
||||
* @param string $route_name_base
|
||||
* The base of route.
|
||||
* @param array $route_parameters
|
||||
* The parameters of route.
|
||||
*
|
||||
* @return mixed
|
||||
* The operations.
|
||||
*/
|
||||
protected function getOperations($cached_values, $row, $route_name_base, array $route_parameters = []) {
|
||||
// Base contexts will not be a :
|
||||
// separated and generated relationships should have 3 parts.
|
||||
if (count(explode(':', $row)) < 2) {
|
||||
return [];
|
||||
}
|
||||
$operations['edit'] = [
|
||||
'title' => $this->t('Edit'),
|
||||
'url' => new Url($route_name_base . '.edit', $route_parameters),
|
||||
'weight' => 10,
|
||||
'attributes' => [
|
||||
'class' => ['use-ajax'],
|
||||
'data-dialog-type' => 'modal',
|
||||
'data-dialog-options' => Json::encode([
|
||||
'width' => 700,
|
||||
]),
|
||||
],
|
||||
];
|
||||
$route_parameters['id'] = $route_parameters['context'];
|
||||
$operations['delete'] = [
|
||||
'title' => $this->t('Delete'),
|
||||
'url' => new Url($route_name_base . '.delete', $route_parameters),
|
||||
'weight' => 100,
|
||||
'attributes' => [
|
||||
'class' => ['use-ajax'],
|
||||
'data-dialog-type' => 'modal',
|
||||
'data-dialog-options' => Json::encode([
|
||||
'width' => 700,
|
||||
]),
|
||||
],
|
||||
];
|
||||
return $operations;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a subclass of '\Drupal\ctools\Form\ResolverRelationshipConfigure'.
|
||||
*
|
||||
* The ConditionConfigure class is designed to be subclassed with custom
|
||||
* route information to control the modal/redirect needs of your use case.
|
||||
*
|
||||
* @return string
|
||||
* Return a subclass of '\Drupal\ctools\Form\ResolverRelationshipConfigure'.
|
||||
*/
|
||||
abstract protected function getContextClass($cached_values);
|
||||
|
||||
/**
|
||||
* The route to which relationship 'add' actions should submit.
|
||||
*
|
||||
* @param mixed $cached_values
|
||||
* The arbitrary value from temporary storage.
|
||||
*
|
||||
* @return string
|
||||
* The route of add action.
|
||||
*/
|
||||
abstract protected function getAddRoute($cached_values);
|
||||
|
||||
/**
|
||||
* Provide the tempstore id for your specified use case.
|
||||
*
|
||||
* @return string
|
||||
* The id of tempstore.
|
||||
*/
|
||||
abstract protected function getTempstoreId();
|
||||
|
||||
/**
|
||||
* Gets the context value.
|
||||
*
|
||||
* @param mixed $cached_values
|
||||
* The arbitrary value from temporary storage.
|
||||
*
|
||||
* @return \Drupal\Core\Plugin\Context\ContextInterface[]
|
||||
* Context data and definitions for plugins supporting
|
||||
* caching and return docs.
|
||||
*/
|
||||
abstract protected function getContexts($cached_values);
|
||||
|
||||
/**
|
||||
* Get relationship operations of route info.
|
||||
*
|
||||
* @param mixed $cached_values
|
||||
* The arbitrary value from temporary storage.
|
||||
* @param string $machine_name
|
||||
* The machine name.
|
||||
* @param string $row
|
||||
* The row.
|
||||
*
|
||||
* @return array
|
||||
* The array of relationship operations.
|
||||
*/
|
||||
abstract protected function getRelationshipOperationsRouteInfo($cached_values, $machine_name, $row);
|
||||
|
||||
}
|
|
@ -0,0 +1,156 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\ctools\Form;
|
||||
|
||||
use Drupal\Core\Ajax\AjaxResponse;
|
||||
use Drupal\Core\Ajax\CloseModalDialogCommand;
|
||||
use Drupal\Core\Ajax\RedirectCommand;
|
||||
use Drupal\Core\Form\FormBase;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\ctools\TypedDataResolver;
|
||||
use Drupal\Core\TempStore\SharedTempStoreFactory;
|
||||
use Drupal\Core\Url;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
|
||||
abstract class RelationshipConfigure extends FormBase {
|
||||
|
||||
/**
|
||||
* @var \Drupal\Core\TempStore\SharedTempStoreFactory
|
||||
*/
|
||||
protected $tempstore;
|
||||
|
||||
/**
|
||||
* @var \Drupal\ctools\TypedDataResolver
|
||||
*/
|
||||
protected $resolver;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $tempstore_id;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $machine_name;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function create(ContainerInterface $container) {
|
||||
return new static($container->get('tempstore.shared'), $container->get('ctools.typed_data.resolver'));
|
||||
}
|
||||
|
||||
|
||||
public function __construct(SharedTempStoreFactory $tempstore, TypedDataResolver $resolver) {
|
||||
$this->tempstore = $tempstore;
|
||||
$this->resolver = $resolver;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFormId() {
|
||||
return 'ctools_relationship_configure';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildForm(array $form, FormStateInterface $form_state, $context_id = NULL, $tempstore_id = NULL, $machine_name = NULL) {
|
||||
$this->tempstore_id = $tempstore_id;
|
||||
$this->machine_name = $machine_name;
|
||||
$cached_values = $this->tempstore->get($this->tempstore_id)->get($this->machine_name);
|
||||
|
||||
/** @var \Drupal\Core\Plugin\Context\ContextInterface[] $contexts */
|
||||
$contexts = $this->getContexts($cached_values);
|
||||
$context_object = $this->resolver->convertTokenToContext($context_id, $contexts);
|
||||
$form['id'] = [
|
||||
'#type' => 'value',
|
||||
'#value' => $context_id,
|
||||
];
|
||||
$form['context_object'] = [
|
||||
'#type' => 'value',
|
||||
'#value' => $context_object,
|
||||
];
|
||||
$form['label'] = [
|
||||
'#type' => 'textfield',
|
||||
'#title' => $this->t('Context label'),
|
||||
'#default_value' => !empty($contexts[$context_id]) ? $contexts[$context_id]->getContextDefinition()->getLabel() : $this->resolver->getLabelByToken($context_id, $contexts),
|
||||
'#required' => TRUE,
|
||||
];
|
||||
$form['context_data'] = [
|
||||
'#type' => 'item',
|
||||
'#title' => $this->t('Data type'),
|
||||
'#markup' => $context_object->getContextDefinition()->getDataType(),
|
||||
];
|
||||
$form['submit'] = [
|
||||
'#type' => 'submit',
|
||||
'#value' => $this->t('Save'),
|
||||
'#ajax' => [
|
||||
'callback' => [$this, 'ajaxSave'],
|
||||
],
|
||||
];
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function submitForm(array &$form, FormStateInterface $form_state) {
|
||||
$cached_values = $this->tempstore->get($this->tempstore_id)->get($this->machine_name);
|
||||
list($route_name, $route_options) = $this->getParentRouteInfo($cached_values);
|
||||
$form_state->setRedirect($route_name, $route_options);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $form
|
||||
* @param \Drupal\Core\Form\FormStateInterface $form_state
|
||||
*
|
||||
* @return \Drupal\Core\Ajax\AjaxResponse
|
||||
*/
|
||||
public function ajaxSave(array &$form, FormStateInterface $form_state) {
|
||||
$cached_values = $this->tempstore->get($this->tempstore_id)->get($this->machine_name);
|
||||
list($route_name, $route_parameters) = $this->getParentRouteInfo($cached_values);
|
||||
$response = new AjaxResponse();
|
||||
$url = Url::fromRoute($route_name, $route_parameters);
|
||||
$response->addCommand(new RedirectCommand($url->toString()));
|
||||
$response->addCommand(new CloseModalDialogCommand());
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Document the route name and parameters for redirect after submission.
|
||||
*
|
||||
* @param array $cached_values
|
||||
*
|
||||
* @return array In the format of
|
||||
* In the format of
|
||||
* return ['route.name', ['machine_name' => $this->machine_name, 'step' => 'step_name']];
|
||||
*/
|
||||
abstract protected function getParentRouteInfo($cached_values);
|
||||
|
||||
/**
|
||||
* Custom logic for setting the conditions array in cached_values.
|
||||
*
|
||||
* @param $cached_values
|
||||
*
|
||||
* @param $contexts
|
||||
* The conditions to set within the cached values.
|
||||
*
|
||||
* @return mixed
|
||||
* Return the $cached_values
|
||||
*/
|
||||
abstract protected function setContexts($cached_values, $contexts);
|
||||
|
||||
/**
|
||||
* Custom logic for retrieving the contexts array from cached_values.
|
||||
*
|
||||
* @param $cached_values
|
||||
*
|
||||
* @return \Drupal\Core\Plugin\Context\ContextInterface[]
|
||||
*/
|
||||
abstract protected function getContexts($cached_values);
|
||||
|
||||
}
|
|
@ -0,0 +1,227 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\ctools\Form;
|
||||
|
||||
use Drupal\Component\Plugin\PluginManagerInterface;
|
||||
use Drupal\Core\Ajax\AjaxResponse;
|
||||
use Drupal\Core\Ajax\OpenModalDialogCommand;
|
||||
use Drupal\Core\Form\FormBase;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\Core\Url;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Drupal\Core\Form\FormBuilderInterface;
|
||||
|
||||
|
||||
abstract class RequiredContext extends FormBase {
|
||||
|
||||
/**
|
||||
* @var \Drupal\Core\TypedData\TypedDataManager
|
||||
*/
|
||||
protected $typedDataManager;
|
||||
|
||||
/**
|
||||
* The builder of form.
|
||||
*
|
||||
* @var \Drupal\Core\Form\FormBuilderInterface
|
||||
*/
|
||||
protected $formBuilder;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $machine_name;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function create(ContainerInterface $container) {
|
||||
return new static(
|
||||
$container->get('typed_data_manager'),
|
||||
$container->get('form_builder')
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
public function __construct(PluginManagerInterface $typed_data_manager, FormBuilderInterface $form_builder) {
|
||||
$this->typedDataManager = $typed_data_manager;
|
||||
$this->formBuilder = $form_builder;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFormId() {
|
||||
return 'ctools_required_context_form';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildForm(array $form, FormStateInterface $form_state) {
|
||||
$cached_values = $form_state->getTemporaryValue('wizard');
|
||||
$this->machine_name = $cached_values['id'];
|
||||
$form['#attached']['library'][] = 'core/drupal.dialog.ajax';
|
||||
$options = [];
|
||||
foreach ($this->typedDataManager->getDefinitions() as $plugin_id => $definition) {
|
||||
$options[$plugin_id] = (string) $definition['label'];
|
||||
}
|
||||
$form['items'] = [
|
||||
'#type' => 'markup',
|
||||
'#prefix' => '<div id="configured-contexts">',
|
||||
'#suffix' => '</div>',
|
||||
'#theme' => 'table',
|
||||
'#header' => [$this->t('Information'), $this->t('Description'), $this->t('Operations')],
|
||||
'#rows' => $this->renderContexts($cached_values),
|
||||
'#empty' => $this->t('No required contexts have been configured.'),
|
||||
];
|
||||
$form['contexts'] = [
|
||||
'#type' => 'select',
|
||||
'#options' => $options,
|
||||
];
|
||||
$form['add'] = [
|
||||
'#type' => 'submit',
|
||||
'#name' => 'add',
|
||||
'#value' => $this->t('Add required context'),
|
||||
'#ajax' => [
|
||||
'callback' => [$this, 'add'],
|
||||
'event' => 'click',
|
||||
],
|
||||
'#submit' => [
|
||||
'callback' => [$this, 'submitform'],
|
||||
],
|
||||
];
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function submitForm(array &$form, FormStateInterface $form_state) {
|
||||
$cached_values = $form_state->getTemporaryValue('wizard');
|
||||
list($route_name, $route_parameters) = $this->getOperationsRouteInfo($cached_values, $this->machine_name, $form_state->getValue('contexts'));
|
||||
$form_state->setRedirect($route_name . '.edit', $route_parameters);
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom ajax form submission handler.
|
||||
*
|
||||
* @param array $form
|
||||
* @param \Drupal\Core\Form\FormStateInterface $form_state
|
||||
*
|
||||
* @return \Drupal\Core\Ajax\AjaxResponse
|
||||
*/
|
||||
public function add(array &$form, FormStateInterface $form_state) {
|
||||
$context = $form_state->getValue('contexts');
|
||||
$content = $this->formBuilder->getForm($this->getContextClass(), $context, $this->getTempstoreId(), $this->machine_name);
|
||||
$content['#attached']['library'][] = 'core/drupal.dialog.ajax';
|
||||
$response = new AjaxResponse();
|
||||
$response->addCommand(new OpenModalDialogCommand($this->t('Configure Required Context'), $content, ['width' => '700']));
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $cached_values
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function renderContexts($cached_values) {
|
||||
$configured_contexts = [];
|
||||
foreach ($this->getContexts($cached_values) as $row => $context) {
|
||||
list($plugin_id, $label, $machine_name, $description) = array_values($context);
|
||||
list($route_name, $route_parameters) = $this->getOperationsRouteInfo($cached_values, $cached_values['id'], $row);
|
||||
$build = [
|
||||
'#type' => 'operations',
|
||||
'#links' => $this->getOperations($route_name, $route_parameters),
|
||||
];
|
||||
$configured_contexts[] = [
|
||||
$this->t('<strong>Label:</strong> @label<br /> <strong>Type:</strong> @type', ['@label' => $label, '@type' => $plugin_id]),
|
||||
$this->t('@description', ['@description' => $description]),
|
||||
'operations' => [
|
||||
'data' => $build,
|
||||
],
|
||||
];
|
||||
}
|
||||
return $configured_contexts;
|
||||
}
|
||||
|
||||
|
||||
protected function getOperations($route_name_base, array $route_parameters = []) {
|
||||
$operations['edit'] = [
|
||||
'title' => $this->t('Edit'),
|
||||
'url' => new Url($route_name_base . '.edit', $route_parameters),
|
||||
'weight' => 10,
|
||||
'attributes' => [
|
||||
'class' => ['use-ajax'],
|
||||
'data-accepts' => 'application/vnd.drupal-modal',
|
||||
'data-dialog-options' => json_encode([
|
||||
'width' => 700,
|
||||
]),
|
||||
],
|
||||
'ajax' => [
|
||||
'',
|
||||
],
|
||||
];
|
||||
$route_parameters['id'] = $route_parameters['context'];
|
||||
$operations['delete'] = [
|
||||
'title' => $this->t('Delete'),
|
||||
'url' => new Url($route_name_base . '.delete', $route_parameters),
|
||||
'weight' => 100,
|
||||
'attributes' => [
|
||||
'class' => ['use-ajax'],
|
||||
'data-accepts' => 'application/vnd.drupal-modal',
|
||||
'data-dialog-options' => json_encode([
|
||||
'width' => 700,
|
||||
]),
|
||||
],
|
||||
];
|
||||
return $operations;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a subclass of '\Drupal\ctools\Form\ContextConfigure'.
|
||||
*
|
||||
* The ContextConfigure class is designed to be subclassed with custom route
|
||||
* information to control the modal/redirect needs of your use case.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
abstract protected function getContextClass();
|
||||
|
||||
/**
|
||||
* Provide the tempstore id for your specified use case.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
abstract protected function getTempstoreId();
|
||||
|
||||
/**
|
||||
* Document the route name and parameters for edit/delete context operations.
|
||||
*
|
||||
* The route name returned from this method is used as a "base" to which
|
||||
* ".edit" and ".delete" are appended in the getOperations() method.
|
||||
* Subclassing '\Drupal\ctools\Form\ContextConfigure' and
|
||||
* '\Drupal\ctools\Form\RequiredContextDelete' should set you up for using
|
||||
* this approach quite seamlessly.
|
||||
*
|
||||
* @param mixed $cached_values
|
||||
*
|
||||
* @param string $machine_name
|
||||
*
|
||||
* @param string $row
|
||||
*
|
||||
* @return array
|
||||
* In the format of
|
||||
* return ['route.base.name', ['machine_name' => $machine_name, 'context' => $row]];
|
||||
*/
|
||||
abstract protected function getOperationsRouteInfo($cached_values, $machine_name, $row);
|
||||
|
||||
/**
|
||||
* Custom logic for retrieving the contexts array from cached_values.
|
||||
*
|
||||
* @param $cached_values
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
abstract protected function getContexts($cached_values);
|
||||
|
||||
}
|
|
@ -0,0 +1,194 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\ctools\Form;
|
||||
|
||||
use Drupal\Core\Form\ConfirmFormBase;
|
||||
use Drupal\Core\Form\ConfirmFormHelper;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\Core\Url;
|
||||
use Drupal\Core\TempStore\SharedTempStoreFactory;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
/**
|
||||
* Base class for adding a required contexts step to your wizard.
|
||||
*/
|
||||
abstract class RequiredContextDelete extends ConfirmFormBase {
|
||||
|
||||
/**
|
||||
* @var \Drupal\Core\TempStore\SharedTempStoreFactory
|
||||
*/
|
||||
protected $tempstore;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $tempstore_id;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $machine_name;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $id;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function create(ContainerInterface $container) {
|
||||
return new static($container->get('tempstore.shared'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Drupal\Core\TempStore\SharedTempStoreFactory $tempstore
|
||||
*/
|
||||
public function __construct(SharedTempStoreFactory $tempstore) {
|
||||
$this->tempstore = $tempstore;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFormId() {
|
||||
return 'ctools_required_context_delete';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildForm(array $form, FormStateInterface $form_state, $id = NULL, $tempstore_id = NULL, $machine_name = NULL) {
|
||||
$this->tempstore_id = $tempstore_id;
|
||||
$this->machine_name = $machine_name;
|
||||
$this->id = $id;
|
||||
|
||||
$cached_values = $this->tempstore->get($this->tempstore_id)->get($this->machine_name);
|
||||
$form['#title'] = $this->getQuestion($id, $cached_values);
|
||||
|
||||
$form['#attributes']['class'][] = 'confirmation';
|
||||
$form['description'] = ['#markup' => $this->getDescription()];
|
||||
$form[$this->getFormName()] = ['#type' => 'hidden', '#value' => 1];
|
||||
|
||||
// By default, render the form using theme_confirm_form().
|
||||
if (!isset($form['#theme'])) {
|
||||
$form['#theme'] = 'confirm_form';
|
||||
}
|
||||
$form['actions'] = ['#type' => 'actions'];
|
||||
$form['actions'] += $this->actions($form, $form_state);
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function submitForm(array &$form, FormStateInterface $form_state) {
|
||||
$cached_values = $this->tempstore->get($this->tempstore_id)->get($this->machine_name);
|
||||
$contexts = $this->getContexts($cached_values);
|
||||
unset($contexts[$this->id]);
|
||||
$cached_values = $this->setContexts($cached_values, $contexts);
|
||||
$this->tempstore->get($this->tempstore_id)->set($this->machine_name, $cached_values);
|
||||
list($route_name, $route_parameters) = $this->getParentRouteInfo($cached_values);
|
||||
$form_state->setRedirect($route_name, $route_parameters);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getQuestion($id = NULL, $cached_values = NULL) {
|
||||
$context = $this->getContexts($cached_values)[$id];
|
||||
return $this->t('Are you sure you want to delete the @label context?', [
|
||||
'@label' => $context['label'],
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getDescription() {
|
||||
return $this->t('This action cannot be undone.');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFormName() {
|
||||
return 'confirm';
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides the action buttons for submitting this form.
|
||||
*/
|
||||
protected function actions(array $form, FormStateInterface $form_state) {
|
||||
return [
|
||||
'submit' => [
|
||||
'#type' => 'submit',
|
||||
'#value' => $this->getConfirmText(),
|
||||
'#validate' => [
|
||||
[$this, 'validate'],
|
||||
],
|
||||
'#submit' => [
|
||||
[$this, 'submitForm'],
|
||||
],
|
||||
],
|
||||
'cancel' => ConfirmFormHelper::buildCancelLink($this, $this->getRequest()),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getCancelUrl() {
|
||||
$cached_values = $this->tempstore->get($this->tempstore_id)->get($this->machine_name);
|
||||
list($route_name, $route_parameters) = $this->getParentRouteInfo($cached_values);
|
||||
return new Url($route_name, $route_parameters);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getConfirmText() {
|
||||
return $this->t('Delete');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getCancelText() {
|
||||
return $this->t('Cancel');
|
||||
}
|
||||
|
||||
/**
|
||||
* Document the route name and parameters for redirect after submission.
|
||||
*
|
||||
* @param $cached_values
|
||||
*
|
||||
* @return array
|
||||
* In the format of
|
||||
* return ['route.name', ['machine_name' => $this->machine_name, 'step' => 'step_name]];
|
||||
*/
|
||||
abstract protected function getParentRouteInfo($cached_values);
|
||||
|
||||
/**
|
||||
* Custom logic for retrieving the contexts array from cached_values.
|
||||
*
|
||||
* @param $cached_values
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
abstract protected function getContexts($cached_values);
|
||||
|
||||
/**
|
||||
* Custom logic for setting the contexts array in cached_values.
|
||||
*
|
||||
* @param $cached_values
|
||||
*
|
||||
* @param $contexts
|
||||
* The contexts to set within the cached values.
|
||||
*
|
||||
* @return mixed
|
||||
* Return the $cached_values
|
||||
*/
|
||||
abstract protected function setContexts($cached_values, $contexts);
|
||||
|
||||
}
|
|
@ -0,0 +1,187 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\ctools\Form;
|
||||
|
||||
use Drupal\Core\Ajax\AjaxResponse;
|
||||
use Drupal\Core\Ajax\CloseModalDialogCommand;
|
||||
use Drupal\Core\Ajax\RedirectCommand;
|
||||
use Drupal\Core\Form\FormBase;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\Core\TempStore\SharedTempStoreFactory;
|
||||
use Drupal\Core\Url;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
|
||||
abstract class ResolverRelationshipConfigure extends FormBase {
|
||||
|
||||
/**
|
||||
* @var \Drupal\Core\TempStore\SharedTempStoreFactory
|
||||
*/
|
||||
protected $tempstore;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $tempstore_id;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $machine_name;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function create(ContainerInterface $container) {
|
||||
return new static($container->get('tempstore.shared'));
|
||||
}
|
||||
|
||||
|
||||
public function __construct(SharedTempStoreFactory $tempstore) {
|
||||
$this->tempstore = $tempstore;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFormId() {
|
||||
return 'ctools_context_configure';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildForm(array $form, FormStateInterface $form_state, $context = NULL, $tempstore_id = NULL, $machine_name = NULL) {
|
||||
$this->tempstore_id = $tempstore_id;
|
||||
$this->machine_name = $machine_name;
|
||||
$cached_values = $this->tempstore->get($this->tempstore_id)->get($this->machine_name);
|
||||
if (is_numeric($context)) {
|
||||
$id = $context;
|
||||
$contexts = $this->getContexts($cached_values);
|
||||
$context = $contexts[$id]['context'];
|
||||
$label = $contexts[$id]['label'];
|
||||
$machine_name = $contexts[$id]['machine_name'];
|
||||
$description = $contexts[$id]['description'];
|
||||
// Conditionally set this form element so that we can update or add.
|
||||
$form['id'] = [
|
||||
'#type' => 'value',
|
||||
'#value' => $id,
|
||||
];
|
||||
}
|
||||
else {
|
||||
$label = '';
|
||||
$machine_name = '';
|
||||
$description = '';
|
||||
}
|
||||
$form['#attached']['library'][] = 'core/drupal.dialog.ajax';
|
||||
$form['context'] = [
|
||||
'#type' => 'value',
|
||||
'#value' => $context,
|
||||
];
|
||||
$form['label'] = [
|
||||
'#type' => 'textfield',
|
||||
'#title' => $this->t('Label'),
|
||||
'#default_value' => $label,
|
||||
'#required' => TRUE,
|
||||
];
|
||||
$form['machine_name'] = [
|
||||
'#type' => 'textfield',
|
||||
'#title' => $this->t('Machine Name'),
|
||||
'#default_value' => $machine_name,
|
||||
'#required' => TRUE,
|
||||
];
|
||||
$form['description'] = [
|
||||
'#type' => 'textarea',
|
||||
'#title' => $this->t('Description'),
|
||||
'#default_value' => $description,
|
||||
];
|
||||
$form['submit'] = [
|
||||
'#type' => 'submit',
|
||||
'#value' => $this->t('Save'),
|
||||
'#ajax' => [
|
||||
'callback' => [$this, 'ajaxSave'],
|
||||
],
|
||||
];
|
||||
return $form;
|
||||
}
|
||||
|
||||
|
||||
public function validateForm(array &$form, FormStateInterface $form_state) {
|
||||
$machine_name = $form_state->getValue('machine_name');
|
||||
$cached_values = $this->tempstore->get($this->tempstore_id)->get($this->machine_name);
|
||||
foreach ($this->getContexts($cached_values) as $id => $context) {
|
||||
if ($context['machine_name'] == $machine_name) {
|
||||
$form_state->setError($form['machine_name'], $this->t('That machine name is in use by another context definition.'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function submitForm(array &$form, FormStateInterface $form_state) {
|
||||
$cached_values = $this->tempstore->get($this->tempstore_id)->get($this->machine_name);
|
||||
$contexts = $this->getContexts($cached_values);
|
||||
$context = [
|
||||
'context' => $form_state->getValue('context'),
|
||||
'label' => $form_state->getValue('label'),
|
||||
'machine_name' => $form_state->getValue('machine_name'),
|
||||
'description' => $form_state->getValue('description'),
|
||||
];
|
||||
if ($form_state->hasValue('id')) {
|
||||
$contexts[$form_state->getValue('id')] = $context;
|
||||
}
|
||||
else {
|
||||
$contexts[] = $context;
|
||||
}
|
||||
$cached_values = $this->setContexts($cached_values, $contexts);
|
||||
$this->tempstore->get($this->tempstore_id)->set($this->machine_name, $cached_values);
|
||||
list($route_name, $route_parameters) = $this->getParentRouteInfo($cached_values);
|
||||
$form_state->setRedirect($route_name, $route_parameters);
|
||||
}
|
||||
|
||||
|
||||
public function ajaxSave(array &$form, FormStateInterface $form_state) {
|
||||
$response = new AjaxResponse();
|
||||
$cached_values = $this->tempstore->get($this->tempstore_id)->get($this->machine_name);
|
||||
list($route_name, $route_parameters) = $this->getParentRouteInfo($cached_values);
|
||||
$url = Url::fromRoute($route_name, $route_parameters);
|
||||
$response->addCommand(new RedirectCommand($url->toString()));
|
||||
$response->addCommand(new CloseModalDialogCommand());
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Document the route name and parameters for redirect after submission.
|
||||
*
|
||||
* @param $cached_values
|
||||
*
|
||||
* @return array
|
||||
* In the format of
|
||||
* return ['route.name', ['machine_name' => $this->machine_name, 'step' => 'step_name]];
|
||||
*/
|
||||
abstract protected function getParentRouteInfo($cached_values);
|
||||
|
||||
/**
|
||||
* Custom logic for retrieving the contexts array from cached_values.
|
||||
*
|
||||
* @param $cached_values
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
abstract protected function getContexts($cached_values);
|
||||
|
||||
/**
|
||||
* Custom logic for setting the contexts array in cached_values.
|
||||
*
|
||||
* @param $cached_values
|
||||
*
|
||||
* @param $contexts
|
||||
* The contexts to set within the cached values.
|
||||
*
|
||||
* @return mixed
|
||||
* Return the $cached_values
|
||||
*/
|
||||
abstract protected function setContexts($cached_values, $contexts);
|
||||
|
||||
}
|
|
@ -0,0 +1,150 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\ctools\Form;
|
||||
|
||||
use Drupal\Core\Form\ConfirmFormBase;
|
||||
use Drupal\Core\Form\ConfirmFormHelper;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\ctools\TypedDataResolver;
|
||||
use Drupal\Core\TempStore\SharedTempStoreFactory;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
|
||||
abstract class ResolverRelationshipDelete extends ConfirmFormBase {
|
||||
|
||||
/**
|
||||
* @var \Drupal\Core\TempStore\SharedTempStoreFactory
|
||||
*/
|
||||
protected $tempstore;
|
||||
|
||||
/**
|
||||
* @var \Drupal\ctools\TypedDataResolver
|
||||
*/
|
||||
protected $resolver;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $tempstore_id;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $machine_name;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $id;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function create(ContainerInterface $container) {
|
||||
return new static($container->get('tempstore.shared'), $container->get('ctools.typed_data.resolver'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Drupal\Core\TempStore\SharedTempStoreFactory $tempstore
|
||||
* The shared tempstore.
|
||||
* @param \Drupal\ctools\TypedDataResolver $resolver
|
||||
* The typed data resolver.
|
||||
*/
|
||||
public function __construct(SharedTempStoreFactory $tempstore, TypedDataResolver $resolver) {
|
||||
$this->tempstore = $tempstore;
|
||||
$this->resolver = $resolver;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFormId() {
|
||||
return 'ctools_resolver_relationship_delete';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getQuestion($id = NULL, $cached_values = []) {
|
||||
$context = $this->getContexts($cached_values)[$id];
|
||||
return $this->t('Are you sure you want to delete the @label relationship?', [
|
||||
'@label' => $context->getContextDefinition()->getLabel(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
abstract public function getCancelUrl($cached_values = []);
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildForm(array $form, FormStateInterface $form_state, $id = NULL, $tempstore_id = NULL, $machine_name = NULL) {
|
||||
$this->tempstore_id = $tempstore_id;
|
||||
$this->machine_name = $machine_name;
|
||||
$this->id = $id;
|
||||
|
||||
$cached_values = $this->tempstore->get($this->tempstore_id)->get($this->machine_name);
|
||||
$form['#title'] = $this->getQuestion($id, $cached_values);
|
||||
|
||||
$form['#attributes']['class'][] = 'confirmation';
|
||||
$form['description'] = ['#markup' => $this->getDescription()];
|
||||
$form[$this->getFormName()] = ['#type' => 'hidden', '#value' => 1];
|
||||
|
||||
// By default, render the form using theme_confirm_form().
|
||||
if (!isset($form['#theme'])) {
|
||||
$form['#theme'] = 'confirm_form';
|
||||
}
|
||||
$form['actions'] = ['#type' => 'actions'];
|
||||
$form['actions'] += $this->actions($form, $form_state, $cached_values);
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function submitForm(array &$form, FormStateInterface $form_state) {
|
||||
$cached_values = $this->tempstore->get($this->tempstore_id)->get($this->machine_name);
|
||||
$form_state->setRedirectUrl($this->getCancelUrl($cached_values));
|
||||
}
|
||||
|
||||
/**
|
||||
* A custom form actions method.
|
||||
*
|
||||
* @param array $form
|
||||
* The form array.
|
||||
* @param \Drupal\Core\Form\FormStateInterface $form_state
|
||||
* The current form state.
|
||||
* @param $cached_values
|
||||
* The current wizard cached values.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function actions(array $form, FormStateInterface $form_state, $cached_values) {
|
||||
return [
|
||||
'submit' => [
|
||||
'#type' => 'submit',
|
||||
'#value' => $this->getConfirmText(),
|
||||
'#validate' => [
|
||||
[$this, 'validate'],
|
||||
],
|
||||
'#submit' => [
|
||||
[$this, 'submitForm'],
|
||||
],
|
||||
],
|
||||
'cancel' => ConfirmFormHelper::buildCancelLink($this, $this->getRequest()),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract contexts from the cached values.
|
||||
*
|
||||
* @param array $cached_values
|
||||
* The cached values.
|
||||
*
|
||||
* @return \Drupal\Core\Plugin\Context\ContextInterface[]
|
||||
*/
|
||||
abstract public function getContexts($cached_values);
|
||||
|
||||
}
|
|
@ -0,0 +1,168 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\ctools\ParamConverter;
|
||||
|
||||
use Drupal\Component\Utility\NestedArray;
|
||||
use Drupal\Core\Entity\EntityTypeManagerInterface;
|
||||
use Drupal\Core\ParamConverter\ParamConverterInterface;
|
||||
use Drupal\Core\TempStore\SharedTempStoreFactory;
|
||||
use Symfony\Component\Routing\Route;
|
||||
|
||||
/**
|
||||
* Parameter converter for pulling entities out of the tempstore.
|
||||
*
|
||||
* This is particularly useful when building non-wizard forms (like dialogs)
|
||||
* that operate on data in the wizard and getting the route access correct.
|
||||
*
|
||||
* There are four different ways to use this!
|
||||
*
|
||||
* In the most basic way, you specify the 'tempstore_id' in the defaults (so
|
||||
* that the form/controller has access to it as well) and in the parameter type
|
||||
* we simply give 'tempstore'. This assumes the entity is the full value
|
||||
* returned from the tempstore.
|
||||
*
|
||||
* @code
|
||||
* example.route:
|
||||
* path: foo/{example}
|
||||
* defaults:
|
||||
* tempstore_id: example.foo
|
||||
* options:
|
||||
* parameters:
|
||||
* example:
|
||||
* type: tempstore
|
||||
* @endcode
|
||||
*
|
||||
* If the value returned from the tempstore is an array, and the entity is
|
||||
* one of the keys, then we specify that after 'tempstore:', for example:
|
||||
*
|
||||
* @code
|
||||
* example.route:
|
||||
* path: foo/{example}
|
||||
* defaults:
|
||||
* tempstore_id: example.foo
|
||||
* options:
|
||||
* parameters:
|
||||
* example:
|
||||
* # Get the 'foo' key from the array returned by the tempstore.
|
||||
* type: tempstore:foo
|
||||
* @endcode
|
||||
*
|
||||
* You can also specify the 'tempstore_id' under the parameter rather than in
|
||||
* the defaults, for example:
|
||||
*
|
||||
* @code
|
||||
* example.route:
|
||||
* path: foo/{example}
|
||||
* options:
|
||||
* parameters:
|
||||
* example:
|
||||
* type: tempstore:foo
|
||||
* tempstore_id: example.foo
|
||||
* @endcode
|
||||
*
|
||||
* Or, if you have two parameters which are represented by two keys on the same
|
||||
* array from the tempstore, put the slug which represents the id for the
|
||||
* tempstore in the 2nd key. For example:
|
||||
*
|
||||
* @code
|
||||
* example.route:
|
||||
* path: foo/{example}/{other}
|
||||
* defaults:
|
||||
* tempstore_id: example.foo
|
||||
* options:
|
||||
* parameters:
|
||||
* example:
|
||||
* type: tempstore:foo
|
||||
* other:
|
||||
* type: tempstore:{example}:other
|
||||
* @endcode
|
||||
*/
|
||||
class TempstoreConverter implements ParamConverterInterface {
|
||||
|
||||
/**
|
||||
* The tempstore factory.
|
||||
*
|
||||
* @var \Drupal\Core\TempStore\SharedTempStoreFactory
|
||||
*/
|
||||
protected $tempstore;
|
||||
|
||||
/**
|
||||
* The entity type manager.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
|
||||
*/
|
||||
protected $entityTypeManager;
|
||||
|
||||
/**
|
||||
* Constructs a TempstoreConverter.
|
||||
*
|
||||
* @param \Drupal\Core\TempStore\SharedTempStoreFactory $tempstore
|
||||
*/
|
||||
public function __construct(SharedTempStoreFactory $tempstore, EntityTypeManagerInterface $entity_type_manager) {
|
||||
$this->tempstore = $tempstore;
|
||||
$this->entityTypeManager = $entity_type_manager;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function convert($value, $definition, $name, array $defaults) {
|
||||
$tempstore_id = !empty($definition['tempstore_id']) ? $definition['tempstore_id'] : $defaults['tempstore_id'];
|
||||
$machine_name = $this->convertVariable($value, $defaults);
|
||||
|
||||
list(, $parts) = explode(':', $definition['type'], 2);
|
||||
$parts = explode(':', $parts);
|
||||
foreach ($parts as $key => $part) {
|
||||
$parts[$key] = $this->convertVariable($part, $defaults);
|
||||
}
|
||||
$cached_values = $this->tempstore->get($tempstore_id)->get($machine_name);
|
||||
// Entity type upcasting is most common, so we just assume that here.
|
||||
// @todo see if there's a better way to do this.
|
||||
if (!$cached_values && $this->entityTypeManager->hasDefinition($name)) {
|
||||
$value = $this->entityTypeManager->getStorage($name)->load($machine_name);
|
||||
return $value;
|
||||
}
|
||||
elseif (!$cached_values) {
|
||||
return NULL;
|
||||
}
|
||||
else {
|
||||
$value = NestedArray::getValue($cached_values, $parts, $key_exists);
|
||||
return $key_exists ? $value : NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A helper function for converting string variable names from the defaults.
|
||||
*
|
||||
* @param mixed $name
|
||||
* If name is a string in the format of {var} it will parse the defaults
|
||||
* for a 'var' default. If $name isn't a string or isn't a slug, it will
|
||||
* return the raw $name value. If no default is found, it will return NULL.
|
||||
* @param array $defaults
|
||||
* The route defaults array.
|
||||
*
|
||||
* @return mixed
|
||||
* The value of a variable in defaults.
|
||||
*/
|
||||
protected function convertVariable($name, $defaults) {
|
||||
if (is_string($name) && strpos($name, '{') === 0) {
|
||||
$length = strlen($name);
|
||||
$name = substr($name, 1, $length - 2);
|
||||
return isset($defaults[$name]) ? $defaults[$name] : NULL;
|
||||
}
|
||||
return $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function applies($definition, $name, Route $route) {
|
||||
if (!empty($definition['type']) && ($definition['type'] == 'tempstore' || strpos($definition['type'], 'tempstore:') === 0)) {
|
||||
if (!empty($definition['tempstore_id']) || $route->hasDefault('tempstore_id')) {
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,134 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\ctools\Plugin\Block;
|
||||
|
||||
use Drupal\Core\Block\BlockBase;
|
||||
use Drupal\Core\Cache\CacheableMetadata;
|
||||
use Drupal\Core\Entity\EntityTypeManagerInterface;
|
||||
use Drupal\Core\Entity\EntityDisplayRepositoryInterface;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
|
||||
use Drupal\Core\Plugin\ContextAwarePluginInterface;
|
||||
use Drupal\Core\Session\AccountInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
/**
|
||||
* Provides a block to view a specific entity.
|
||||
*
|
||||
* @Block(
|
||||
* id = "entity_view",
|
||||
* deriver = "Drupal\ctools\Plugin\Deriver\EntityViewDeriver",
|
||||
* )
|
||||
*/
|
||||
class EntityView extends BlockBase implements ContextAwarePluginInterface, ContainerFactoryPluginInterface {
|
||||
|
||||
/**
|
||||
* The entity type manager.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
|
||||
*/
|
||||
protected $entityTypeManager;
|
||||
|
||||
/**
|
||||
* The entity display repository.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityDisplayRepositoryInterface
|
||||
*/
|
||||
protected $entityDisplayRepository;
|
||||
|
||||
/**
|
||||
* Constructs a new EntityView.
|
||||
*
|
||||
* @param array $configuration
|
||||
* A configuration array containing information about the plugin instance.
|
||||
* @param string $plugin_id
|
||||
* The plugin ID for the plugin instance.
|
||||
* @param mixed $plugin_definition
|
||||
* The plugin implementation definition.
|
||||
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
|
||||
* The entity type manager.
|
||||
* @param \Drupal\Core\Entity\EntityDisplayRepositoryInterface $entity_display_repository
|
||||
* The entity display repository.
|
||||
*/
|
||||
public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entity_type_manager, EntityDisplayRepositoryInterface $entity_display_repository) {
|
||||
parent::__construct($configuration, $plugin_id, $plugin_definition);
|
||||
|
||||
$this->entityTypeManager = $entity_type_manager;
|
||||
$this->entityDisplayRepository = $entity_display_repository;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
|
||||
return new static(
|
||||
$configuration,
|
||||
$plugin_id,
|
||||
$plugin_definition,
|
||||
$container->get('entity_type.manager'),
|
||||
$container->get('entity_display.repository')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function defaultConfiguration() {
|
||||
return [
|
||||
'view_mode' => 'default',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function blockForm($form, FormStateInterface $form_state) {
|
||||
$form['view_mode'] = [
|
||||
'#type' => 'select',
|
||||
'#options' => $this->entityDisplayRepository->getViewModeOptions($this->getDerivativeId()),
|
||||
'#title' => $this->t('View mode'),
|
||||
'#default_value' => $this->configuration['view_mode'],
|
||||
];
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function blockSubmit($form, FormStateInterface $form_state) {
|
||||
$this->configuration['view_mode'] = $form_state->getValue('view_mode');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function access(AccountInterface $account, $return_as_object = FALSE) {
|
||||
// Check the parent's access.
|
||||
$parent_access = parent::access($account, TRUE);
|
||||
if (!$parent_access->isAllowed()) {
|
||||
return $return_as_object ? $parent_access : $parent_access->isAllowed();
|
||||
}
|
||||
|
||||
/** @var $entity \Drupal\Core\Entity\EntityInterface */
|
||||
$entity = $this->getContextValue('entity');
|
||||
return $entity->access('view', $account, $return_as_object);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function build() {
|
||||
/** @var $entity \Drupal\Core\Entity\EntityInterface */
|
||||
$entity = $this->getContextValue('entity');
|
||||
|
||||
$view_builder = $this->entityTypeManager->getViewBuilder($entity->getEntityTypeId());
|
||||
$build = $view_builder->view($entity, $this->configuration['view_mode']);
|
||||
|
||||
CacheableMetadata::createFromObject($entity)
|
||||
->merge(CacheableMetadata::createFromRenderArray($build))
|
||||
->applyTo($build);
|
||||
|
||||
return $build;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\ctools\Plugin;
|
||||
|
||||
use Drupal\Core\Block\BlockPluginInterface;
|
||||
use Drupal\Core\Plugin\DefaultLazyPluginCollection;
|
||||
|
||||
/**
|
||||
* Provides a collection of block plugins.
|
||||
*/
|
||||
class BlockPluginCollection extends DefaultLazyPluginCollection {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @return \Drupal\Core\Block\BlockPluginInterface
|
||||
*/
|
||||
public function &get($instance_id) {
|
||||
return parent::get($instance_id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all blocks keyed by their region.
|
||||
*
|
||||
* @return array
|
||||
* An associative array keyed by region, containing an associative array of
|
||||
* block plugins.
|
||||
*/
|
||||
public function getAllByRegion() {
|
||||
$region_assignments = [];
|
||||
foreach ($this as $block_id => $block) {
|
||||
$configuration = $block->getConfiguration();
|
||||
$region = isset($configuration['region']) ? $configuration['region'] : NULL;
|
||||
$region_assignments[$region][$block_id] = $block;
|
||||
}
|
||||
foreach ($region_assignments as $region => $region_assignment) {
|
||||
// @todo Determine the reason this needs error suppression.
|
||||
@uasort($region_assignment, function (BlockPluginInterface $a, BlockPluginInterface $b) {
|
||||
$a_config = $a->getConfiguration();
|
||||
$a_weight = isset($a_config['weight']) ? $a_config['weight'] : 0;
|
||||
$b_config = $b->getConfiguration();
|
||||
$b_weight = isset($b_config['weight']) ? $b_config['weight'] : 0;
|
||||
if ($a_weight == $b_weight) {
|
||||
return strcmp($a->label(), $b->label());
|
||||
}
|
||||
return $a_weight > $b_weight ? 1 : -1;
|
||||
});
|
||||
$region_assignments[$region] = $region_assignment;
|
||||
}
|
||||
return $region_assignments;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,96 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\ctools\Plugin;
|
||||
|
||||
use Drupal\Core\Display\VariantInterface;
|
||||
|
||||
/**
|
||||
* Provides an interface for variant plugins that use block plugins.
|
||||
*/
|
||||
interface BlockVariantInterface extends VariantInterface {
|
||||
|
||||
/**
|
||||
* Returns the human-readable list of regions keyed by machine name.
|
||||
*
|
||||
* @return array
|
||||
* An array of human-readable region names keyed by machine name.
|
||||
*/
|
||||
public function getRegionNames();
|
||||
|
||||
/**
|
||||
* Returns the human-readable name of a specific region.
|
||||
*
|
||||
* @param string $region
|
||||
* The machine name of a region.
|
||||
*
|
||||
* @return string
|
||||
* The human-readable name of a region.
|
||||
*/
|
||||
public function getRegionName($region);
|
||||
|
||||
/**
|
||||
* Adds a block to this display variant.
|
||||
*
|
||||
* @param array $configuration
|
||||
* An array of block configuration.
|
||||
*
|
||||
* @return string
|
||||
* The block ID.
|
||||
*/
|
||||
public function addBlock(array $configuration);
|
||||
|
||||
/**
|
||||
* Returns the region a specific block is assigned to.
|
||||
*
|
||||
* @param string $block_id
|
||||
* The block ID.
|
||||
*
|
||||
* @return string
|
||||
* The machine name of the region this block is assigned to.
|
||||
*/
|
||||
public function getRegionAssignment($block_id);
|
||||
|
||||
/**
|
||||
* Returns an array of regions and their block plugins.
|
||||
*
|
||||
* @return array
|
||||
* The array is first keyed by region machine name, with the values
|
||||
* containing an array keyed by block ID, with block plugin instances as the
|
||||
* values.
|
||||
*/
|
||||
public function getRegionAssignments();
|
||||
|
||||
/**
|
||||
* Returns a specific block plugin.
|
||||
*
|
||||
* @param string $block_id
|
||||
* The block ID.
|
||||
*
|
||||
* @return \Drupal\Core\Block\BlockPluginInterface
|
||||
* The block plugin.
|
||||
*/
|
||||
public function getBlock($block_id);
|
||||
|
||||
/**
|
||||
* Updates the configuration of a specific block plugin.
|
||||
*
|
||||
* @param string $block_id
|
||||
* The block ID.
|
||||
* @param array $configuration
|
||||
* The array of configuration to set.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function updateBlock($block_id, array $configuration);
|
||||
|
||||
/**
|
||||
* Removes a specific block from this display variant.
|
||||
*
|
||||
* @param string $block_id
|
||||
* The block ID.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function removeBlock($block_id);
|
||||
|
||||
}
|
|
@ -0,0 +1,170 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\ctools\Plugin;
|
||||
|
||||
use Drupal\ctools\Event\BlockVariantEvent;
|
||||
use Drupal\ctools\Event\BlockVariantEvents;
|
||||
|
||||
/**
|
||||
* Provides methods for \Drupal\ctools\Plugin\BlockVariantInterface.
|
||||
*/
|
||||
trait BlockVariantTrait {
|
||||
|
||||
/**
|
||||
* The block manager.
|
||||
*
|
||||
* @var \Drupal\Core\Block\BlockManager
|
||||
*/
|
||||
protected $blockManager;
|
||||
|
||||
/**
|
||||
* The plugin collection that holds the block plugins.
|
||||
*
|
||||
* @var \Drupal\ctools\Plugin\BlockPluginCollection
|
||||
*/
|
||||
protected $blockPluginCollection;
|
||||
|
||||
/**
|
||||
* The event dispatcher.
|
||||
*
|
||||
* @var \Symfony\Component\EventDispatcher\EventDispatcherInterface
|
||||
*/
|
||||
protected $eventDispatcher;
|
||||
|
||||
/**
|
||||
* @see \Drupal\ctools\Plugin\BlockVariantInterface::getRegionNames()
|
||||
*/
|
||||
abstract public function getRegionNames();
|
||||
|
||||
/**
|
||||
* @see \Drupal\ctools\Plugin\BlockVariantInterface::getBlock()
|
||||
*/
|
||||
public function getBlock($block_id) {
|
||||
return $this->getBlockCollection()->get($block_id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see \Drupal\ctools\Plugin\BlockVariantInterface::addBlock()
|
||||
*/
|
||||
public function addBlock(array $configuration) {
|
||||
$configuration['uuid'] = $this->uuidGenerator()->generate();
|
||||
$this->getBlockCollection()->addInstanceId($configuration['uuid'], $configuration);
|
||||
|
||||
$block = $this->getBlock($configuration['uuid']);
|
||||
// Allow modules to react to the change.
|
||||
$event = new BlockVariantEvent($block, $this);
|
||||
$this->eventDispatcher()->dispatch(BlockVariantEvents::ADD_BLOCK, $event);
|
||||
|
||||
return $configuration['uuid'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @see \Drupal\ctools\Plugin\BlockVariantInterface::removeBlock()
|
||||
*/
|
||||
public function removeBlock($block_id) {
|
||||
$block = $this->getBlock($block_id);
|
||||
$this->getBlockCollection()->removeInstanceId($block_id);
|
||||
|
||||
// Allow modules to react to the change.
|
||||
$event = new BlockVariantEvent($block, $this);
|
||||
$this->eventDispatcher()->dispatch(BlockVariantEvents::DELETE_BLOCK, $event);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see \Drupal\ctools\Plugin\BlockVariantInterface::updateBlock()
|
||||
*/
|
||||
public function updateBlock($block_id, array $configuration) {
|
||||
$block = $this->getBlock($block_id);
|
||||
$existing_configuration = $block->getConfiguration();
|
||||
$this->getBlockCollection()->setInstanceConfiguration($block_id, $configuration + $existing_configuration);
|
||||
|
||||
// Allow modules to react to the change.
|
||||
$event = new BlockVariantEvent($block, $this);
|
||||
$this->eventDispatcher()->dispatch(BlockVariantEvents::UPDATE_BLOCK, $event);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see \Drupal\ctools\Plugin\BlockVariantInterface::getRegionAssignment()
|
||||
*/
|
||||
public function getRegionAssignment($block_id) {
|
||||
$configuration = $this->getBlock($block_id)->getConfiguration();
|
||||
return isset($configuration['region']) ? $configuration['region'] : NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see \Drupal\ctools\Plugin\BlockVariantInterface::getRegionAssignments()
|
||||
*/
|
||||
public function getRegionAssignments() {
|
||||
// Build an array of the region names in the right order.
|
||||
$empty = array_fill_keys(array_keys($this->getRegionNames()), []);
|
||||
$full = $this->getBlockCollection()->getAllByRegion();
|
||||
// Merge it with the actual values to maintain the ordering.
|
||||
return array_intersect_key(array_merge($empty, $full), $empty);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see \Drupal\ctools\Plugin\BlockVariantInterface::getRegionName()
|
||||
*/
|
||||
public function getRegionName($region) {
|
||||
$regions = $this->getRegionNames();
|
||||
return isset($regions[$region]) ? $regions[$region] : '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the block plugin manager.
|
||||
*
|
||||
* @return \Drupal\Core\Block\BlockManager
|
||||
* The block plugin manager.
|
||||
*/
|
||||
protected function getBlockManager() {
|
||||
if (!$this->blockManager) {
|
||||
$this->blockManager = \Drupal::service('plugin.manager.block');
|
||||
}
|
||||
return $this->blockManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the block plugins used for this display variant.
|
||||
*
|
||||
* @return \Drupal\Core\Block\BlockPluginInterface[]|\Drupal\ctools\Plugin\BlockPluginCollection
|
||||
* An array or collection of configured block plugins.
|
||||
*/
|
||||
protected function getBlockCollection() {
|
||||
if (!$this->blockPluginCollection) {
|
||||
$this->blockPluginCollection = new BlockPluginCollection($this->getBlockManager(), $this->getBlockConfig());
|
||||
}
|
||||
return $this->blockPluginCollection;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the event dispatcher.
|
||||
*
|
||||
* @return \Symfony\Component\EventDispatcher\EventDispatcherInterface
|
||||
*/
|
||||
protected function eventDispatcher() {
|
||||
if (!$this->eventDispatcher) {
|
||||
$this->eventDispatcher = \Drupal::service('event_dispatcher');
|
||||
}
|
||||
return $this->eventDispatcher;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the UUID generator.
|
||||
*
|
||||
* @return \Drupal\Component\Uuid\UuidInterface
|
||||
*/
|
||||
abstract protected function uuidGenerator();
|
||||
|
||||
/**
|
||||
* Returns the configuration for stored blocks.
|
||||
*
|
||||
* @return array
|
||||
* An array of block configuration, keyed by the unique block ID.
|
||||
*/
|
||||
abstract protected function getBlockConfig();
|
||||
|
||||
}
|
|
@ -0,0 +1,165 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\ctools\Plugin\Condition;
|
||||
|
||||
use Drupal\Core\Condition\ConditionPluginBase;
|
||||
use Drupal\Core\Entity\EntityTypeBundleInfoInterface;
|
||||
use Drupal\Core\Entity\EntityTypeManagerInterface;
|
||||
use Drupal\Core\Entity\ContentEntityInterface;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
|
||||
use Drupal\ctools\ConstraintConditionInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
/**
|
||||
* Provides a 'Entity Bundle' condition.
|
||||
*
|
||||
* @Condition(
|
||||
* id = "entity_bundle",
|
||||
* deriver = "\Drupal\ctools\Plugin\Deriver\EntityBundle"
|
||||
* )
|
||||
*/
|
||||
class EntityBundle extends ConditionPluginBase implements ConstraintConditionInterface, ContainerFactoryPluginInterface {
|
||||
|
||||
/**
|
||||
* The entity type bundle info service.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityTypeBundleInfoInterface
|
||||
*/
|
||||
protected $entityTypeBundleInfo;
|
||||
|
||||
/**
|
||||
* @var \Drupal\Core\Entity\EntityTypeInterface|null
|
||||
*/
|
||||
protected $bundleOf;
|
||||
|
||||
/**
|
||||
* Creates a new EntityBundle instance.
|
||||
*
|
||||
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
|
||||
* The entity type manager.
|
||||
* @param \Drupal\Core\Entity\EntityTypeBundleInfoInterface $entity_type_bundle_info
|
||||
* The entity type bundle info service.
|
||||
* @param array $configuration
|
||||
* The plugin configuration, i.e. an array with configuration values keyed
|
||||
* by configuration option name. The special key 'context' may be used to
|
||||
* initialize the defined contexts by setting it to an array of context
|
||||
* values keyed by context names.
|
||||
* @param string $plugin_id
|
||||
* The plugin_id for the plugin instance.
|
||||
* @param mixed $plugin_definition
|
||||
* The plugin implementation definition.
|
||||
*/
|
||||
public function __construct(EntityTypeManagerInterface $entity_type_manager, EntityTypeBundleInfoInterface $entity_type_bundle_info, array $configuration, $plugin_id, $plugin_definition) {
|
||||
parent::__construct($configuration, $plugin_id, $plugin_definition);
|
||||
$this->entityTypeBundleInfo = $entity_type_bundle_info;
|
||||
$this->bundleOf = $entity_type_manager->getDefinition($this->getDerivativeId());
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
|
||||
return new static(
|
||||
$container->get('entity_type.manager'),
|
||||
$container->get('entity_type.bundle.info'),
|
||||
$configuration,
|
||||
$plugin_id,
|
||||
$plugin_definition
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
|
||||
$options = [];
|
||||
$bundles = $this->entityTypeBundleInfo->getBundleInfo($this->bundleOf->id());
|
||||
foreach ($bundles as $id => $info) {
|
||||
$options[$id] = $info['label'];
|
||||
}
|
||||
$form['bundles'] = [
|
||||
'#title' => $this->pluginDefinition['label'],
|
||||
'#type' => 'checkboxes',
|
||||
'#options' => $options,
|
||||
'#default_value' => $this->configuration['bundles'],
|
||||
];
|
||||
return parent::buildConfigurationForm($form, $form_state);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
|
||||
$this->configuration['bundles'] = array_filter($form_state->getValue('bundles'));
|
||||
parent::submitConfigurationForm($form, $form_state);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function evaluate() {
|
||||
if (empty($this->configuration['bundles']) && !$this->isNegated()) {
|
||||
return TRUE;
|
||||
}
|
||||
/** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
|
||||
$entity = $this->getContextValue($this->bundleOf->id());
|
||||
|
||||
if (!$entity instanceof ContentEntityInterface) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return !empty($this->configuration['bundles'][$entity->bundle()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function summary() {
|
||||
if (count($this->configuration['bundles']) > 1) {
|
||||
$bundles = $this->configuration['bundles'];
|
||||
$last = array_pop($bundles);
|
||||
$bundles = implode(', ', $bundles);
|
||||
return $this->t('@bundle_type is @bundles or @last', ['@bundle_type' => $this->bundleOf->getBundleLabel(), '@bundles' => $bundles, '@last' => $last]);
|
||||
}
|
||||
$bundle = reset($this->configuration['bundles']);
|
||||
return $this->t('@bundle_type is @bundle', ['@bundle_type' => $this->bundleOf->getBundleLabel(), '@bundle' => $bundle]);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function defaultConfiguration() {
|
||||
return ['bundles' => []] + parent::defaultConfiguration();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @param \Drupal\Core\Plugin\Context\ContextInterface[] $contexts
|
||||
*/
|
||||
public function applyConstraints(array $contexts = []) {
|
||||
// Nullify any bundle constraints on contexts we care about.
|
||||
$this->removeConstraints($contexts);
|
||||
$bundle = array_values($this->configuration['bundles']);
|
||||
// There's only one expected context for this plugint type.
|
||||
foreach ($this->getContextMapping() as $definition_id => $context_id) {
|
||||
$contexts[$context_id]->getContextDefinition()->addConstraint('Bundle', ['value' => $bundle]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @param \Drupal\Core\Plugin\Context\ContextInterface[] $contexts
|
||||
*/
|
||||
public function removeConstraints(array $contexts = []) {
|
||||
// Reset the bundle constraint for any context we've mapped.
|
||||
foreach ($this->getContextMapping() as $definition_id => $context_id) {
|
||||
$constraints = $contexts[$context_id]->getContextDefinition()->getConstraints();
|
||||
unset($constraints['Bundle']);
|
||||
$contexts[$context_id]->getContextDefinition()->setConstraints($constraints);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\ctools\Plugin\Condition;
|
||||
|
||||
use Drupal\node\Plugin\Condition\NodeType as CoreNodeType;
|
||||
use Drupal\ctools\ConstraintConditionInterface;
|
||||
|
||||
|
||||
class NodeType extends CoreNodeType implements ConstraintConditionInterface {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @param \Drupal\Core\Plugin\Context\ContextInterface[] $contexts
|
||||
*/
|
||||
public function applyConstraints(array $contexts = []) {
|
||||
// Nullify any bundle constraints on contexts we care about.
|
||||
$this->removeConstraints($contexts);
|
||||
// If a single bundle is configured, we can set a proper constraint.
|
||||
if (count($this->configuration['bundles']) == 1) {
|
||||
$bundle = array_values($this->configuration['bundles']);
|
||||
foreach ($this->getContextMapping() as $definition_id => $context_id) {
|
||||
$contexts[$context_id]->getContextDefinition()->addConstraint('Bundle', ['value' => $bundle[0]]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @param \Drupal\Core\Plugin\Context\ContextInterface[] $contexts
|
||||
*/
|
||||
public function removeConstraints(array $contexts = []) {
|
||||
// Reset the bundle constraint for any context we've mapped.
|
||||
foreach ($this->getContextMapping() as $definition_id => $context_id) {
|
||||
$constraints = $contexts[$context_id]->getContextDefinition()->getConstraints();
|
||||
unset($constraints['Bundle']);
|
||||
$contexts[$context_id]->getContextDefinition()->setConstraints($constraints);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\ctools\Plugin\Deriver;
|
||||
|
||||
use Drupal\Core\Plugin\Context\EntityContextDefinition;
|
||||
|
||||
/**
|
||||
* Deriver that creates a condition for each entity type with bundles.
|
||||
*/
|
||||
class EntityBundle extends EntityDeriverBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getDerivativeDefinitions($base_plugin_definition) {
|
||||
foreach ($this->entityTypeManager->getDefinitions() as $entity_type_id => $entity_type) {
|
||||
if ($entity_type->hasKey('bundle')) {
|
||||
$this->derivatives[$entity_type_id] = $base_plugin_definition;
|
||||
$this->derivatives[$entity_type_id]['label'] = $this->getEntityBundleLabel($entity_type);
|
||||
$this->derivatives[$entity_type_id]['context_definitions'] = [
|
||||
"$entity_type_id" => new EntityContextDefinition('entity:' . $entity_type_id),
|
||||
];
|
||||
}
|
||||
}
|
||||
return $this->derivatives;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides the bundle label with a fallback when not defined.
|
||||
*
|
||||
* @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
|
||||
* The entity type we are looking the bundle label for.
|
||||
*
|
||||
* @return \Drupal\Core\StringTranslation\TranslatableMarkup
|
||||
* The entity bundle label or a fallback label.
|
||||
*/
|
||||
protected function getEntityBundleLabel($entity_type) {
|
||||
|
||||
if ($label = $entity_type->getBundleLabel()) {
|
||||
return $this->t('@label', ['@label' => $label]);
|
||||
}
|
||||
|
||||
$fallback = $entity_type->getLabel();
|
||||
if ($bundle_entity_type = $entity_type->getBundleEntityType()) {
|
||||
// This is a better fallback.
|
||||
$fallback = $this->entityTypeManager->getDefinition($bundle_entity_type)->getLabel();
|
||||
}
|
||||
|
||||
return $this->t('@label bundle', ['@label' => $fallback]);
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,73 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\ctools\Plugin\Deriver;
|
||||
|
||||
use Drupal\Component\Plugin\Derivative\DeriverBase;
|
||||
use Drupal\Core\Entity\EntityTypeManagerInterface;
|
||||
use Drupal\Core\Entity\EntityFieldManagerInterface;
|
||||
use Drupal\Core\Entity\EntityTypeRepositoryInterface;
|
||||
use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface;
|
||||
use Drupal\Core\StringTranslation\StringTranslationTrait;
|
||||
use Drupal\Core\StringTranslation\TranslationInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
/**
|
||||
* An abstract base class that sets up the needs of entity specific derivers.
|
||||
*/
|
||||
abstract class EntityDeriverBase extends DeriverBase implements ContainerDeriverInterface {
|
||||
|
||||
use StringTranslationTrait;
|
||||
|
||||
/**
|
||||
* The entity type manager.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
|
||||
*/
|
||||
protected $entityTypeManager;
|
||||
|
||||
/**
|
||||
* The entity field manager.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityFieldManagerInterface
|
||||
*/
|
||||
protected $entityFieldManager;
|
||||
|
||||
/**
|
||||
* The entity type repository.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityTypeRepositoryInterface
|
||||
*/
|
||||
protected $entityTypeRepository;
|
||||
|
||||
/**
|
||||
* Constructs new EntityViewDeriver.
|
||||
*
|
||||
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
|
||||
* The entity type manager.
|
||||
* @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation
|
||||
* The string translation service.
|
||||
* @param \Drupal\Core\Entity\EntityFieldManagerInterface $entity_field_manager
|
||||
* The entity field manager.
|
||||
* @param \Drupal\Core\Entity\EntityTypeRepositoryInterface $entity_type_repository
|
||||
* The entity type repository.
|
||||
*/
|
||||
public function __construct(EntityTypeManagerInterface $entity_type_manager, TranslationInterface $string_translation, EntityFieldManagerInterface $entity_field_manager, EntityTypeRepositoryInterface $entity_type_repository) {
|
||||
$this->entityTypeManager = $entity_type_manager;
|
||||
$this->stringTranslation = $string_translation;
|
||||
$this->entityFieldManager = $entity_field_manager;
|
||||
$this->entityTypeRepository = $entity_type_repository;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function create(ContainerInterface $container, $base_plugin_id) {
|
||||
return new static(
|
||||
$container->get('entity_type.manager'),
|
||||
$container->get('string_translation'),
|
||||
$container->get('entity_field.manager'),
|
||||
$container->get('entity_type.repository')
|
||||
);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\ctools\Plugin\Deriver;
|
||||
|
||||
use Drupal\Core\Plugin\Context\EntityContextDefinition;
|
||||
|
||||
/**
|
||||
* Provides entity view block definitions for each entity type.
|
||||
*/
|
||||
class EntityViewDeriver extends EntityDeriverBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getDerivativeDefinitions($base_plugin_definition) {
|
||||
foreach ($this->entityTypeManager->getDefinitions() as $entity_type_id => $entity_type) {
|
||||
if ($entity_type->hasViewBuilderClass()) {
|
||||
$this->derivatives[$entity_type_id] = $base_plugin_definition;
|
||||
$this->derivatives[$entity_type_id]['admin_label'] = $this->t('Entity view (@label)', ['@label' => $entity_type->getLabel()]);
|
||||
$this->derivatives[$entity_type_id]['context_definitions'] = [
|
||||
'entity' => new EntityContextDefinition('entity:' . $entity_type_id),
|
||||
];
|
||||
}
|
||||
}
|
||||
return $this->derivatives;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\ctools\Plugin\Deriver;
|
||||
|
||||
use Drupal\Core\TypedData\DataDefinitionInterface;
|
||||
|
||||
|
||||
class TypedDataEntityRelationshipDeriver extends TypedDataRelationshipDeriver {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected $label = '@property Entity from @base';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function generateDerivativeDefinition($base_plugin_definition, $data_type_id, $data_type_definition, DataDefinitionInterface $base_definition, $property_name, DataDefinitionInterface $property_definition) {
|
||||
if (method_exists($property_definition, 'getType') && $property_definition->getType() == 'entity_reference') {
|
||||
parent::generateDerivativeDefinition($base_plugin_definition, $data_type_id, $data_type_definition, $base_definition, $property_name, $property_definition);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\ctools\Plugin\Deriver;
|
||||
|
||||
use Drupal\Core\TypedData\DataDefinitionInterface;
|
||||
|
||||
|
||||
class TypedDataLanguageRelationshipDeriver extends TypedDataRelationshipDeriver {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @todo this results in awful labels like "Language Language from Content"
|
||||
* Fix it.
|
||||
*/
|
||||
protected $label = '@property Language from @base';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function generateDerivativeDefinition($base_plugin_definition, $data_type_id, $data_type_definition, DataDefinitionInterface $base_definition, $property_name, DataDefinitionInterface $property_definition) {
|
||||
if (method_exists($property_definition, 'getType') && $property_definition->getType() == 'language') {
|
||||
parent::generateDerivativeDefinition($base_plugin_definition, $data_type_id, $data_type_definition, $base_definition, $property_name, $property_definition);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getDerivativeDefinitions($base_plugin_definition) {
|
||||
parent::getDerivativeDefinitions($base_plugin_definition);
|
||||
// The data types will all be set to string since language extends string
|
||||
// and the parent class finds the related primitive.
|
||||
foreach ($this->derivatives as $plugin_id => $derivative) {
|
||||
$this->derivatives[$plugin_id]['data_type'] = 'language';
|
||||
}
|
||||
return $this->derivatives;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,112 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\ctools\Plugin\Deriver;
|
||||
|
||||
use Drupal\Component\Plugin\Derivative\DeriverBase;
|
||||
use Drupal\Core\Field\BaseFieldDefinition;
|
||||
use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface;
|
||||
use Drupal\Core\StringTranslation\StringTranslationTrait;
|
||||
use Drupal\Core\StringTranslation\TranslationInterface;
|
||||
use Drupal\Core\TypedData\ComplexDataInterface;
|
||||
use Drupal\Core\TypedData\DataDefinitionInterface;
|
||||
use Drupal\Core\TypedData\DataReferenceDefinitionInterface;
|
||||
use Drupal\Core\TypedData\ListDataDefinitionInterface;
|
||||
use Drupal\Core\TypedData\TypedDataManagerInterface;
|
||||
use Drupal\field\Entity\FieldConfig;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
|
||||
abstract class TypedDataPropertyDeriverBase extends DeriverBase implements ContainerDeriverInterface {
|
||||
|
||||
use StringTranslationTrait;
|
||||
|
||||
/**
|
||||
* @var \Drupal\Core\TypedData\TypedDataManagerInterface
|
||||
*/
|
||||
protected $typedDataManager;
|
||||
|
||||
/**
|
||||
* The label string for use with derivative labels.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $label = '@property from @base';
|
||||
|
||||
/**
|
||||
* TypedDataPropertyDeriverBase constructor.
|
||||
*
|
||||
* @param \Drupal\Core\TypedData\TypedDataManagerInterface $typed_data_manager
|
||||
* The typed data manager.
|
||||
* @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation
|
||||
* The string translation service.
|
||||
*/
|
||||
public function __construct(TypedDataManagerInterface $typed_data_manager, TranslationInterface $string_translation) {
|
||||
$this->typedDataManager = $typed_data_manager;
|
||||
$this->stringTranslation = $string_translation;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function create(ContainerInterface $container, $base_plugin_id) {
|
||||
return new static(
|
||||
$container->get('typed_data_manager'),
|
||||
$container->get('string_translation')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getDerivativeDefinitions($base_plugin_definition) {
|
||||
foreach ($this->typedDataManager->getDefinitions() as $data_type_id => $data_type_definition) {
|
||||
if (is_subclass_of($data_type_definition['class'], ComplexDataInterface::class, TRUE)) {
|
||||
/** @var \Drupal\Core\TypedData\ComplexDataDefinitionInterface $base_definition */
|
||||
$base_definition = $this->typedDataManager->createDataDefinition($data_type_id);
|
||||
foreach ($base_definition->getPropertyDefinitions() as $property_name => $property_definition) {
|
||||
if ($property_definition instanceof BaseFieldDefinition || $property_definition instanceof FieldConfig) {
|
||||
$this->generateDerivativeDefinition($base_plugin_definition, $data_type_id, $data_type_definition, $base_definition, $property_name, $property_definition);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return $this->derivatives;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $property_definition
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
protected function getDataType($property_definition) {
|
||||
if ($property_definition instanceof DataReferenceDefinitionInterface) {
|
||||
return $property_definition->getTargetDefinition()->getDataType();
|
||||
}
|
||||
if ($property_definition instanceof ListDataDefinitionInterface) {
|
||||
return $property_definition->getItemDefinition()->getDataType();
|
||||
}
|
||||
return $property_definition->getDataType();
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates and maintains a derivative definition.
|
||||
*
|
||||
* This method should directly manipulate $this->derivatives and not return
|
||||
* values. This allows implementations control over the derivative names.
|
||||
*
|
||||
* @param $base_plugin_definition
|
||||
* The base plugin definition.
|
||||
* @param string $data_type_id
|
||||
* The plugin id of the data type.
|
||||
* @param mixed $data_type_definition
|
||||
* The plugin definition of the data type.
|
||||
* @param \Drupal\Core\TypedData\DataDefinitionInterface $base_definition
|
||||
* The data type definition of a complex data object.
|
||||
* @param string $property_name
|
||||
* The name of the property.
|
||||
* @param \Drupal\Core\TypedData\DataDefinitionInterface $property_definition
|
||||
* The property definition.
|
||||
*/
|
||||
abstract protected function generateDerivativeDefinition($base_plugin_definition, $data_type_id, $data_type_definition, DataDefinitionInterface $base_definition, $property_name, DataDefinitionInterface $property_definition);
|
||||
|
||||
}
|
|
@ -0,0 +1,81 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\ctools\Plugin\Deriver;
|
||||
|
||||
use Drupal\Core\Plugin\Context\ContextDefinition;
|
||||
use Drupal\Core\Plugin\Context\EntityContextDefinition;
|
||||
use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface;
|
||||
use Drupal\Core\TypedData\DataDefinitionInterface;
|
||||
use Drupal\field\FieldConfigInterface;
|
||||
|
||||
|
||||
class TypedDataRelationshipDeriver extends TypedDataPropertyDeriverBase implements ContainerDeriverInterface {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function generateDerivativeDefinition($base_plugin_definition, $data_type_id, $data_type_definition, DataDefinitionInterface $base_definition, $property_name, DataDefinitionInterface $property_definition) {
|
||||
$bundle_info = $base_definition->getConstraint('Bundle');
|
||||
// Identify base definitions that appear on bundle-able entities.
|
||||
if ($bundle_info && array_filter($bundle_info) && $base_definition->getConstraint('EntityType')) {
|
||||
$base_data_type = 'entity:' . $base_definition->getConstraint('EntityType');
|
||||
}
|
||||
// Otherwise, just use the raw data type identifier.
|
||||
else {
|
||||
$base_data_type = $data_type_id;
|
||||
}
|
||||
// If we've not processed this thing before.
|
||||
if (!isset($this->derivatives[$base_data_type . ':' . $property_name])) {
|
||||
$derivative = $base_plugin_definition;
|
||||
|
||||
$derivative['label'] = $this->t($this->label, [
|
||||
'@property' => $property_definition->getLabel(),
|
||||
'@base' => $data_type_definition['label'],
|
||||
]);
|
||||
$derivative['data_type'] = $property_definition->getFieldStorageDefinition()->getPropertyDefinition($property_definition->getFieldStorageDefinition()->getMainPropertyName())->getDataType();
|
||||
$derivative['property_name'] = $property_name;
|
||||
if (strpos($base_data_type, 'entity:') === 0) {
|
||||
$context_definition = new EntityContextDefinition($base_data_type, $this->typedDataManager->createDataDefinition($base_data_type));
|
||||
}
|
||||
else {
|
||||
$context_definition = new ContextDefinition($base_data_type, $this->typedDataManager->createDataDefinition($base_data_type));
|
||||
}
|
||||
// Add the constraints of the base definition to the context definition.
|
||||
if ($base_definition->getConstraint('Bundle')) {
|
||||
$context_definition->addConstraint('Bundle', $base_definition->getConstraint('Bundle'));
|
||||
}
|
||||
$derivative['context_definitions'] = [
|
||||
'base' => $context_definition,
|
||||
];
|
||||
$derivative['property_name'] = $property_name;
|
||||
|
||||
$this->derivatives[$base_data_type . ':' . $property_name] = $derivative;
|
||||
}
|
||||
// Individual fields can be on multiple bundles.
|
||||
elseif ($property_definition instanceof FieldConfigInterface) {
|
||||
// We should only end up in here on entity bundles.
|
||||
$derivative = $this->derivatives[$base_data_type . ':' . $property_name];
|
||||
// Update label.
|
||||
/** @var \Drupal\Core\StringTranslation\TranslatableMarkup $label */
|
||||
$label = $derivative['label'];
|
||||
list(,, $argument_name) = explode(':', $data_type_id);
|
||||
$arguments = $label->getArguments();
|
||||
$arguments['@' . $argument_name] = $data_type_definition['label'];
|
||||
$string_args = $arguments;
|
||||
array_shift($string_args);
|
||||
$last = array_slice($string_args, -1);
|
||||
// The slice doesn't remove, so do that now.
|
||||
array_pop($string_args);
|
||||
$string = count($string_args) >= 2 ? '@property from ' . implode(', ', array_keys($string_args)) . ' and ' . array_keys($last)[0] : '@property from @base and ' . array_keys($last)[0];
|
||||
$this->derivatives[$base_data_type . ':' . $property_name]['label'] = $this->t($string, $arguments);
|
||||
if ($base_definition->getConstraint('Bundle')) {
|
||||
// Add bundle constraints.
|
||||
$context_definition = $derivative['context_definitions']['base'];
|
||||
$bundles = $context_definition->getConstraint('Bundle') ?: [];
|
||||
$bundles = array_merge($bundles, $base_definition->getConstraint('Bundle'));
|
||||
$context_definition->addConstraint('Bundle', $bundles);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,224 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\ctools\Plugin\DisplayVariant;
|
||||
|
||||
use Drupal\Component\Uuid\UuidInterface;
|
||||
use Drupal\Core\Block\BlockManagerInterface;
|
||||
use Drupal\Core\Condition\ConditionManager;
|
||||
use Drupal\Core\Display\VariantBase;
|
||||
use Drupal\Core\Display\ContextAwareVariantInterface;
|
||||
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
|
||||
use Drupal\Core\Plugin\Context\ContextHandlerInterface;
|
||||
use Drupal\Core\Session\AccountInterface;
|
||||
use Drupal\Core\Utility\Token;
|
||||
use Drupal\ctools\Form\AjaxFormTrait;
|
||||
use Drupal\ctools\Plugin\BlockVariantInterface;
|
||||
use Drupal\ctools\Plugin\BlockVariantTrait;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
/**
|
||||
* Provides a base class for a display variant that simply contains blocks.
|
||||
*/
|
||||
abstract class BlockDisplayVariant extends VariantBase implements ContextAwareVariantInterface, ContainerFactoryPluginInterface, BlockVariantInterface {
|
||||
|
||||
use AjaxFormTrait;
|
||||
use BlockVariantTrait;
|
||||
|
||||
/**
|
||||
* The context handler.
|
||||
*
|
||||
* @var \Drupal\Core\Plugin\Context\ContextHandlerInterface
|
||||
*/
|
||||
protected $contextHandler;
|
||||
|
||||
/**
|
||||
* The UUID generator.
|
||||
*
|
||||
* @var \Drupal\Component\Uuid\UuidInterface
|
||||
*/
|
||||
protected $uuidGenerator;
|
||||
|
||||
/**
|
||||
* The current user.
|
||||
*
|
||||
* @var \Drupal\Core\Session\AccountInterface
|
||||
*/
|
||||
protected $account;
|
||||
|
||||
/**
|
||||
* The token service.
|
||||
*
|
||||
* @var \Drupal\Core\Utility\Token
|
||||
*/
|
||||
protected $token;
|
||||
|
||||
/**
|
||||
* An array of collected contexts.
|
||||
*
|
||||
* This is only used on runtime, and is not stored.
|
||||
*
|
||||
* @var \Drupal\Component\Plugin\Context\ContextInterface[]
|
||||
*/
|
||||
protected $contexts = [];
|
||||
|
||||
/**
|
||||
* Constructs a new BlockDisplayVariant.
|
||||
*
|
||||
* @param array $configuration
|
||||
* A configuration array containing information about the plugin instance.
|
||||
* @param string $plugin_id
|
||||
* The plugin ID for the plugin instance.
|
||||
* @param mixed $plugin_definition
|
||||
* The plugin implementation definition.
|
||||
* @param \Drupal\Core\Plugin\Context\ContextHandlerInterface $context_handler
|
||||
* The context handler.
|
||||
* @param \Drupal\Core\Session\AccountInterface $account
|
||||
* The current user.
|
||||
* @param \Drupal\Component\Uuid\UuidInterface $uuid_generator
|
||||
* The UUID generator.
|
||||
* @param \Drupal\Core\Utility\Token $token
|
||||
* The token service.
|
||||
* @param \Drupal\Core\Block\BlockManagerInterface $block_manager
|
||||
* The block manager.
|
||||
* @param \Drupal\Core\Condition\ConditionManager $condition_manager
|
||||
* The condition manager.
|
||||
*/
|
||||
public function __construct(array $configuration, $plugin_id, $plugin_definition, ContextHandlerInterface $context_handler, AccountInterface $account, UuidInterface $uuid_generator, Token $token, BlockManagerInterface $block_manager, ConditionManager $condition_manager) {
|
||||
// Inject dependencies as early as possible, so they can be used in
|
||||
// configuration.
|
||||
$this->contextHandler = $context_handler;
|
||||
$this->account = $account;
|
||||
$this->uuidGenerator = $uuid_generator;
|
||||
$this->token = $token;
|
||||
$this->blockManager = $block_manager;
|
||||
$this->conditionManager = $condition_manager;
|
||||
|
||||
parent::__construct($configuration, $plugin_id, $plugin_definition);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
|
||||
return new static(
|
||||
$configuration,
|
||||
$plugin_id,
|
||||
$plugin_definition,
|
||||
$container->get('context.handler'),
|
||||
$container->get('current_user'),
|
||||
$container->get('uuid'),
|
||||
$container->get('token'),
|
||||
$container->get('plugin.manager.block'),
|
||||
$container->get('plugin.manager.condition')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function defaultConfiguration() {
|
||||
return parent::defaultConfiguration() + [
|
||||
'blocks' => [],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function calculateDependencies() {
|
||||
foreach ($this->getBlockCollection() as $instance) {
|
||||
$this->calculatePluginDependencies($instance);
|
||||
}
|
||||
return $this->dependencies;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getConfiguration() {
|
||||
return [
|
||||
'blocks' => $this->getBlockCollection()->getConfiguration(),
|
||||
] + parent::getConfiguration();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setConfiguration(array $configuration) {
|
||||
// Preserve the uuid.
|
||||
if ($this->configuration && !empty($this->configuration['uuid'])) {
|
||||
$configuration['uuid'] = $this->configuration['uuid'];
|
||||
}
|
||||
parent::setConfiguration($configuration);
|
||||
$this->getBlockCollection()->setConfiguration($this->configuration['blocks']);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the contexts.
|
||||
*
|
||||
* @return \Drupal\Component\Plugin\Context\ContextInterface[]
|
||||
* An array of set contexts, keyed by context name.
|
||||
*/
|
||||
public function getContexts() {
|
||||
return $this->contexts;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the contexts.
|
||||
*
|
||||
* @param \Drupal\Component\Plugin\Context\ContextInterface[] $contexts
|
||||
* An array of contexts, keyed by context name.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setContexts(array $contexts) {
|
||||
$this->contexts = $contexts;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function contextHandler() {
|
||||
return $this->contextHandler;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getBlockConfig() {
|
||||
return $this->configuration['blocks'];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function uuidGenerator() {
|
||||
return $this->uuidGenerator;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function __sleep() {
|
||||
$vars = parent::__sleep();
|
||||
|
||||
// Gathered contexts objects should not be serialized.
|
||||
if (($key = array_search('contexts', $vars)) !== FALSE) {
|
||||
unset($vars[$key]);
|
||||
}
|
||||
|
||||
// The block plugin collection should also not be serialized, ensure that
|
||||
// configuration is synced back.
|
||||
if (($key = array_search('blockPluginCollection', $vars)) !== FALSE) {
|
||||
if ($this->blockPluginCollection) {
|
||||
$this->configuration['blocks'] = $this->blockPluginCollection->getConfiguration();
|
||||
}
|
||||
unset($vars[$key]);
|
||||
}
|
||||
|
||||
return $vars;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\ctools\Plugin;
|
||||
|
||||
/**
|
||||
* Provides an interface for configuring a plugin via wizard steps.
|
||||
*/
|
||||
interface PluginWizardInterface {
|
||||
|
||||
/**
|
||||
* Retrieve a list of FormInterface classes by their step key in the wizard.
|
||||
*
|
||||
* @param mixed $cached_values
|
||||
* The cached values used in the wizard. The plugin we're editing will
|
||||
* always be assigned to the 'plugin' key.
|
||||
*
|
||||
* @return array
|
||||
* An associative array keyed on the step name with an array value with the
|
||||
* following keys:
|
||||
* - title (string): Human-readable title of the step.
|
||||
* - form (string): Fully-qualified class name of the form for this step.
|
||||
*/
|
||||
public function getWizardOperations($cached_values);
|
||||
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\ctools\Plugin\Relationship;
|
||||
|
||||
use Drupal\Core\Plugin\Context\Context;
|
||||
use Drupal\Core\Plugin\Context\EntityContextDefinition;
|
||||
|
||||
/**
|
||||
* @Relationship(
|
||||
* id = "typed_data_entity_relationship",
|
||||
* deriver = "\Drupal\ctools\Plugin\Deriver\TypedDataEntityRelationshipDeriver"
|
||||
* )
|
||||
*/
|
||||
class TypedDataEntityRelationship extends TypedDataRelationship {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getRelationship() {
|
||||
$plugin_definition = $this->getPluginDefinition();
|
||||
|
||||
$entity_type = $this->getData($this->getContext('base'))->getDataDefinition()->getSetting('target_type');
|
||||
$context_definition = new EntityContextDefinition("entity:$entity_type", $plugin_definition['label']);
|
||||
$context_value = NULL;
|
||||
|
||||
// If the 'base' context has a value, then get the property value to put on
|
||||
// the context (otherwise, mapping hasn't occurred yet and we just want to
|
||||
// return the context with the right definition and no value).
|
||||
if ($this->getContext('base')->hasContextValue()) {
|
||||
$context_value = $this->getData($this->getContext('base'))->entity;
|
||||
}
|
||||
|
||||
$context_definition->setDefaultValue($context_value);
|
||||
return new Context($context_definition, $context_value);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\ctools\Plugin\Relationship;
|
||||
|
||||
use Drupal\Core\Plugin\Context\Context;
|
||||
use Drupal\Core\Plugin\Context\ContextDefinition;
|
||||
|
||||
/**
|
||||
* @Relationship(
|
||||
* id = "typed_data_language_relationship",
|
||||
* deriver = "\Drupal\ctools\Plugin\Deriver\TypedDataLanguageRelationshipDeriver"
|
||||
* )
|
||||
*/
|
||||
class TypedDataLanguageRelationship extends TypedDataRelationship {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getRelationship() {
|
||||
$plugin_definition = $this->getPluginDefinition();
|
||||
|
||||
$context_definition = new ContextDefinition("language", $plugin_definition['label']);
|
||||
$context_value = NULL;
|
||||
|
||||
// If the 'base' context has a value, then get the property value to put on
|
||||
// the context (otherwise, mapping hasn't occurred yet and we just want to
|
||||
// return the context with the right definition and no value).
|
||||
if ($this->getContext('base')->hasContextValue()) {
|
||||
$context_value = $this->getData($this->getContext('base'))->language;
|
||||
}
|
||||
|
||||
$context_definition->setDefaultValue($context_value);
|
||||
return new Context($context_definition, $context_value);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,84 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\ctools\Plugin\Relationship;
|
||||
|
||||
use Drupal\Core\Field\FieldItemInterface;
|
||||
use Drupal\Core\Plugin\Context\Context;
|
||||
use Drupal\Core\Plugin\Context\ContextDefinition;
|
||||
use Drupal\Core\Plugin\Context\ContextInterface;
|
||||
use Drupal\Core\Plugin\Context\EntityContextDefinition;
|
||||
use Drupal\Core\TypedData\DataReferenceInterface;
|
||||
use Drupal\Core\TypedData\ListInterface;
|
||||
use Drupal\ctools\Plugin\RelationshipBase;
|
||||
|
||||
/**
|
||||
* @Relationship(
|
||||
* id = "typed_data_relationship",
|
||||
* deriver = "\Drupal\ctools\Plugin\Deriver\TypedDataRelationshipDeriver"
|
||||
* )
|
||||
*/
|
||||
class TypedDataRelationship extends RelationshipBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getRelationship() {
|
||||
$plugin_definition = $this->getPluginDefinition();
|
||||
|
||||
$data_type = $plugin_definition['data_type'];
|
||||
if (strpos($data_type, 'entity:') === 0) {
|
||||
$context_definition = new EntityContextDefinition($data_type, $plugin_definition['label']);
|
||||
}
|
||||
else {
|
||||
$context_definition = new ContextDefinition($data_type, $plugin_definition['label']);
|
||||
}
|
||||
$context_value = NULL;
|
||||
|
||||
// If the 'base' context has a value, then get the property value to put on
|
||||
// the context (otherwise, mapping hasn't occurred yet and we just want to
|
||||
// return the context with the right definition and no value).
|
||||
if ($this->getContext('base')->hasContextValue()) {
|
||||
$data = $this->getData($this->getContext('base'));
|
||||
$property = $this->getMainPropertyName($data);
|
||||
$context_value = $data->get($property)->getValue();
|
||||
}
|
||||
|
||||
$context_definition->setDefaultValue($context_value);
|
||||
return new Context($context_definition, $context_value);
|
||||
}
|
||||
|
||||
|
||||
public function getName() {
|
||||
return $this->getPluginDefinition()['property_name'];
|
||||
}
|
||||
|
||||
|
||||
protected function getData(ContextInterface $context) {
|
||||
/** @var \Drupal\Core\TypedData\ComplexDataInterface $base */
|
||||
$base = $context->getContextValue();
|
||||
$name = $this->getPluginDefinition()['property_name'];
|
||||
$data = $base->get($name);
|
||||
// @todo add configuration to get N instead of first.
|
||||
if ($data instanceof ListInterface) {
|
||||
$data = $data->first();
|
||||
}
|
||||
if ($data instanceof DataReferenceInterface) {
|
||||
$data = $data->getTarget();
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
protected function getMainPropertyName(FieldItemInterface $data) {
|
||||
return $data->getFieldDefinition()->getFieldStorageDefinition()->getMainPropertyName();
|
||||
}
|
||||
|
||||
|
||||
public function getRelationshipValue() {
|
||||
$property = $this->getMainPropertyName();
|
||||
/** @var \Drupal\Core\TypedData\ComplexDataInterface $data */
|
||||
$data = $this->getRelationship()->getContextData();
|
||||
$data->get($property)->getValue();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\ctools\Plugin;
|
||||
|
||||
use Drupal\Core\Plugin\ContextAwarePluginBase;
|
||||
|
||||
/**
|
||||
* Base class for Relationship plugins.
|
||||
*/
|
||||
abstract class RelationshipBase extends ContextAwarePluginBase implements RelationshipInterface {}
|
|
@ -0,0 +1,27 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\ctools\Plugin;
|
||||
|
||||
use Drupal\Component\Plugin\DerivativeInspectionInterface;
|
||||
use Drupal\Core\Plugin\ContextAwarePluginInterface;
|
||||
|
||||
/**
|
||||
* Defines an interface for Relationship plugins.
|
||||
*/
|
||||
interface RelationshipInterface extends ContextAwarePluginInterface, DerivativeInspectionInterface {
|
||||
|
||||
/**
|
||||
* Generates a context based on this plugin's configuration.
|
||||
*
|
||||
* @return \Drupal\Core\Plugin\Context\ContextInterface
|
||||
*/
|
||||
public function getRelationship();
|
||||
|
||||
/**
|
||||
* The name of the property used to get this relationship.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName();
|
||||
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\ctools\Plugin;
|
||||
|
||||
use Drupal\Core\Plugin\Context\ContextAwarePluginManagerTrait;
|
||||
use Drupal\Core\Plugin\DefaultPluginManager;
|
||||
use Drupal\Core\Cache\CacheBackendInterface;
|
||||
use Drupal\Core\Extension\ModuleHandlerInterface;
|
||||
|
||||
/**
|
||||
* Provides the Relationship plugin manager.
|
||||
*/
|
||||
class RelationshipManager extends DefaultPluginManager implements RelationshipManagerInterface {
|
||||
|
||||
use ContextAwarePluginManagerTrait;
|
||||
|
||||
/**
|
||||
* Constructor for RelationshipManager objects.
|
||||
*
|
||||
* @param \Traversable $namespaces
|
||||
* An object that implements \Traversable which contains the root paths
|
||||
* keyed by the corresponding namespace to look for plugin implementations.
|
||||
* @param \Drupal\Core\Cache\CacheBackendInterface $cache_backend
|
||||
* Cache backend instance to use.
|
||||
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
|
||||
* The module handler to invoke the alter hook with.
|
||||
*/
|
||||
public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) {
|
||||
parent::__construct('Plugin/Relationship', $namespaces, $module_handler, 'Drupal\ctools\Plugin\RelationshipInterface', 'Drupal\ctools\Annotation\Relationship');
|
||||
|
||||
$this->alterInfo('ctools_relationship_info');
|
||||
$this->setCacheBackend($cache_backend, 'ctools_relationship_plugins');
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\ctools\Plugin;
|
||||
|
||||
use Drupal\Component\Plugin\Discovery\CachedDiscoveryInterface;
|
||||
use Drupal\Core\Plugin\Context\ContextAwarePluginManagerInterface;
|
||||
|
||||
/**
|
||||
* Provides the Relationship plugin manager.
|
||||
*/
|
||||
interface RelationshipManagerInterface extends ContextAwarePluginManagerInterface, CachedDiscoveryInterface {}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue