Move all files to 2017/
This commit is contained in:
parent
ac7370f67f
commit
2875863330
15717 changed files with 0 additions and 0 deletions
42
2017/web/modules/README.txt
Normal file
42
2017/web/modules/README.txt
Normal file
|
@ -0,0 +1,42 @@
|
|||
Modules extend your site functionality beyond Drupal core.
|
||||
|
||||
WHAT TO PLACE IN THIS DIRECTORY?
|
||||
--------------------------------
|
||||
|
||||
Placing downloaded and custom modules in this directory separates downloaded and
|
||||
custom modules from Drupal core's modules. This allows Drupal core to be updated
|
||||
without overwriting these files.
|
||||
|
||||
DOWNLOAD ADDITIONAL MODULES
|
||||
---------------------------
|
||||
|
||||
Contributed modules from the Drupal community may be downloaded at
|
||||
https://www.drupal.org/project/project_module.
|
||||
|
||||
ORGANIZING MODULES IN THIS DIRECTORY
|
||||
------------------------------------
|
||||
|
||||
You may create subdirectories in this directory, to organize your added modules,
|
||||
without breaking the site. Some common subdirectories include "contrib" for
|
||||
contributed modules, and "custom" for custom modules. Note that if you move a
|
||||
module to a subdirectory after it has been enabled, you may need to clear the
|
||||
Drupal cache so it can be found.
|
||||
|
||||
There are number of directories that are ignored when looking for modules. These
|
||||
are 'src', 'lib', 'vendor', 'assets', 'css', 'files', 'images', 'js', 'misc',
|
||||
'templates', 'includes', 'fixtures' and 'Drupal'.
|
||||
|
||||
MULTISITE CONFIGURATION
|
||||
-----------------------
|
||||
|
||||
In multisite configurations, modules found in this directory are available to
|
||||
all sites. You may also put modules in the sites/all/modules directory, and the
|
||||
versions in sites/all/modules will take precedence over versions of the same
|
||||
module that are here. Alternatively, the sites/your_site_name/modules directory
|
||||
pattern may be used to restrict modules to a specific site instance.
|
||||
|
||||
MORE INFORMATION
|
||||
----------------
|
||||
|
||||
Refer to the “Developing for Drupal” section of the README.txt in the Drupal
|
||||
root directory for further information on extending Drupal with custom modules.
|
382
2017/web/modules/contrib/admin_toolbar/CHANGELOG.txt
Normal file
382
2017/web/modules/contrib/admin_toolbar/CHANGELOG.txt
Normal file
|
@ -0,0 +1,382 @@
|
|||
Admin Toolbar 8.x-1.25, 2018-11-22
|
||||
----------------------------------
|
||||
Changes since 8.x-1.24:
|
||||
|
||||
- #3012102 by tikaszvince, Jody Lynn, adriancid, grahl, jigarius: Provider
|
||||
property missing on link definition.
|
||||
- #3010451 by epowelljr, adriancid: Improve the admin_toolbar module
|
||||
description.
|
||||
- #2958415 by adriancid, romainj, Prashant.c, harshita29: Replace usages of the
|
||||
deprecated drupal_set_message() function.
|
||||
- #2996485 by idebr, adriancid: Remove unused function
|
||||
admin_toolbar_tools_get_links().
|
||||
- #2989281 by JKerschner, adriancid: Consistently use $entityTypeManager.
|
||||
- #2985106 by Eli-T, adriancid, eme: Add ability to hide Drupal.org links
|
||||
exposed by admin_toolbar_tools from certain users.
|
||||
- #2938884 by Spurlos, bdanin, romainj, purdy_nc, adriancid: A non-existent
|
||||
route breaks the site.
|
||||
|
||||
Admin Toolbar 8.x-1.24, 2018-05-28
|
||||
----------------------------------
|
||||
Changes since 8.x-1.23:
|
||||
|
||||
- #2973131 by adriancid: Don't refer to Drupal in the help page.
|
||||
- #2975170 by adriancid: Add composer.json file to submodules.
|
||||
- #2975165 by Gamewalker, adriancid: datetime.time services is not found in
|
||||
ToolbarController.
|
||||
- #2971466 by recrit, adriancid, acbramley: Add media links incorrectly set to
|
||||
"node.add.".
|
||||
- #2972553 by dww, adriancid: Add static cache to speed up
|
||||
admin_toolbar_links_access_filter_user_has_admin_role().
|
||||
- #2971435 by adriancid: Module help page for Admin Toolbar Extra Tools module
|
||||
doesn't show the links.
|
||||
- #2971398 by adriancid: Add the docblock to the ToolbarController constructor.
|
||||
- #2969686 by adriancid, Vidushi Mehta: Add a menu link to clean the twig cache.
|
||||
- #2969325 by adriancid: Fix the module version in the CHANGELOG.txt.
|
||||
- #2961450 by adriancid: Convert the AdminToolbarAlterTest test class to
|
||||
PHPUnit.
|
||||
- #2961445 by adriancid: Convert the AdminToolbarToolsAlterTest test class to
|
||||
PHPUnit.
|
||||
- #2959684 by adriancid: Remove recommended modules section from README.txt.
|
||||
- #2959647 by adriancid: Use interfaces instead of classes to inject
|
||||
dependencies.
|
||||
- #2952643 by romainj, if-jds, adriancid: Add Item for Files under Content Menu.
|
||||
- #2944463 by adriancid: Update the composer.json file.
|
||||
|
||||
Admin Toolbar 8.x-1.23, 2018-02-06
|
||||
----------------------------------
|
||||
Changes since 8.x-1.22:
|
||||
|
||||
- #2924266 by sunlix, romainj, adriancid, samerali: Add a menu link for the
|
||||
media module.
|
||||
- #2941184 by daniel.nitsche, adriancid: Remove unwanted comment from
|
||||
admin.toolbar.css.
|
||||
- #2912503 by Amsteri, m.abdulqader: Right to left language direction support.
|
||||
- #2937982 by romainj, adriancid: Auto-generation of menu links conflicts with
|
||||
other modules.
|
||||
- #2932873 by vaplas, saravanaprasanth, adriancid: Horizontal mode only works if
|
||||
the page is loaded in horizontal mode.
|
||||
- #2935311 by romainj, adriancid: Use the $entityTypeManager variable instead of
|
||||
the \Drupal::entityTypeManager service.
|
||||
- #2935449 by adriancid: Add the release information for the 1.22 version in the
|
||||
CHANGELOG.txt.
|
||||
- #2932476 by romainj: toolbar.tree library should have a dependency to the
|
||||
core/drupal library.
|
||||
- #2931503 by K3vin_nl: Admin toolbar generates invalid class names.
|
||||
|
||||
Admin Toolbar 8.x-1.22, 2018-01-02
|
||||
----------------------------------
|
||||
Changes since 8.x-1.21:
|
||||
|
||||
- #2929053 by kkuhnen, eme, adriancid: admin_toolbar.js should use Drupal
|
||||
behaviors.
|
||||
- #2929061 by romainj, dsnopek, adriancid: admin_toolbar_links_access_filter
|
||||
doesn't do anything unless admin_toolbar is enabled.
|
||||
- #2928836 by eme: One extra pixel line under the admin toolbar.
|
||||
- #2925501 by eme, adriancid, RumyanaRuseva: Menu does not take changes into
|
||||
account (caching issue).
|
||||
- #2927914 by adriancid: Parameter comment indentation must be 3 spaces.
|
||||
- #2927911 by adriancid: Remove unused variables.
|
||||
- #2927905 by adriancid: All dependencies must be prefixed with the project
|
||||
name.
|
||||
- #2925327 by Berdir, adriancid: Better check for is-link-in-admin-menu for
|
||||
local task links.
|
||||
- #2922046 by mikejw, adriancid, Berdir, BrianLewisDesign: Notice: Undefined
|
||||
index: entity.eform_type.collection in
|
||||
admin_toolbar_tools_menu_links_discovered_alter.
|
||||
- #2925128 by adriancid: Create the module help page for the Admin Toolbar Links
|
||||
Access Filter submodule.
|
||||
|
||||
Admin Toolbar 8.x-1.21, 2017-11-20
|
||||
----------------------------------
|
||||
Changes since 8.x-1.20:
|
||||
|
||||
- #2923580 by sylus, adriancid: Unsupported operand types in
|
||||
ToolbarHandler::lazyBuilder().
|
||||
- #2731369 by stefan.r, DuneBL, Berdir, kbasarab, joachim, adriancid: Local
|
||||
tasks don't show in the toolbar.
|
||||
- #2920793 by adriancid: Change the user TAKTAK by matio89 in the CHANGELOG.txt
|
||||
file.
|
||||
- #2873228 by smustgrave, adriancid, flocondetoile: Toolbar menu accessible and
|
||||
navigable with keyboard.
|
||||
- #2919775 by adriancid: Create the CHANGELOG.txt file.
|
||||
- #2919772 by adriancid: Use the README.txt template.
|
||||
- #2919769 by adriancid: Use the README.txt template for the admin_toolbar_tools
|
||||
submodule.
|
||||
- #2897309 by finne, adriancid, eme, rgpublic: admin_toolbar_tools module
|
||||
makes all pages uncacheable.
|
||||
- #2913299 by esod, Chi, adriancid, hudri, eme: CSS Z-Index of toolbar is
|
||||
inappropriate.
|
||||
- #2919390 by adriancid: Create the README.txt file for the admin toolbar links
|
||||
access filter submodule.
|
||||
- #2919367 by adriancid: Fix coding standard format.
|
||||
- #2919346 by adriancid: Don't show menu links that you don't have access
|
||||
permission for.
|
||||
- #2917710: Create the .info.yml file for the admin_toolbar_links_access_filter
|
||||
submodule.
|
||||
- #2916064 by adriancid, eme, finne: Use in drupal.org links url parameter and
|
||||
not route_name.
|
||||
- #2916040 by adriancid, finne, eme: Remove unused route admin_development.
|
||||
- #2915778 by finne, adriancid: Remove the _csrf_token from routes that don't
|
||||
need it.
|
||||
- #2909359 by adriancid, Musa.thomas: Add a menu link to clean the Views cache.
|
||||
- #2910931 by adriancid: .info.yml files don't have the drupal version.
|
||||
- #2759135 by Johnny vd Laar, miiimooo, romainj, chegor, adriancid, ckaotik,
|
||||
bdominguez, SpadXIII, mrtndlmt: Content type, Vocabularies and Menus names are
|
||||
not translated.
|
||||
- #2909710 by adriancid, Musa.thomas: Fix coding standard format.
|
||||
- #2910934 by adriancid, romainj: Error trying to clean the cache.
|
||||
- #2910892 by adriancid: Delete the LICENSE.txt.
|
||||
- #2909637 by bapi_22, Musa.thomas, adriancid: Avoid static call inside class
|
||||
method.
|
||||
- #2909003 by eme: fix z-index for CKEditor.
|
||||
- #2504449 by robin.ingelbrecht, rwam, eme: Un-hover delay.
|
||||
|
||||
Admin Toolbar 8.x-1.20, 2017-09-07
|
||||
----------------------------------
|
||||
Changes since 8.x-1.19:
|
||||
|
||||
- #2887439 by romainj: Fix test.
|
||||
- #2759135 by Johnny vd Laar, miiimooo, chegor, romainj: Content type,
|
||||
Vocabularies and Menus names are not translated.
|
||||
- #2894520 by romainj, bapi_22: Remove deprecated constant REQUEST_TIME from
|
||||
code base.
|
||||
- #2883098 by romainj, Alka Kumari: Admin Toolbar Extra Tools module display
|
||||
theme machine names instead of labels.
|
||||
- #2504449 by robin.ingelbrecht: Un-hover delay.
|
||||
- #2838636 by ddrozdik, Fons Vandamme, kerby70, romainj: Issue with z-index of
|
||||
dropdown in horizontal tray.
|
||||
- #2838636 by Fons Vandamme, ddrozdik, romainj: Issue with z-index of dropdown
|
||||
in horizontal tray.
|
||||
- #2870404 by romainj: Add a link to the Webprofiler settings page.
|
||||
- #2706643 by esod, romainj, Keenegan, DamienMcKenna: Use short array syntax.
|
||||
|
||||
Admin Toolbar 8.x-1.19, 2017-04-06
|
||||
----------------------------------
|
||||
Changes since 8.x-1.18:
|
||||
|
||||
- #2706643 by esod, romainj, Keenegan, DamienMcKenna: Use short array syntax.
|
||||
- #2781745 by minakshiPh, eelkeblok, romainj, akhilavnair_zyxware: Drupal coding
|
||||
standard issues found in most of the files.
|
||||
- #2855720 by stefan.r, romainj: No logout link in admin toolbar anymore.
|
||||
- #2841512 by Chi, romainj: User error: Redirects to external URLs are not
|
||||
allowed by default.
|
||||
|
||||
Admin Toolbar 8.x-1.18, 2016-12-01
|
||||
----------------------------------
|
||||
Changes since 8.x-1.17:
|
||||
|
||||
- #2830677 by vaplas, romainj: z-index for sub menu.
|
||||
- by romainj: Get rid of the Hello popup.
|
||||
- #2805431 by marcusx: Accidentaly committed alert.
|
||||
- #2630724 by squarecandy, romainj, reblutus, Hemangi Gokhale, jacoferg,
|
||||
Balu Ertl, Jeff Burnz, Don Greco: Consider changes to link title parameter to
|
||||
avoid tooltip visual conflict.
|
||||
- #2518202 by james.williams, chegor, eme, romainj, DuneBL: Change default link
|
||||
to taxonomy.
|
||||
|
||||
Admin Toolbar 8.x-1.17, 2016-08-19
|
||||
----------------------------------
|
||||
Changes since 8.x-1.16:
|
||||
|
||||
- #2779251 by romainj, DuneBL: Wrong integration of field_collection delete
|
||||
form.
|
||||
- #2776229 by Chi, romainj, mattlt: Chevron icons missing if Drupal is not in
|
||||
document root.
|
||||
- by romainj: CSS coding standard cleaning.
|
||||
- #2781059 by mstrelan, romainj: Why is CRON in all caps?
|
||||
- #2778935 by akhilavnair_zyxware, rjarraud: As per Drupal Standards each line
|
||||
in documentation should not exceeds 80 characters.
|
||||
- by romainj: Adds ending new line where required.
|
||||
- #2776229 by Chi, rjarraud: Chevron icons missing if Drupal is not in document
|
||||
root.
|
||||
- by eme: Commiting again #2707611.
|
||||
- #2757687 by neerajsingh: Remove usages of \Drupal::url().
|
||||
- #2707747 by Balu Ertl, nevergone, eme, esod: D8 logo not rendered with smooth
|
||||
antialiasing.
|
||||
|
||||
Admin Toolbar 8.x-1.16, 2016-07-28
|
||||
----------------------------------
|
||||
Changes since 8.x-1.15:
|
||||
|
||||
- #2723209 by andrewmacpherson, colan, mattshoaf: Enabling admin_toolbar_tools
|
||||
causes Devel Settings to disappear from the main configuration page.
|
||||
- #2759335 bycwells, jalpesh: fixes a mistaken link in hook_help().
|
||||
- #2664564 by kolier, matio89, romainj and Michèle: auto-detect content entities
|
||||
with Field UI route.
|
||||
- #2735257 by colan, romainj, Balu Ertl: respect of coding standards in the
|
||||
module README.txt file.
|
||||
- #2735257 by colan, romainj, Balu Ertl: shortens the module README.txt
|
||||
description text.
|
||||
- by romainj: Fixes a problem with the link to the Admin menu overview page.
|
||||
- #2735257 by Balu Ertl, colan, romainj: improves Admin Toolbar Extra Tools
|
||||
description in the README.txt file.
|
||||
- #2723381 by joachim, romainj: fieldable content entities are no more
|
||||
hardcoded.
|
||||
- #2735257 by Balu Ertl, colan, romainj: added some description details in the
|
||||
README.txt files.
|
||||
- by romainj: Menu link definitions updated.
|
||||
- by romainj: Change routing permissions to follow Drupal default permissions
|
||||
for administration pages.
|
||||
- by romainj: Fixes issue #2737027.
|
||||
- by romainj: fixes issue #2701825.
|
||||
- by romainj: Adds the menu name for each menu item in
|
||||
admin_toolbar_tools/admin_toolbar_tools.links.menu.yml file.
|
||||
- #2735153 by Kionn: InvalidArgumentException: Cannot redirect to an empty URL.
|
||||
в Symfony\Component\HttpFoundation\RedirectResponse->setTargetUrl().
|
||||
- by matio89: correction InvalidArgumentException: Cannot redirect to an empty
|
||||
URL. в Symfony\Component\HttpFoundation\RedirectResponse->setTargetUrl().
|
||||
- by romainj: Add a new Render Cache shortcut on the admin menu.
|
||||
- by romainj: Fixes issue #2731663 by canceling the move of the Logout menu
|
||||
link.
|
||||
|
||||
Admin Toolbar 8.x-1.15, 2016-05-23
|
||||
----------------------------------
|
||||
Changes since 8.x-1.14:
|
||||
|
||||
- by matio89: add RTL in admin.toolbar.css.
|
||||
- by romainj: Changes Devel menu item titles.
|
||||
- by romainj: Fixes issue #2713899.
|
||||
- by romainj: Minor code/typo cleaning.
|
||||
- #2707611 by Balu Ertl: Add fine shadow under dropdown menus.
|
||||
- #2707789 by esod: Fix Automated Tests.
|
||||
- by romainj: Code cleaning.
|
||||
- by romainj: Replace the deprecated entityManager() by entityTypeManager()
|
||||
service.
|
||||
- by romainj: Emptying menu cache with all link types.
|
||||
- #2614962 by dbt102, seppelM, neha.gangwar, chegor: Correct text in
|
||||
info.yml(s).
|
||||
- by eme: Minor typo changes.
|
||||
- by eme: Fix dependencies to core modules.
|
||||
- by eme: Fix issue #2666964.
|
||||
- by eme: Fix css background color level3.
|
||||
- by eme: fix issue #2658896 and refactor and fix chevron-right.svg.
|
||||
- by eme: fix Issue #2493037.
|
||||
|
||||
Admin Toolbar 8.x-1.14, 2016-02-08
|
||||
----------------------------------
|
||||
Changes since 8.x-1.13:
|
||||
|
||||
- by matio89: Correction differents bugs(problem white page when installing a
|
||||
new module).
|
||||
- #2643648 by Lord_of_Codes: Proposed README.txt file for Admin Toolbar.
|
||||
- by matio89: resolving the dependecies problem(dependencies of others modules).
|
||||
- by matio89: Correction route of entities.
|
||||
|
||||
Admin Toolbar 8.x-1.13, 2016-02-02
|
||||
----------------------------------
|
||||
Changes since 8.x-1.12:
|
||||
|
||||
- by matio89: Admin toolbar is compatible with 8.0.2.
|
||||
- by matio89: Commmit dev version compatible with drupal 8.0.2.
|
||||
- by matio89: New version of admin toolbar compatible with 8.0.2.
|
||||
|
||||
Admin Toolbar 8.x-1.12, 2016-01-15
|
||||
----------------------------------
|
||||
Changes since 8.x-1.11:
|
||||
|
||||
- by matio89: Correction AdminToolbaToolsAlterTest.
|
||||
- #2493037 by mimran: Empty elements in #toolbar-bar.
|
||||
- #2598136 by mimran, felribeiro: Menu items duplicated.
|
||||
- #2635154 by Lukas von Blarer: Too general CSS selectors.
|
||||
- by eme: Fix chevron right in local state.
|
||||
|
||||
Admin Toolbar 8.x-1.11, 2015-12-11
|
||||
----------------------------------
|
||||
Changes since 8.x-1.10:
|
||||
|
||||
- #2620430 by Vagelis, NarendraR: Typo.
|
||||
- #2632888 by JamesK: Add dependency on node module.
|
||||
- by eme: Fix admin toolbar test.
|
||||
- #2552081 by jonhattan, bruvers: chevron-right.svg not found.
|
||||
- by Vagelis: Minor typos.
|
||||
- by eme: Refactor basic tests.
|
||||
- #2613378 by chegor: Add basic test.
|
||||
- #2612694 by chegor: Add new view.
|
||||
- #2627918 by joe_carvajal: Version in info.yml files does Update Manager try to
|
||||
update.
|
||||
- by matio89: correction collapsible behaviour in vertical menu layout.
|
||||
- #2582825 by Ben Coleman: Installing Admin Toolbar Tools loses anonymous user
|
||||
login link.
|
||||
- by matio89: Correction the login link on the site when in a logged-out state.
|
||||
|
||||
Admin Toolbar 8.x-1.10, 2015-08-07
|
||||
----------------------------------
|
||||
Changes since 8.x-1.9:
|
||||
|
||||
- #2546939 by jonhattan: Add dependency on toolbar module.
|
||||
|
||||
Admin Toolbar 8.x-1.9, 2015-07-22
|
||||
---------------------------------
|
||||
Changes since 8.x-1.8:
|
||||
|
||||
- #2537016 by matio89: Removing dependance for user & system.
|
||||
- #2533420 by Dave Reid, twistor: Chase HEAD changes in toolbar.
|
||||
- #2537016 by twistor: Rewrite admin_toolbar_tools.module
|
||||
- by matio89: Correction all bugs and add new security features.
|
||||
|
||||
Admin Toolbar 8.x-1.8, 2015-06-22
|
||||
---------------------------------
|
||||
Changes since 8.x-1.7:
|
||||
|
||||
- correction not found route.
|
||||
- #2493037 by bobrov1989: Empty elements in #toolbar-bar.
|
||||
- by fethi: icones.
|
||||
|
||||
Admin Toolbar 8.x-1.7, 2015-06-22
|
||||
---------------------------------
|
||||
Changes since 8.x-1.6:
|
||||
|
||||
- correction not found route.
|
||||
- #2493037 by bobrov1989: Empty elements in #toolbar-bar.
|
||||
- by fethi: icones.
|
||||
|
||||
Admin Toolbar 8.x-1.6, 2015-06-03
|
||||
---------------------------------
|
||||
Changes since 8.x-1.5:
|
||||
|
||||
- by matio89: correction admin_toolbar.
|
||||
|
||||
Admin Toolbar 8.x-1.5, 2015-06-03
|
||||
---------------------------------
|
||||
Changes since 8.x-1.4:
|
||||
|
||||
- by matio89: test if module update exist or no to display install and update
|
||||
module.
|
||||
- by fethi: Change the colors used to match the Seven styleguide.
|
||||
- by matio89: compatibility with Drupal 8 béta 11.
|
||||
- by fethi: Change the colors used to match the Seven styleguide.
|
||||
|
||||
Admin Toolbar 8.x-1.4, 2015-05-20
|
||||
---------------------------------
|
||||
Changes since 8.x-1.3:
|
||||
|
||||
- by matio89: correction add/node.
|
||||
|
||||
Admin Toolbar 8.x-1.3, 2015-05-19
|
||||
---------------------------------
|
||||
Changes since 8.x-1.2:
|
||||
|
||||
- by matio89: add new functionalities.
|
||||
- by matio89: add administration devel link.
|
||||
- by matio89: correction reload page.
|
||||
- by matio89: correction redirect to the same page.
|
||||
|
||||
Admin Toolbar 8.x-1.2, 2015-05-19
|
||||
---------------------------------
|
||||
Changes since 8.x-1.1:
|
||||
|
||||
- by matio89: add new functionalities.
|
||||
- by matio89: add administration devel link.
|
||||
- by matio89: correction reload page.
|
||||
- by matio89: correction redirect to the same page.
|
||||
|
||||
Admin Toolbar 8.x-1.1, 2015-05-19
|
||||
---------------------------------
|
||||
Changes since 8.x-1.0:
|
||||
|
||||
- by matio89: add new functionalities.
|
||||
|
||||
Admin Toolbar 8.x-1.0, 2015-05-07
|
||||
---------------------------------
|
||||
- Initial release.
|
339
2017/web/modules/contrib/admin_toolbar/LICENSE.txt
Normal file
339
2017/web/modules/contrib/admin_toolbar/LICENSE.txt
Normal file
|
@ -0,0 +1,339 @@
|
|||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 2, June 1991
|
||||
|
||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
License is intended to guarantee your freedom to share and change free
|
||||
software--to make sure the software is free for all its users. This
|
||||
General Public License applies to most of the Free Software
|
||||
Foundation's software and to any other program whose authors commit to
|
||||
using it. (Some other Free Software Foundation software is covered by
|
||||
the GNU Lesser General Public License instead.) You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
this service if you wish), that you receive source code or can get it
|
||||
if you want it, that you can change the software or use pieces of it
|
||||
in new free programs; and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
anyone to deny you these rights or to ask you to surrender the rights.
|
||||
These restrictions translate to certain responsibilities for you if you
|
||||
distribute copies of the software, or if you modify it.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must give the recipients all the rights that
|
||||
you have. You must make sure that they, too, receive or can get the
|
||||
source code. And you must show them these terms so they know their
|
||||
rights.
|
||||
|
||||
We protect your rights with two steps: (1) copyright the software, and
|
||||
(2) offer you this license which gives you legal permission to copy,
|
||||
distribute and/or modify the software.
|
||||
|
||||
Also, for each author's protection and ours, we want to make certain
|
||||
that everyone understands that there is no warranty for this free
|
||||
software. If the software is modified by someone else and passed on, we
|
||||
want its recipients to know that what they have is not the original, so
|
||||
that any problems introduced by others will not reflect on the original
|
||||
authors' reputations.
|
||||
|
||||
Finally, any free program is threatened constantly by software
|
||||
patents. We wish to avoid the danger that redistributors of a free
|
||||
program will individually obtain patent licenses, in effect making the
|
||||
program proprietary. To prevent this, we have made it clear that any
|
||||
patent must be licensed for everyone's free use or not licensed at all.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License applies to any program or other work which contains
|
||||
a notice placed by the copyright holder saying it may be distributed
|
||||
under the terms of this General Public License. The "Program", below,
|
||||
refers to any such program or work, and a "work based on the Program"
|
||||
means either the Program or any derivative work under copyright law:
|
||||
that is to say, a work containing the Program or a portion of it,
|
||||
either verbatim or with modifications and/or translated into another
|
||||
language. (Hereinafter, translation is included without limitation in
|
||||
the term "modification".) Each licensee is addressed as "you".
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running the Program is not restricted, and the output from the Program
|
||||
is covered only if its contents constitute a work based on the
|
||||
Program (independent of having been made by running the Program).
|
||||
Whether that is true depends on what the Program does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Program's
|
||||
source code as you receive it, in any medium, provided that you
|
||||
conspicuously and appropriately publish on each copy an appropriate
|
||||
copyright notice and disclaimer of warranty; keep intact all the
|
||||
notices that refer to this License and to the absence of any warranty;
|
||||
and give any other recipients of the Program a copy of this License
|
||||
along with the Program.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy, and
|
||||
you may at your option offer warranty protection in exchange for a fee.
|
||||
|
||||
2. You may modify your copy or copies of the Program or any portion
|
||||
of it, thus forming a work based on the Program, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) You must cause the modified files to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
b) You must cause any work that you distribute or publish, that in
|
||||
whole or in part contains or is derived from the Program or any
|
||||
part thereof, to be licensed as a whole at no charge to all third
|
||||
parties under the terms of this License.
|
||||
|
||||
c) If the modified program normally reads commands interactively
|
||||
when run, you must cause it, when started running for such
|
||||
interactive use in the most ordinary way, to print or display an
|
||||
announcement including an appropriate copyright notice and a
|
||||
notice that there is no warranty (or else, saying that you provide
|
||||
a warranty) and that users may redistribute the program under
|
||||
these conditions, and telling the user how to view a copy of this
|
||||
License. (Exception: if the Program itself is interactive but
|
||||
does not normally print such an announcement, your work based on
|
||||
the Program is not required to print an announcement.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Program,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Program, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Program.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Program
|
||||
with the Program (or with a work based on the Program) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may copy and distribute the Program (or a work based on it,
|
||||
under Section 2) in object code or executable form under the terms of
|
||||
Sections 1 and 2 above provided that you also do one of the following:
|
||||
|
||||
a) Accompany it with the complete corresponding machine-readable
|
||||
source code, which must be distributed under the terms of Sections
|
||||
1 and 2 above on a medium customarily used for software interchange; or,
|
||||
|
||||
b) Accompany it with a written offer, valid for at least three
|
||||
years, to give any third party, for a charge no more than your
|
||||
cost of physically performing source distribution, a complete
|
||||
machine-readable copy of the corresponding source code, to be
|
||||
distributed under the terms of Sections 1 and 2 above on a medium
|
||||
customarily used for software interchange; or,
|
||||
|
||||
c) Accompany it with the information you received as to the offer
|
||||
to distribute corresponding source code. (This alternative is
|
||||
allowed only for noncommercial distribution and only if you
|
||||
received the program in object code or executable form with such
|
||||
an offer, in accord with Subsection b above.)
|
||||
|
||||
The source code for a work means the preferred form of the work for
|
||||
making modifications to it. For an executable work, complete source
|
||||
code means all the source code for all modules it contains, plus any
|
||||
associated interface definition files, plus the scripts used to
|
||||
control compilation and installation of the executable. However, as a
|
||||
special exception, the source code distributed need not include
|
||||
anything that is normally distributed (in either source or binary
|
||||
form) with the major components (compiler, kernel, and so on) of the
|
||||
operating system on which the executable runs, unless that component
|
||||
itself accompanies the executable.
|
||||
|
||||
If distribution of executable or object code is made by offering
|
||||
access to copy from a designated place, then offering equivalent
|
||||
access to copy the source code from the same place counts as
|
||||
distribution of the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
4. You may not copy, modify, sublicense, or distribute the Program
|
||||
except as expressly provided under this License. Any attempt
|
||||
otherwise to copy, modify, sublicense or distribute the Program is
|
||||
void, and will automatically terminate your rights under this License.
|
||||
However, parties who have received copies, or rights, from you under
|
||||
this License will not have their licenses terminated so long as such
|
||||
parties remain in full compliance.
|
||||
|
||||
5. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Program or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Program (or any work based on the
|
||||
Program), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Program or works based on it.
|
||||
|
||||
6. Each time you redistribute the Program (or any work based on the
|
||||
Program), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute or modify the Program subject to
|
||||
these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties to
|
||||
this License.
|
||||
|
||||
7. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Program at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Program by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Program.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under
|
||||
any particular circumstance, the balance of the section is intended to
|
||||
apply and the section as a whole is intended to apply in other
|
||||
circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system, which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
8. If the distribution and/or use of the Program is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Program under this License
|
||||
may add an explicit geographical distribution limitation excluding
|
||||
those countries, so that distribution is permitted only in or among
|
||||
countries not thus excluded. In such case, this License incorporates
|
||||
the limitation as if written in the body of this License.
|
||||
|
||||
9. The Free Software Foundation may publish revised and/or new versions
|
||||
of the General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Program
|
||||
specifies a version number of this License which applies to it and "any
|
||||
later version", you have the option of following the terms and conditions
|
||||
either of that version or of any later version published by the Free
|
||||
Software Foundation. If the Program does not specify a version number of
|
||||
this License, you may choose any version ever published by the Free Software
|
||||
Foundation.
|
||||
|
||||
10. If you wish to incorporate parts of the Program into other free
|
||||
programs whose distribution conditions are different, write to the author
|
||||
to ask for permission. For software which is copyrighted by the Free
|
||||
Software Foundation, write to the Free Software Foundation; we sometimes
|
||||
make exceptions for this. Our decision will be guided by the two goals
|
||||
of preserving the free status of all derivatives of our free software and
|
||||
of promoting the sharing and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
|
||||
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
|
||||
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
|
||||
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
|
||||
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
|
||||
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
|
||||
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
|
||||
REPAIR OR CORRECTION.
|
||||
|
||||
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
||||
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
|
||||
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
|
||||
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
|
||||
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
|
||||
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
convey the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program is interactive, make it output a short notice like this
|
||||
when it starts in an interactive mode:
|
||||
|
||||
Gnomovision version 69, Copyright (C) year name of author
|
||||
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, the commands you use may
|
||||
be called something other than `show w' and `show c'; they could even be
|
||||
mouse-clicks or menu items--whatever suits your program.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or your
|
||||
school, if any, to sign a "copyright disclaimer" for the program, if
|
||||
necessary. Here is a sample; alter the names:
|
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
|
||||
`Gnomovision' (which makes passes at compilers) written by James Hacker.
|
||||
|
||||
<signature of Ty Coon>, 1 April 1989
|
||||
Ty Coon, President of Vice
|
||||
|
||||
This General Public License does not permit incorporating your program into
|
||||
proprietary programs. If your program is a subroutine library, you may
|
||||
consider it more useful to permit linking proprietary applications with the
|
||||
library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License.
|
69
2017/web/modules/contrib/admin_toolbar/README.txt
Normal file
69
2017/web/modules/contrib/admin_toolbar/README.txt
Normal file
|
@ -0,0 +1,69 @@
|
|||
CONTENTS OF THIS FILE
|
||||
---------------------
|
||||
|
||||
* Introduction
|
||||
* Requirements
|
||||
* Recommended modules
|
||||
* Installation
|
||||
* Configuration
|
||||
* Maintainers
|
||||
|
||||
|
||||
INTRODUCTION
|
||||
------------
|
||||
|
||||
Admin Toolbar intends to improve the default Drupal Toolbar to transform it into
|
||||
a drop-down menu, providing a fast and full access to all administration links.
|
||||
|
||||
* For a full description of the module, visit the project page:
|
||||
https://www.drupal.org/project/admin_toolbar
|
||||
|
||||
* To submit bug reports and feature suggestions, or to track changes:
|
||||
https://www.drupal.org/project/issues/search/admin_toolbar
|
||||
|
||||
|
||||
REQUIREMENTS
|
||||
------------
|
||||
|
||||
No special requirements.
|
||||
|
||||
|
||||
RECOMMENDED MODULES
|
||||
-------------------
|
||||
|
||||
* Admin Toolbar Extra Tools (https://www.drupal.org/project/admin_toolbar):
|
||||
Provides menu links to administration pages or actions (eg. Flushing caches)
|
||||
that are not generated by Drupal core.
|
||||
|
||||
* Admin Toolbar Links Access Filter (https://www.drupal.org/node/2474539):
|
||||
Provides a workaround for the common problem that users with
|
||||
'Use the administration pages and help' permission see menu links they don't
|
||||
have access permission for.
|
||||
|
||||
INSTALLATION
|
||||
------------
|
||||
|
||||
* Install as you would normally install a contributed Drupal module.
|
||||
See: https://www.drupal.org/node/895232 for further information.
|
||||
|
||||
|
||||
CONFIGURATION
|
||||
-------------
|
||||
|
||||
No configuration is needed.
|
||||
|
||||
|
||||
MAINTAINERS
|
||||
-----------
|
||||
|
||||
Current maintainers:
|
||||
* Wilfrid Roze (eme) - https://www.drupal.org/u/eme
|
||||
* Romain Jarraud (romainj) - https://www.drupal.org/u/romainj
|
||||
* Adrian Cid Almaguer (adriancid) - https://www.drupal.org/u/adriancid
|
||||
* Mohamed Anis Taktak (matio89) - https://www.drupal.org/u/matio89
|
||||
|
||||
This project has been sponsored by:
|
||||
* emerya
|
||||
Founded in 2009, emerya is a human-sized company, dedicated to the design and
|
||||
implementation of web interfaces. Visit: http://http://emerya.fr/ for more
|
||||
information.
|
|
@ -0,0 +1,15 @@
|
|||
name: Admin Toolbar
|
||||
description: Provides an improved drop-down menu interface to the site Toolbar.
|
||||
package: Administration
|
||||
|
||||
type: module
|
||||
# core: 8.x
|
||||
|
||||
dependencies:
|
||||
- drupal:toolbar
|
||||
|
||||
# Information added by Drupal.org packaging script on 2018-11-22
|
||||
version: '8.x-1.25'
|
||||
core: '8.x'
|
||||
project: 'admin_toolbar'
|
||||
datestamp: 1542915184
|
16
2017/web/modules/contrib/admin_toolbar/admin_toolbar.install
Normal file
16
2017/web/modules/contrib/admin_toolbar/admin_toolbar.install
Normal file
|
@ -0,0 +1,16 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Install, update and uninstall functions for the Admin Toolbar module.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Rebuild routes to mitigate issue 2938884.
|
||||
*
|
||||
* @see https://www.drupal.org/project/admin_toolbar/issues/2938884
|
||||
*/
|
||||
function admin_toolbar_update_8001() {
|
||||
// Rebuilding the route cache.
|
||||
\Drupal::service("router.builder")->rebuild();
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
toolbar.tree:
|
||||
css:
|
||||
theme:
|
||||
css/admin.toolbar.css: {}
|
||||
js:
|
||||
js/jquery.hoverIntent.js: {}
|
||||
js/admin_toolbar.js: {}
|
||||
dependencies:
|
||||
- core/jquery
|
||||
- core/drupal
|
97
2017/web/modules/contrib/admin_toolbar/admin_toolbar.module
Normal file
97
2017/web/modules/contrib/admin_toolbar/admin_toolbar.module
Normal file
|
@ -0,0 +1,97 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* This is the module to create a drop-down menu for the core toolbar.
|
||||
*/
|
||||
|
||||
use Drupal\Core\Menu\MenuTreeParameters;
|
||||
use Drupal\Core\Routing\RouteMatchInterface;
|
||||
use Drupal\Core\Url;
|
||||
use Drupal\Component\Utility\Html;
|
||||
|
||||
/**
|
||||
* Implements hook_toolbar_alter().
|
||||
*/
|
||||
function admin_toolbar_toolbar_alter(&$items) {
|
||||
$items['administration']['tray']['toolbar_administration']['#pre_render'] = ['admin_toolbar_prerender_toolbar_administration_tray'];
|
||||
$items['administration']['#attached']['library'][] = 'admin_toolbar/toolbar.tree';
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_help().
|
||||
*/
|
||||
function admin_toolbar_help($route_name, RouteMatchInterface $route_match) {
|
||||
switch ($route_name) {
|
||||
case 'help.page.admin_toolbar':
|
||||
$variables = [
|
||||
':toolbar' => Url::fromRoute('help.page', ['name' => 'toolbar'])->toString(),
|
||||
':automated_cron' => (\Drupal::moduleHandler()->moduleExists('automated_cron')) ? Url::fromRoute('help.page', ['name' => 'automated_cron'])->toString() : '#',
|
||||
];
|
||||
|
||||
$output = '';
|
||||
$output .= '<h3>' . t('About') . '</h3>';
|
||||
$output .= '<p>' . t('The Admin Toolbar module enhances the <a href=":toolbar">Toolbar</a> module by providing fast access to all the administrative links at the top of your site. Admin Toolbar remains a very "lightweight" module by closely integrating with all Toolbar functionality. It can be used in conjunction with all the sub modules included on Admin Toolbar, for quick access to system commands such as Flush all caches, <a href=":automated_cron">Run cron</a>, Run Updates, etc.', $variables) . '</p>';
|
||||
$output .= '<h3>' . t('Uses') . '</h3>';
|
||||
$output .= '<p>' . t('The Admin Toolbar greatly improves the user experience for those who regularly interact with the site Toolbar by providing fast, full access to all links in the site Toolbar without having to click to get there.') . '</p>';
|
||||
|
||||
return $output;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the toolbar's administration tray.
|
||||
*
|
||||
* This is a clone of core's toolbar_prerender_toolbar_administration_tray()
|
||||
* function, which uses setMaxDepth(4) instead of setTopLevelOnly().
|
||||
*
|
||||
* @param array $element
|
||||
* A renderable array.
|
||||
*
|
||||
* @return array
|
||||
* The updated renderable array.
|
||||
*
|
||||
* @see toolbar_prerender_toolbar_administration_tray()
|
||||
*/
|
||||
function admin_toolbar_prerender_toolbar_administration_tray(array $element) {
|
||||
$menu_tree = \Drupal::service('toolbar.menu_tree');
|
||||
$parameters = new MenuTreeParameters();
|
||||
$parameters->setRoot('system.admin')->excludeRoot()->setMaxDepth(4)->onlyEnabledLinks();
|
||||
$tree = $menu_tree->load(NULL, $parameters);
|
||||
$manipulators = [
|
||||
['callable' => 'menu.default_tree_manipulators:checkAccess'],
|
||||
['callable' => 'menu.default_tree_manipulators:generateIndexAndSort'],
|
||||
['callable' => 'toolbar_tools_menu_navigation_links'],
|
||||
];
|
||||
$tree = $menu_tree->transform($tree, $manipulators);
|
||||
$element['administration_menu'] = $menu_tree->build($tree);
|
||||
|
||||
return $element;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds toolbar-specific attributes to the menu link tree.
|
||||
*
|
||||
* @param \Drupal\Core\Menu\MenuLinkTreeElement[] $tree
|
||||
* The menu link tree to manipulate.
|
||||
*
|
||||
* @return \Drupal\Core\Menu\MenuLinkTreeElement[]
|
||||
* The manipulated menu link tree.
|
||||
*/
|
||||
function toolbar_tools_menu_navigation_links(array $tree) {
|
||||
foreach ($tree as $element) {
|
||||
if ($element->subtree) {
|
||||
toolbar_tools_menu_navigation_links($element->subtree);
|
||||
}
|
||||
$link = $element->link;
|
||||
|
||||
// Get the non-localized title to make the icon class.
|
||||
$definition = $link->getPluginDefinition();
|
||||
|
||||
$element->options['attributes']['class'][] = 'toolbar-icon';
|
||||
$string = strtolower(str_replace(['.', ' ', '_'], ['-', '-', '-'], $definition['id']));
|
||||
$element->options['attributes']['class'][] = Html::cleanCssIdentifier('toolbar-icon-' . $string);
|
||||
$element->options['attributes']['title'] = $link->getDescription();
|
||||
}
|
||||
return $tree;
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
CONTENTS OF THIS FILE
|
||||
---------------------
|
||||
|
||||
* Introduction
|
||||
* Requirements
|
||||
* Installation
|
||||
* Configuration
|
||||
* Maintainers
|
||||
|
||||
|
||||
INTRODUCTION
|
||||
------------
|
||||
|
||||
The Admin Toolbar Links Access Filter module Provides a workaround for the
|
||||
common problem that users with 'Use the administration pages and help'
|
||||
permission see menu links they don't have access permission for. Once the issue
|
||||
https://www.drupal.org/node/296693 be solved, this module will be deprecated.
|
||||
|
||||
* To know why we create this module check this issue:
|
||||
https://www.drupal.org/node/2917704
|
||||
|
||||
* To submit bug reports and feature suggestions, or to track changes:
|
||||
https://www.drupal.org/project/issues/search/admin_toolbar
|
||||
|
||||
|
||||
REQUIREMENTS
|
||||
------------
|
||||
|
||||
This module requires the following modules:
|
||||
|
||||
* Admin Toolbar (https://www.drupal.org/project/admin_toolbar)
|
||||
|
||||
|
||||
INSTALLATION
|
||||
------------
|
||||
|
||||
* Install as you would normally install a contributed Drupal module.
|
||||
See: https://www.drupal.org/node/895232 for further information.
|
||||
|
||||
|
||||
CONFIGURATION
|
||||
-------------
|
||||
|
||||
No configuration is needed.
|
||||
|
||||
|
||||
MAINTAINERS
|
||||
-----------
|
||||
|
||||
Current maintainers:
|
||||
* Wilfrid Roze (eme) - https://www.drupal.org/u/eme
|
||||
* Romain Jarraud (romainj) - https://www.drupal.org/u/romainj
|
||||
* Adrian Cid Almaguer (adriancid) - https://www.drupal.org/u/adriancid
|
|
@ -0,0 +1,15 @@
|
|||
name: Admin Toolbar Links Access Filter
|
||||
description: Provides a workaround for the common problem that users with 'Use the administration pages and help' permission see menu links they don't have access permission for. Once the issue <a href='https://www.drupal.org/node/296693'>https://www.drupal.org/node/296693</a> be solved, this module will be deprecated.
|
||||
package: Administration
|
||||
|
||||
type: module
|
||||
# core: 8.x
|
||||
|
||||
dependencies:
|
||||
- admin_toolbar:admin_toolbar
|
||||
|
||||
# Information added by Drupal.org packaging script on 2018-11-22
|
||||
version: '8.x-1.25'
|
||||
core: '8.x'
|
||||
project: 'admin_toolbar'
|
||||
datestamp: 1542915184
|
|
@ -0,0 +1,200 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* This module don't show menu links that you don't have access permission for.
|
||||
*/
|
||||
|
||||
use Drupal\Core\Session\AccountInterface;
|
||||
use Drupal\Core\Url;
|
||||
use Drupal\user\Entity\Role;
|
||||
use Symfony\Component\Routing\Exception\RouteNotFoundException;
|
||||
use Drupal\Core\Routing\RouteMatchInterface;
|
||||
|
||||
/**
|
||||
* Implements hook_help().
|
||||
*/
|
||||
function admin_toolbar_links_access_filter_help($route_name, RouteMatchInterface $route_match) {
|
||||
switch ($route_name) {
|
||||
// Main module help.
|
||||
case 'help.page.admin_toolbar_links_access_filter':
|
||||
$output = '';
|
||||
$output .= '<h3>' . t('About') . '</h3>';
|
||||
$output .= '<p>' . t('The Admin Toolbar Links Access Filter module provides a workaround for the common problem that users with <em>Use the administration pages and help</em> permission see menu links they done not have access permission for.') . '</p>';
|
||||
|
||||
return $output;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_preprocess_menu().
|
||||
*
|
||||
* Hides links from admin menu, if user doesn't have access rights.
|
||||
*/
|
||||
function admin_toolbar_links_access_filter_preprocess_menu(&$variables) {
|
||||
if (empty($variables['items'])) {
|
||||
// Additional empty check to prevent exotic situations, where the preprocess
|
||||
// function is entered even without items.
|
||||
// @see https://www.drupal.org/node/2833885
|
||||
return;
|
||||
}
|
||||
// Ensure that menu_name exists.
|
||||
if (!isset($variables['menu_name'])) {
|
||||
// In rare cases (for unknown reasons) menu_name may not be set.
|
||||
// As fallback, we can fetch it from the first menu item.
|
||||
$first_link = reset($variables['items']);
|
||||
/** @var Drupal\Core\Menu\MenuLinkDefault $original_link */
|
||||
// Fetch the menu_name from the original link.
|
||||
$original_link = $first_link['original_link'];
|
||||
$variables['menu_name'] = $original_link->getMenuName();
|
||||
}
|
||||
if ($variables['menu_name'] == 'admin') {
|
||||
if (!admin_toolbar_links_access_filter_user_has_admin_role($variables['user'])) {
|
||||
admin_toolbar_links_access_filter_filter_non_accessible_links($variables['items']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Hides links from admin menu, if user doesn't have access rights.
|
||||
*/
|
||||
function admin_toolbar_links_access_filter_filter_non_accessible_links(array &$items) {
|
||||
foreach ($items as $route => &$item) {
|
||||
$route_name = $route;
|
||||
$route_params = [];
|
||||
if (!empty($item['original_link'])) {
|
||||
/** @var \Drupal\Core\Menu\MenuLinkBase $original_link */
|
||||
$original_link = $item['original_link'];
|
||||
if ($original_link->getUrlObject()->isExternal()) {
|
||||
// Do not filter external URL at all.
|
||||
continue;
|
||||
}
|
||||
$route_name = $original_link->getRouteName();
|
||||
$route_params = $original_link->getRouteParameters();
|
||||
}
|
||||
|
||||
// Check, if user has access rights to the route.
|
||||
if (!\Drupal::accessManager()->checkNamedRoute($route_name, $route_params)) {
|
||||
unset($items[$route]);
|
||||
}
|
||||
else {
|
||||
if (!empty($items[$route]['below'])) {
|
||||
// Recursively call this function for the child items.
|
||||
admin_toolbar_links_access_filter_filter_non_accessible_links($items[$route]['below']);
|
||||
}
|
||||
if (empty($items[$route]['below']) && \Drupal::moduleHandler()->moduleExists('admin_toolbar')) {
|
||||
|
||||
// Every child item has been cleared out.
|
||||
// Now check, if the given route represents an overview page only,
|
||||
// without having functionality on its own. In this case, we can safely
|
||||
// unset this item, as there aren't any children left.
|
||||
// This assumption is only valid, when the admin_toolbar module is
|
||||
// installed because otherwise we won't have child items at all.
|
||||
if (admin_toolbar_links_access_filter_is_overview_page($route)) {
|
||||
unset($items[$route]);
|
||||
}
|
||||
else {
|
||||
// Let's remove the expanded flag.
|
||||
$items[$route]['is_expanded'] = FALSE;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements template_preprocess_admin_block_content().
|
||||
*/
|
||||
function admin_toolbar_links_access_filter_admin_block_content(&$variables) {
|
||||
if (!admin_toolbar_links_access_filter_user_has_admin_role($variables['user'])) {
|
||||
foreach ($variables['content'] as $key => &$item) {
|
||||
if (isset($item['url']) && $item['url'] instanceof Url) {
|
||||
/* @var \Drupal\Core\Url $url */
|
||||
$url = $item['url'];
|
||||
if ($url->access()) {
|
||||
continue;
|
||||
}
|
||||
unset($variables['content'][$key]);
|
||||
}
|
||||
|
||||
// The key is structured in the form: "ID title route",
|
||||
// concatenated with spaces.
|
||||
$key_parts = explode(' ', $key);
|
||||
$route = end($key_parts);
|
||||
|
||||
// Special handling for Views pages, as they are not defined
|
||||
// system routes.
|
||||
// @TODO check the permission for Views + find a generic way for similar
|
||||
// cases. Best way would be to get the link entity somehow to properly
|
||||
// check permissions.
|
||||
if (strpos($route, 'views_view:') === 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Check, if user has access rights to the route.
|
||||
if (!\Drupal::accessManager()->checkNamedRoute($route)) {
|
||||
unset($variables['content'][$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the given route name is an overview page.
|
||||
*
|
||||
* Checks if the given route name matches a pure (admin) overview page that can
|
||||
* be skipped, if there are no child items set. The typical example are routes
|
||||
* having the SystemController::systemAdminMenuBlockPage() function as their
|
||||
* controller callback set.
|
||||
*
|
||||
* @param string $route_name
|
||||
* The route name to check.
|
||||
*
|
||||
* @return bool
|
||||
* TRUE, if the given route name matches a pure admin overview page route,
|
||||
* FALSE otherwise.
|
||||
*/
|
||||
function admin_toolbar_links_access_filter_is_overview_page($route_name) {
|
||||
// @var \Drupal\Core\Routing\RouteProviderInterface $route_provider.
|
||||
$route_provider = \Drupal::service('router.route_provider');
|
||||
$overview_page_controllers = [
|
||||
'\Drupal\system\Controller\AdminController::index',
|
||||
'\Drupal\system\Controller\SystemController::overview',
|
||||
'\Drupal\system\Controller\SystemController::systemAdminMenuBlockPage',
|
||||
];
|
||||
try {
|
||||
$route = $route_provider->getRouteByName($route_name);
|
||||
$controller = $route->getDefault('_controller');
|
||||
return !empty($controller) && in_array($controller, $overview_page_controllers);
|
||||
}
|
||||
catch (RouteNotFoundException $ex) {
|
||||
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks, if the given user has admin rights.
|
||||
*
|
||||
* @param \Drupal\Core\Session\AccountInterface $account
|
||||
* The account to check.
|
||||
*
|
||||
* @return bool
|
||||
* TRUE, if the given user account has at least one role with admin rights
|
||||
* assigned, FALSE otherwise.
|
||||
*/
|
||||
function admin_toolbar_links_access_filter_user_has_admin_role(AccountInterface $account) {
|
||||
static $user_has_admin_role = [];
|
||||
$uid = $account->id();
|
||||
if (!isset($user_has_admin_role[$uid])) {
|
||||
$roles = Role::loadMultiple($account->getRoles());
|
||||
foreach ($roles as $role) {
|
||||
if ($role->isAdmin()) {
|
||||
$user_has_admin_role[$uid] = TRUE;
|
||||
break;
|
||||
}
|
||||
$user_has_admin_role[$uid] = FALSE;
|
||||
}
|
||||
}
|
||||
return $user_has_admin_role[$uid];
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
{
|
||||
"name": "drupal/admin_toolbar_links_access_filter",
|
||||
"description": "Provides a workaround for the common problem that users with 'Use the administration pages and help' permission see menu links they don't have access permission for. Once the issue https://www.drupal.org/node/296693 be solved, this module will be deprecated.",
|
||||
"type": "drupal-module",
|
||||
"keywords": ["Drupal", "Toolbar"],
|
||||
"homepage": "http://drupal.org/project/admin_toolbar",
|
||||
"license": "GPL-2.0+",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Wilfrid Roze (eme)",
|
||||
"homepage": "https://www.drupal.org/u/eme",
|
||||
"role": "Maintainer"
|
||||
},
|
||||
{
|
||||
"name": "Romain Jarraud (romainj)",
|
||||
"homepage": "https://www.drupal.org/u/romainj",
|
||||
"role": "Maintainer"
|
||||
},
|
||||
{
|
||||
"name": "Adrian Cid Almaguer (adriancid)",
|
||||
"email": "adriancid@gmail.com",
|
||||
"homepage": "https://www.drupal.org/u/adriancid",
|
||||
"role": "Maintainer"
|
||||
},
|
||||
{
|
||||
"name": "Mohamed Anis Taktak (matio89)",
|
||||
"homepage": "https://www.drupal.org/u/matio89",
|
||||
"role": "Maintainer"
|
||||
}
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://www.drupal.org/project/issues/admin_toolbar",
|
||||
"source": "http://cgit.drupalcode.org/admin_toolbar"
|
||||
},
|
||||
"require": {
|
||||
"drupal/admin_toolbar": "^1"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,62 @@
|
|||
CONTENTS OF THIS FILE
|
||||
---------------------
|
||||
|
||||
* Introduction
|
||||
* Requirements
|
||||
* Recommended modules
|
||||
* Installation
|
||||
* Configuration
|
||||
* Maintainers
|
||||
|
||||
|
||||
INTRODUCTION
|
||||
------------
|
||||
|
||||
Admin Toolbar Extra Tools provides menu links to administration pages or actions
|
||||
(eg. Flushing caches) that are not generated by Drupal core. It adds menu items
|
||||
that are not generated by Drupal core. For example there are no menu items for
|
||||
each content type by default or menu links to Manage fields on each entity
|
||||
types. That's the purpose of Admin Toolbar Extra Tools to add them.
|
||||
|
||||
* For a full description of the module, visit the project page:
|
||||
https://www.drupal.org/project/admin_toolbar
|
||||
|
||||
* To submit bug reports and feature suggestions, or to track changes:
|
||||
https://www.drupal.org/project/issues/search/admin_toolbar
|
||||
|
||||
|
||||
REQUIREMENTS
|
||||
------------
|
||||
|
||||
This module requires the following modules:
|
||||
|
||||
* Admin Toolbar (https://www.drupal.org/project/admin_toolbar)
|
||||
|
||||
|
||||
INSTALLATION
|
||||
------------
|
||||
|
||||
* Install as you would normally install a contributed Drupal module.
|
||||
See: https://www.drupal.org/node/895232 for further information.
|
||||
|
||||
|
||||
CONFIGURATION
|
||||
-------------
|
||||
|
||||
No configuration is needed.
|
||||
|
||||
|
||||
MAINTAINERS
|
||||
-----------
|
||||
|
||||
Current maintainers:
|
||||
* Wilfrid Roze (eme) - https://www.drupal.org/u/eme
|
||||
* Romain Jarraud (romainj) - https://www.drupal.org/u/romainj
|
||||
* Adrian Cid Almaguer (adriancid) - https://www.drupal.org/u/adriancid
|
||||
* Mohamed Anis Taktak (matio89) - https://www.drupal.org/u/matio89
|
||||
|
||||
This project has been sponsored by:
|
||||
* emerya
|
||||
Founded in 2009, emerya is a human-sized company, dedicated to the design and
|
||||
implementation of web interfaces. Visit: http://http://emerya.fr/ for more
|
||||
information.
|
|
@ -0,0 +1,16 @@
|
|||
name: Admin Toolbar Extra Tools
|
||||
description: Adds menu links to the Admin Toolbar.
|
||||
package: Administration
|
||||
|
||||
type: module
|
||||
# core: 8.x
|
||||
|
||||
dependencies:
|
||||
- admin_toolbar:admin_toolbar
|
||||
- drupal:system (>=8.5)
|
||||
|
||||
# Information added by Drupal.org packaging script on 2018-11-22
|
||||
version: '8.x-1.25'
|
||||
core: '8.x'
|
||||
project: 'admin_toolbar'
|
||||
datestamp: 1542915184
|
|
@ -0,0 +1,4 @@
|
|||
toolbar.icon:
|
||||
css:
|
||||
theme:
|
||||
css/tools.css: {}
|
|
@ -0,0 +1,76 @@
|
|||
admin_toolbar_tools.help:
|
||||
title: 'Tools'
|
||||
route_name: <front>
|
||||
menu_name: admin
|
||||
parent: system.admin
|
||||
weight: -100
|
||||
|
||||
system.admin_index:
|
||||
title: 'Index'
|
||||
route_name: system.admin_index
|
||||
menu_name: admin
|
||||
parent: admin_toolbar_tools.help
|
||||
weight: -100
|
||||
|
||||
system.run_cron:
|
||||
title: 'Run cron'
|
||||
route_name: admin_toolbar.run.cron
|
||||
menu_name: admin
|
||||
parent: admin_toolbar_tools.help
|
||||
weight: -8
|
||||
|
||||
system.db_update:
|
||||
title: 'Run updates'
|
||||
route_name: system.db_update
|
||||
menu_name: admin
|
||||
parent: admin_toolbar_tools.help
|
||||
weight: -6
|
||||
|
||||
system.modules_uninstall:
|
||||
title: 'Uninstall module'
|
||||
route_name: system.modules_uninstall
|
||||
menu_name: admin
|
||||
parent: system.modules_list
|
||||
|
||||
admin_toolbar_tools.flush:
|
||||
title: 'Flush all caches'
|
||||
route_name: admin_toolbar_tools.flush
|
||||
weight: -9
|
||||
parent: admin_toolbar_tools.help
|
||||
menu_name: admin
|
||||
|
||||
admin_toolbar_tools.cssjs:
|
||||
title: 'Flush CSS and Javascript'
|
||||
route_name: admin_toolbar_tools.cssjs
|
||||
parent: admin_toolbar_tools.flush
|
||||
menu_name: admin
|
||||
|
||||
admin_toolbar_tools.plugin:
|
||||
title: 'Flush plugins cache'
|
||||
route_name: admin_toolbar_tools.plugin
|
||||
parent: admin_toolbar_tools.flush
|
||||
menu_name: admin
|
||||
|
||||
admin_toolbar_tools.flush_static:
|
||||
title: 'Flush static cache'
|
||||
route_name: admin_toolbar_tools.flush_static
|
||||
parent: admin_toolbar_tools.flush
|
||||
menu_name: admin
|
||||
|
||||
admin_toolbar_tools.flush_menu:
|
||||
title: 'Flush routing and links cache'
|
||||
route_name: admin_toolbar_tools.flush_menu
|
||||
parent: admin_toolbar_tools.flush
|
||||
menu_name: admin
|
||||
|
||||
admin_toolbar_tools.flush_twig:
|
||||
title: 'Flush twig cache'
|
||||
route_name: admin_toolbar_tools.flush_twig
|
||||
parent: admin_toolbar_tools.flush
|
||||
menu_name: admin
|
||||
|
||||
admin_toolbar_tools.flush_rendercache:
|
||||
title: 'Flush render cache'
|
||||
route_name: admin_toolbar_tools.flush_rendercache
|
||||
parent: admin_toolbar_tools.flush
|
||||
menu_name: admin
|
|
@ -0,0 +1,677 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Provides extra menu links for the core drupal toolbar.
|
||||
*/
|
||||
|
||||
use Drupal\Core\Routing\RouteMatchInterface;
|
||||
use Drupal\Core\Url;
|
||||
|
||||
/**
|
||||
* Implements hook_toolbar().
|
||||
*/
|
||||
function admin_toolbar_tools_toolbar() {
|
||||
$items = [];
|
||||
$items['admin_toolbar_tools'] = [
|
||||
'#type' => 'toolbar_item',
|
||||
'tab' => [
|
||||
'#type' => 'link',
|
||||
'#attributes' => [
|
||||
'class' => ['toolbar-icon', 'toolbar-icon-admin-toolbar-tools-help'],
|
||||
],
|
||||
],
|
||||
'#attached' => ['library' => ['admin_toolbar_tools/toolbar.icon']],
|
||||
];
|
||||
|
||||
return $items;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_help().
|
||||
*/
|
||||
function admin_toolbar_tools_help($route_name, RouteMatchInterface $route_match) {
|
||||
switch ($route_name) {
|
||||
case 'help.page.admin_toolbar_tools':
|
||||
$output = '';
|
||||
$output .= '<p>';
|
||||
$output .= t('The Admin Toolbar Extra Tools module comes packaged with the <a href=":admin-toolbar">Admin Toolbar</a> module and adds functionality to it. The additional functionality is accessed thru extra links on the main administration Toolbar. Some links to Admin Toolbar Extra Tools administration pages are located at the bottom of this page.</a>', [':admin-toolbar' => Url::fromRoute('help.page', ['name' => 'admin_toolbar'])->toString()]);
|
||||
$output .= '</p>';
|
||||
$output .= '<h3>' . t('Uses') . '</h3>';
|
||||
$output .= '<p>' . t('To use Admin Toolbar Extra Tools just install it like any other module. There is no other configuration required.') . '</p>';
|
||||
|
||||
return $output;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_menu_links_discovered_alter().
|
||||
*/
|
||||
function admin_toolbar_tools_menu_links_discovered_alter(&$links) {
|
||||
$moduleHandler = \Drupal::moduleHandler();
|
||||
$entityTypeManager = \Drupal::entityTypeManager();
|
||||
$routeProvider = \Drupal::service('router.route_provider');
|
||||
$routes = [];
|
||||
foreach ($routeProvider->getAllRoutes() as $route_name => $route) {
|
||||
$routes[] = $route_name;
|
||||
}
|
||||
|
||||
$entityTypes = $entityTypeManager->getDefinitions();
|
||||
$content_entities = [];
|
||||
foreach ($entityTypes as $key => $entityType) {
|
||||
if ($entityType->getBundleEntityType() && ($entityType->get('field_ui_base_route') != '')) {
|
||||
$content_entities[$key] = [
|
||||
'content_entity' => $key,
|
||||
'content_entity_bundle' => $entityType->getBundleEntityType(),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
// Adding a menu link to clean the Views cache.
|
||||
if ($moduleHandler->moduleExists('views')) {
|
||||
$links['admin_toolbar_tools.flush_views'] = [
|
||||
'title' => t('Flush views cache'),
|
||||
'provider' => 'admin_toolbar_tools',
|
||||
'route_name' => 'admin_toolbar_tools.flush_views',
|
||||
'menu_name' => 'admin',
|
||||
'parent' => 'admin_toolbar_tools.flush',
|
||||
];
|
||||
// Adding a menu link to Files.
|
||||
if ($moduleHandler->moduleExists('file') && in_array('view.files.page_1', $routes)) {
|
||||
$links['admin_toolbar_tools.view.files'] = [
|
||||
'title' => t('Files'),
|
||||
'provider' => 'admin_toolbar_tools',
|
||||
'route_name' => 'view.files.page_1',
|
||||
'menu_name' => 'admin',
|
||||
'parent' => 'system.admin_content',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
// Adds common links to entities.
|
||||
foreach ($content_entities as $entities) {
|
||||
$content_entity_bundle = $entities['content_entity_bundle'];
|
||||
$content_entity = $entities['content_entity'];
|
||||
foreach ($entityTypeManager->getStorage($content_entity_bundle)->loadMultiple() as $machine_name => $bundle) {
|
||||
// Normally, the edit form for the bundle would be its root link.
|
||||
$content_entity_bundle_root = NULL;
|
||||
if (in_array('entity.' . $content_entity_bundle . '.overview_form', $routes)) {
|
||||
// Some bundles have an overview/list form that make a better root link.
|
||||
$content_entity_bundle_root = 'entity.' . $content_entity_bundle . '.overview_form.' . $machine_name;
|
||||
$links[$content_entity_bundle_root] = [
|
||||
'title' => t($bundle->label()),
|
||||
'provider' => 'admin_toolbar_tools',
|
||||
'route_name' => 'entity.' . $content_entity_bundle . '.overview_form',
|
||||
'menu_name' => 'admin',
|
||||
'parent' => 'entity.' . $content_entity_bundle . '.collection',
|
||||
'route_parameters' => [$content_entity_bundle => $machine_name],
|
||||
];
|
||||
}
|
||||
if (in_array('entity.' . $content_entity_bundle . '.edit_form', $routes)) {
|
||||
$key = 'entity.' . $content_entity_bundle . '.edit_form.' . $machine_name;
|
||||
$links[$key] = [
|
||||
'title' => t($bundle->label()),
|
||||
'provider' => 'admin_toolbar_tools',
|
||||
'route_name' => 'entity.' . $content_entity_bundle . '.edit_form',
|
||||
'menu_name' => 'admin',
|
||||
'parent' => 'entity.' . $content_entity_bundle . '.collection',
|
||||
'route_parameters' => [$content_entity_bundle => $machine_name],
|
||||
];
|
||||
if (empty($content_entity_bundle_root)) {
|
||||
$content_entity_bundle_root = $key;
|
||||
}
|
||||
else {
|
||||
$links[$key]['parent'] = $content_entity_bundle_root;
|
||||
$links[$key]['title'] = t('Edit');
|
||||
}
|
||||
}
|
||||
if ($moduleHandler->moduleExists('field_ui')) {
|
||||
if (in_array('entity.' . $content_entity . '.field_ui_fields', $routes)) {
|
||||
$links['entity.' . $content_entity . '.field_ui_fields' . $machine_name] = [
|
||||
'title' => t('Manage fields'),
|
||||
'provider' => 'admin_toolbar_tools',
|
||||
'route_name' => 'entity.' . $content_entity . '.field_ui_fields',
|
||||
'menu_name' => 'admin',
|
||||
'parent' => $content_entity_bundle_root,
|
||||
'route_parameters' => [$content_entity_bundle => $machine_name],
|
||||
'weight' => 1,
|
||||
];
|
||||
}
|
||||
if (in_array('entity.entity_form_display.' . $content_entity . '.default', $routes)) {
|
||||
$links['entity.entity_form_display.' . $content_entity . '.default' . $machine_name] = [
|
||||
'title' => t('Manage form display'),
|
||||
'provider' => 'admin_toolbar_tools',
|
||||
'route_name' => 'entity.entity_form_display.' . $content_entity . '.default',
|
||||
'menu_name' => 'admin',
|
||||
'parent' => $content_entity_bundle_root,
|
||||
'route_parameters' => [$content_entity_bundle => $machine_name],
|
||||
'weight' => 2,
|
||||
];
|
||||
}
|
||||
if (in_array('entity.entity_view_display.' . $content_entity . '.default', $routes)) {
|
||||
$links['entity.entity_view_display.' . $content_entity . '.default.' . $machine_name] = [
|
||||
'title' => t('Manage display'),
|
||||
'provider' => 'admin_toolbar_tools',
|
||||
'route_name' => 'entity.entity_view_display.' . $content_entity . '.default',
|
||||
'menu_name' => 'admin',
|
||||
'parent' => $content_entity_bundle_root,
|
||||
'route_parameters' => [$content_entity_bundle => $machine_name],
|
||||
'weight' => 3,
|
||||
];
|
||||
}
|
||||
}
|
||||
if ($moduleHandler->moduleExists('devel') && in_array('entity.' . $content_entity_bundle . '.devel_load', $routes)) {
|
||||
$links['entity.' . $content_entity_bundle . '.devel_load.' . $machine_name] = [
|
||||
'title' => t('Devel'),
|
||||
'provider' => 'admin_toolbar_tools',
|
||||
'route_name' => 'entity.' . $content_entity_bundle . '.devel_load',
|
||||
'menu_name' => 'admin',
|
||||
'parent' => $content_entity_bundle_root,
|
||||
'route_parameters' => [$content_entity_bundle => $machine_name],
|
||||
'weight' => 4,
|
||||
];
|
||||
}
|
||||
if (in_array('entity.' . $content_entity_bundle . '.delete_form', $routes)) {
|
||||
$links['entity.' . $content_entity_bundle . '.delete_form.' . $machine_name] = [
|
||||
'title' => t('Delete'),
|
||||
'provider' => 'admin_toolbar_tools',
|
||||
'route_name' => 'entity.' . $content_entity_bundle . '.delete_form',
|
||||
'menu_name' => 'admin',
|
||||
'parent' => $content_entity_bundle_root,
|
||||
'route_parameters' => [$content_entity_bundle => $machine_name],
|
||||
'weight' => 5,
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Add user links.
|
||||
$links['user.admin_create'] = [
|
||||
'title' => t('Add a new user'),
|
||||
'provider' => 'admin_toolbar_tools',
|
||||
'route_name' => 'user.admin_create',
|
||||
'menu_name' => 'admin',
|
||||
'parent' => 'entity.user.collection',
|
||||
];
|
||||
$links['user.admin_permissions'] = [
|
||||
'title' => t('Permissions'),
|
||||
'provider' => 'admin_toolbar_tools',
|
||||
'route_name' => 'user.admin_permissions',
|
||||
'menu_name' => 'admin',
|
||||
'parent' => 'entity.user.collection',
|
||||
];
|
||||
$links['entity.user_role.collection'] = [
|
||||
'title' => t('Roles'),
|
||||
'provider' => 'admin_toolbar_tools',
|
||||
'route_name' => 'entity.user_role.collection',
|
||||
'menu_name' => 'admin',
|
||||
'parent' => 'entity.user.collection',
|
||||
];
|
||||
$links['admin_toolbar_tools.user.logout'] = [
|
||||
'title' => t('Logout'),
|
||||
'provider' => 'admin_toolbar_tools',
|
||||
'route_name' => 'user.logout',
|
||||
'parent' => 'admin_toolbar_tools.help',
|
||||
'weight' => 10,
|
||||
];
|
||||
$links['user.role_add'] = [
|
||||
'title' => t('Add a new role'),
|
||||
'provider' => 'admin_toolbar_tools',
|
||||
'route_name' => 'user.role_add',
|
||||
'menu_name' => 'admin',
|
||||
'parent' => 'entity.user_role.collection',
|
||||
'weight' => -5,
|
||||
];
|
||||
if ($moduleHandler->moduleExists('field_ui')) {
|
||||
$links['entity.user.field_ui_fields_'] = [
|
||||
'title' => t('Manage fields'),
|
||||
'provider' => 'admin_toolbar_tools',
|
||||
'route_name' => 'entity.user.field_ui_fields',
|
||||
'menu_name' => 'admin',
|
||||
'parent' => 'entity.user.admin_form',
|
||||
];
|
||||
$links['entity.entity_form_display.user.default_'] = [
|
||||
'title' => t('Manage form display'),
|
||||
'provider' => 'admin_toolbar_tools',
|
||||
'route_name' => 'entity.entity_form_display.user.default',
|
||||
'menu_name' => 'admin',
|
||||
'parent' => 'entity.user.admin_form',
|
||||
];
|
||||
$links['entity.entity_view_display.user.default_'] = [
|
||||
'title' => t('Manage display'),
|
||||
'provider' => 'admin_toolbar_tools',
|
||||
'route_name' => 'entity.entity_view_display.user.default',
|
||||
'menu_name' => 'admin',
|
||||
'parent' => 'entity.user.admin_form',
|
||||
];
|
||||
}
|
||||
foreach (user_roles() as $role) {
|
||||
$links['entity.user_role.edit_form.' . $role->id()] = [
|
||||
'title' => t($role->label()),
|
||||
'provider' => 'admin_toolbar_tools',
|
||||
'route_name' => 'entity.user_role.edit_form',
|
||||
'menu_name' => 'admin',
|
||||
'parent' => 'entity.user_role.collection',
|
||||
'route_parameters' => ['user_role' => $role->id()],
|
||||
];
|
||||
$links['entity.user_role.edit_permissions_form.' . $role->id()] = [
|
||||
'title' => t('Edit permissions'),
|
||||
'provider' => 'admin_toolbar_tools',
|
||||
'route_name' => 'entity.user_role.edit_permissions_form',
|
||||
'menu_name' => 'admin',
|
||||
'parent' => 'entity.user_role.edit_form.' . $role->id(),
|
||||
'route_parameters' => ['user_role' => $role->id()],
|
||||
];
|
||||
$links['entity.user_role.delete_form.' . $role->id()] = [
|
||||
'title' => t('Delete'),
|
||||
'provider' => 'admin_toolbar_tools',
|
||||
'route_name' => 'entity.user_role.delete_form',
|
||||
'menu_name' => 'admin',
|
||||
'parent' => 'entity.user_role.edit_form.' . $role->id(),
|
||||
'route_parameters' => ['user_role' => $role->id()],
|
||||
];
|
||||
if ($moduleHandler->moduleExists('devel')) {
|
||||
$links['entity.user_role.devel_load.' . $role->id()] = [
|
||||
'title' => t('Devel'),
|
||||
'provider' => 'admin_toolbar_tools',
|
||||
'route_name' => 'entity.user_role.devel_load',
|
||||
'menu_name' => 'admin',
|
||||
'parent' => 'entity.user_role.edit_form.' . $role->id(),
|
||||
'route_parameters' => ['user_role' => $role->id()],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
if ($moduleHandler->moduleExists('node')) {
|
||||
$links['admin_toolbar_tools.add_content'] = $links['node.add_page'];
|
||||
$links['admin_toolbar_tools.add_content']['parent'] = 'system.admin_content';
|
||||
$links['node.type_add'] = [
|
||||
'title' => t('Add content type'),
|
||||
'provider' => 'admin_toolbar_tools',
|
||||
'route_name' => 'node.type_add',
|
||||
'menu_name' => 'admin',
|
||||
'parent' => 'entity.node_type.collection',
|
||||
'weight' => -5,
|
||||
];
|
||||
// Add node links for each content type.
|
||||
foreach ($entityTypeManager->getStorage('node_type')->loadMultiple() as $type) {
|
||||
$links['node.add.' . $type->id()] = [
|
||||
'title' => t($type->label()),
|
||||
'provider' => 'admin_toolbar_tools',
|
||||
'route_name' => 'node.add',
|
||||
'parent' => 'admin_toolbar_tools.add_content',
|
||||
'route_parameters' => ['node_type' => $type->id()],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
if ($moduleHandler->moduleExists('field_ui')) {
|
||||
$links['field_ui.entity_form_mode_add'] = [
|
||||
'title' => t('Add new form mode'),
|
||||
'provider' => 'admin_toolbar_tools',
|
||||
'route_name' => 'field_ui.entity_form_mode_add',
|
||||
'menu_name' => 'admin',
|
||||
'parent' => 'entity.entity_form_mode.collection',
|
||||
];
|
||||
$links['field_ui.entity_view_mode_add'] = [
|
||||
'title' => t('Add new view mode'),
|
||||
'provider' => 'admin_toolbar_tools',
|
||||
'route_name' => 'field_ui.entity_view_mode_add',
|
||||
'menu_name' => 'admin',
|
||||
'parent' => 'entity.entity_view_mode.collection',
|
||||
];
|
||||
}
|
||||
|
||||
if ($moduleHandler->moduleExists('taxonomy')) {
|
||||
$links['entity.taxonomy_vocabulary.add_form'] = [
|
||||
'title' => t('Add vocabulary'),
|
||||
'provider' => 'admin_toolbar_tools',
|
||||
'route_name' => 'entity.taxonomy_vocabulary.add_form',
|
||||
'menu_name' => 'admin',
|
||||
'parent' => 'entity.taxonomy_vocabulary.collection',
|
||||
'weight' => -5,
|
||||
];
|
||||
}
|
||||
|
||||
if ($moduleHandler->moduleExists('menu_ui')) {
|
||||
$links['entity.menu.add_form'] = [
|
||||
'title' => t('Add menu'),
|
||||
'provider' => 'admin_toolbar_tools',
|
||||
'route_name' => 'entity.menu.add_form',
|
||||
'menu_name' => 'admin',
|
||||
'parent' => 'entity.menu.collection',
|
||||
'weight' => -50,
|
||||
];
|
||||
// Adds links to /admin/structure/menu.
|
||||
foreach (menu_ui_get_menus() as $machine_name => $label) {
|
||||
$links['entity.menu.edit_form.' . $machine_name] = [
|
||||
'title' => t($label),
|
||||
'provider' => 'admin_toolbar_tools',
|
||||
'route_name' => 'entity.menu.edit_form',
|
||||
'menu_name' => 'admin',
|
||||
'parent' => 'entity.menu.collection',
|
||||
'route_parameters' => ['menu' => $machine_name],
|
||||
];
|
||||
$links['entity.menu.delete_form.' . $machine_name] = [
|
||||
'title' => t('Delete'),
|
||||
'provider' => 'admin_toolbar_tools',
|
||||
'route_name' => 'entity.menu.delete_form',
|
||||
'menu_name' => 'admin',
|
||||
'parent' => 'entity.menu.edit_form.' . $machine_name,
|
||||
'route_parameters' => ['menu' => $machine_name],
|
||||
];
|
||||
if ($moduleHandler->moduleExists('devel')) {
|
||||
$links['entity.menu.devel_load.' . $machine_name] = [
|
||||
'title' => t('Devel'),
|
||||
'provider' => 'admin_toolbar_tools',
|
||||
'route_name' => 'entity.menu.devel_load',
|
||||
'menu_name' => 'admin',
|
||||
'parent' => 'entity.menu.edit_form.' . $machine_name,
|
||||
'route_parameters' => ['menu' => $machine_name],
|
||||
];
|
||||
}
|
||||
$links['entity.menu.add_link_form.' . $machine_name] = [
|
||||
'title' => t('Add link'),
|
||||
'provider' => 'admin_toolbar_tools',
|
||||
'route_name' => 'entity.menu.add_link_form',
|
||||
'menu_name' => 'admin',
|
||||
'parent' => 'entity.menu.edit_form.' . $machine_name,
|
||||
'route_parameters' => ['menu' => $machine_name],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
// If module block_content is enabled.
|
||||
if ($moduleHandler->moduleExists('block_content')) {
|
||||
$links['block_content.add_page'] = [
|
||||
'title' => t('Add custom block'),
|
||||
'provider' => 'admin_toolbar_tools',
|
||||
'route_name' => 'block_content.add_page',
|
||||
'menu_name' => 'admin',
|
||||
'parent' => 'block.admin_display',
|
||||
'weight' => -100,
|
||||
];
|
||||
$links['entity.block_content.collection'] = [
|
||||
'title' => t('Custom block library'),
|
||||
'provider' => 'admin_toolbar_tools',
|
||||
'route_name' => 'entity.block_content.collection',
|
||||
'menu_name' => 'admin',
|
||||
'parent' => 'block.admin_display',
|
||||
];
|
||||
$links['entity.block_content_type.collection'] = [
|
||||
'title' => t('Types'),
|
||||
'provider' => 'admin_toolbar_tools',
|
||||
'route_name' => 'entity.block_content_type.collection',
|
||||
'menu_name' => 'admin',
|
||||
'parent' => 'block.admin_display',
|
||||
];
|
||||
}
|
||||
|
||||
// If module Contact is enabled.
|
||||
if ($moduleHandler->moduleExists('contact')) {
|
||||
$links['contact.form_add'] = [
|
||||
'title' => t('Add contact form'),
|
||||
'provider' => 'admin_toolbar_tools',
|
||||
'route_name' => 'contact.form_add',
|
||||
'menu_name' => 'admin',
|
||||
'parent' => 'entity.contact_form.collection',
|
||||
'weight' => -5,
|
||||
];
|
||||
}
|
||||
|
||||
// If module Update Manager is enabled.
|
||||
if ($moduleHandler->moduleExists('update')) {
|
||||
$links['update.module_update'] = [
|
||||
'title' => t('Update'),
|
||||
'provider' => 'admin_toolbar_tools',
|
||||
'route_name' => 'update.module_update',
|
||||
'menu_name' => 'admin',
|
||||
'parent' => 'system.modules_list',
|
||||
];
|
||||
$links['update.module_install'] = [
|
||||
'title' => t('Install new module'),
|
||||
'provider' => 'admin_toolbar_tools',
|
||||
'route_name' => 'update.module_install',
|
||||
'menu_name' => 'admin',
|
||||
'parent' => 'system.modules_list',
|
||||
];
|
||||
}
|
||||
|
||||
// If module Devel is enabled.
|
||||
if ($moduleHandler->moduleExists('devel')) {
|
||||
$links['admin_development'] = [
|
||||
'title' => t('Development'),
|
||||
'provider' => 'admin_toolbar_tools',
|
||||
'route_name' => 'system.admin_config_development',
|
||||
'menu_name' => 'admin',
|
||||
'parent' => 'admin_toolbar_tools.help',
|
||||
'weight' => '-8',
|
||||
];
|
||||
$links['admin_toolbar_tools.devel.admin_settings'] = [
|
||||
'title' => t('Devel settings'),
|
||||
'provider' => 'admin_toolbar_tools',
|
||||
'route_name' => 'devel.admin_settings',
|
||||
'menu_name' => 'admin',
|
||||
'parent' => 'admin_development',
|
||||
'weight' => '-1',
|
||||
];
|
||||
if ($moduleHandler->moduleExists('webprofiler')) {
|
||||
$links['admin_toolbar_tools.devel.webprofiler'] = [
|
||||
'title' => t('Web Profiler settings'),
|
||||
'provider' => 'admin_toolbar_tools',
|
||||
'route_name' => 'webprofiler.settings',
|
||||
'menu_name' => 'admin',
|
||||
'parent' => 'admin_development',
|
||||
];
|
||||
}
|
||||
$links['admin_toolbar_tools.devel.configs_list'] = [
|
||||
'title' => t('Config editor'),
|
||||
'provider' => 'admin_toolbar_tools',
|
||||
'route_name' => 'devel.configs_list',
|
||||
'menu_name' => 'admin',
|
||||
'parent' => 'admin_development',
|
||||
];
|
||||
$links['admin_toolbar_tools.devel.reinstall'] = [
|
||||
'title' => t('Reinstall modules'),
|
||||
'provider' => 'admin_toolbar_tools',
|
||||
'route_name' => 'devel.reinstall',
|
||||
'parent' => 'admin_development',
|
||||
];
|
||||
$links['admin_toolbar_tools.devel.menu_rebuild'] = [
|
||||
'title' => t('Rebuild menu'),
|
||||
'provider' => 'admin_toolbar_tools',
|
||||
'route_name' => 'devel.menu_rebuild',
|
||||
'menu_name' => 'admin',
|
||||
'parent' => 'admin_development',
|
||||
];
|
||||
$links['admin_toolbar_tools.devel.state_system_page'] = [
|
||||
'title' => t('State editor'),
|
||||
'provider' => 'admin_toolbar_tools',
|
||||
'route_name' => 'devel.state_system_page',
|
||||
'menu_name' => 'admin',
|
||||
'parent' => 'admin_development',
|
||||
];
|
||||
$links['admin_toolbar_tools.devel.theme_registry'] = [
|
||||
'title' => t('Theme registry'),
|
||||
'provider' => 'admin_toolbar_tools',
|
||||
'route_name' => 'devel.theme_registry',
|
||||
'menu_name' => 'admin',
|
||||
'parent' => 'admin_development',
|
||||
];
|
||||
$links['admin_toolbar_tools.devel.entity_info_page'] = [
|
||||
'title' => t('Entity Info'),
|
||||
'provider' => 'admin_toolbar_tools',
|
||||
'route_name' => 'devel.entity_info_page',
|
||||
'menu_name' => 'admin',
|
||||
'parent' => 'admin_development',
|
||||
];
|
||||
$links['admin_toolbar_tools.devel.execute_php'] = [
|
||||
'title' => t('Execute PHP Code'),
|
||||
'provider' => 'admin_toolbar_tools',
|
||||
'route_name' => 'devel.execute_php',
|
||||
'menu_name' => 'admin',
|
||||
'parent' => 'admin_development',
|
||||
];
|
||||
$links['admin_toolbar_tools.devel.session'] = [
|
||||
'title' => t('Session viewer'),
|
||||
'provider' => 'admin_toolbar_tools',
|
||||
'route_name' => 'devel.session',
|
||||
'menu_name' => 'admin',
|
||||
'parent' => 'admin_development',
|
||||
];
|
||||
$links['admin_toolbar_tools.devel.elements_page'] = [
|
||||
'title' => t('Form API field types'),
|
||||
'provider' => 'admin_toolbar_tools',
|
||||
'route_name' => 'devel.elements_page',
|
||||
'menu_name' => 'admin',
|
||||
'parent' => 'admin_development',
|
||||
];
|
||||
// Menu link for the Toolbar module.
|
||||
$links['admin_toolbar_tools.toolbar.settings'] = [
|
||||
'title' => t('Toolbar settings'),
|
||||
'provider' => 'admin_toolbar_tools',
|
||||
'route_name' => 'devel.toolbar.settings_form',
|
||||
'menu_name' => 'admin',
|
||||
'parent' => 'devel.admin_settings',
|
||||
];
|
||||
}
|
||||
|
||||
// If module Views Ui enabled.
|
||||
if ($moduleHandler->moduleExists('views_ui')) {
|
||||
$links['admin_toolbar_tools.views_ui.add'] = [
|
||||
'title' => t('Add new view'),
|
||||
'provider' => 'admin_toolbar_tools',
|
||||
'route_name' => 'views_ui.add',
|
||||
'menu_name' => 'admin',
|
||||
'parent' => 'entity.view.collection',
|
||||
'weight' => -5,
|
||||
];
|
||||
$links['admin_toolbar_tools.views_ui.field_list'] = [
|
||||
'title' => t('Used in views'),
|
||||
'provider' => 'admin_toolbar_tools',
|
||||
'route_name' => 'views_ui.reports_fields',
|
||||
'menu_name' => 'admin',
|
||||
'parent' => 'entity.field_storage_config.collection',
|
||||
];
|
||||
}
|
||||
|
||||
$links['admin_toolbar_tools.system.theme_settings'] = [
|
||||
'title' => t('Settings'),
|
||||
'provider' => 'admin_toolbar_tools',
|
||||
'route_name' => 'system.theme_settings',
|
||||
'menu_name' => 'admin',
|
||||
'parent' => 'system.themes_page',
|
||||
];
|
||||
|
||||
if ($moduleHandler->moduleExists('webprofiler')) {
|
||||
$links['admin_toolbar_tools.devel.webprofiler'] = [
|
||||
'title' => t('Webprofiler settings'),
|
||||
'provider' => 'admin_toolbar_tools',
|
||||
'route_name' => 'webprofiler.settings',
|
||||
'menu_name' => 'admin',
|
||||
'parent' => 'admin_development',
|
||||
];
|
||||
}
|
||||
|
||||
if ($moduleHandler->moduleExists('update')) {
|
||||
$links['update.theme_install_'] = [
|
||||
'title' => t('Install new theme'),
|
||||
'provider' => 'admin_toolbar_tools',
|
||||
'route_name' => 'update.theme_install',
|
||||
'menu_name' => 'admin',
|
||||
'parent' => 'system.themes_page',
|
||||
];
|
||||
$links['update.theme_update_'] = [
|
||||
'title' => t('Update'),
|
||||
'provider' => 'admin_toolbar_tools',
|
||||
'route_name' => 'update.theme_update',
|
||||
'menu_name' => 'admin',
|
||||
'parent' => 'system.themes_page',
|
||||
];
|
||||
// Lists installed themes.
|
||||
$installed_themes = admin_toolbar_tools_installed_themes();
|
||||
foreach ($installed_themes as $key_theme => $label_theme) {
|
||||
$links['system.theme_settings_theme.' . $key_theme] = [
|
||||
'title' => t($label_theme),
|
||||
'provider' => 'admin_toolbar_tools',
|
||||
'route_name' => 'system.theme_settings_theme',
|
||||
'menu_name' => 'admin',
|
||||
'parent' => 'system.theme_settings_',
|
||||
'route_parameters' => [
|
||||
'theme' => $key_theme,
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
// If module Language enabled.
|
||||
if ($moduleHandler->moduleExists('language')) {
|
||||
$links['admin_toolbar_tools.language.negotiation'] = [
|
||||
'title' => t('Detection and selection'),
|
||||
'provider' => 'admin_toolbar_tools',
|
||||
'route_name' => 'language.negotiation',
|
||||
'menu_name' => 'admin',
|
||||
'parent' => 'entity.configurable_language.collection',
|
||||
];
|
||||
}
|
||||
|
||||
// If module Media enabled.
|
||||
if ($moduleHandler->moduleExists('media')) {
|
||||
$links['admin_toolbar_tools.add_media'] = [
|
||||
'title' => t('Add media'),
|
||||
'provider' => 'admin_toolbar_tools',
|
||||
'route_name' => 'entity.media.add_page',
|
||||
'menu_name' => 'admin',
|
||||
'parent' => 'system.admin_content',
|
||||
];
|
||||
// Add node links for each media type.
|
||||
foreach ($entityTypeManager->getStorage('media_type')->loadMultiple() as $type) {
|
||||
$links['media.add.' . $type->id()] = [
|
||||
'title' => t($type->label()),
|
||||
'provider' => 'admin_toolbar_tools',
|
||||
'route_name' => 'entity.media.add_form',
|
||||
'parent' => 'admin_toolbar_tools.add_media',
|
||||
'route_parameters' => ['media_type' => $type->id()],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
// If module Config enabled.
|
||||
if ($moduleHandler->moduleExists('config')) {
|
||||
$links['admin_toolbar_tools.config.import'] = [
|
||||
'title' => t('Import'),
|
||||
'provider' => 'admin_toolbar_tools',
|
||||
'route_name' => 'config.import_full',
|
||||
'menu_name' => 'admin',
|
||||
'parent' => 'config.sync',
|
||||
'weight' => 1,
|
||||
];
|
||||
$links['admin_toolbar_tools.config.export'] = [
|
||||
'title' => t('Export'),
|
||||
'provider' => 'admin_toolbar_tools',
|
||||
'route_name' => 'config.export_full',
|
||||
'menu_name' => 'admin',
|
||||
'parent' => 'config.sync',
|
||||
'weight' => 2,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return installed themes.
|
||||
*
|
||||
* @return array
|
||||
* An array of friendly theme names, keyed by the machine name.
|
||||
*/
|
||||
function admin_toolbar_tools_installed_themes() {
|
||||
$themeHandler = \Drupal::service('theme_handler');
|
||||
$all_themes = $themeHandler->listInfo();
|
||||
$themes_installed = [];
|
||||
foreach ($all_themes as $key_theme => $theme) {
|
||||
if ($themeHandler->hasUi($key_theme)) {
|
||||
$themes_installed[$key_theme] = $themeHandler->getName($key_theme);
|
||||
}
|
||||
}
|
||||
|
||||
return $themes_installed;
|
||||
}
|
|
@ -0,0 +1,80 @@
|
|||
admin_toolbar_tools.flush:
|
||||
path: '/admin/flush'
|
||||
defaults:
|
||||
_controller: '\Drupal\admin_toolbar_tools\Controller\ToolbarController::flushAll'
|
||||
_title: 'Flush all caches'
|
||||
requirements:
|
||||
_permission: 'administer site configuration'
|
||||
_csrf_token: 'TRUE'
|
||||
|
||||
admin_toolbar_tools.cssjs:
|
||||
path: '/admin/flush/cssjs'
|
||||
defaults:
|
||||
_controller: '\Drupal\admin_toolbar_tools\Controller\ToolbarController::flushJsCss'
|
||||
_title: 'Flush Css and Javascript'
|
||||
requirements:
|
||||
_permission: 'administer site configuration'
|
||||
_csrf_token: 'TRUE'
|
||||
|
||||
admin_toolbar_tools.plugin:
|
||||
path: '/admin/flush/plugin'
|
||||
defaults:
|
||||
_controller: '\Drupal\admin_toolbar_tools\Controller\ToolbarController::flushPlugins'
|
||||
_title: 'Plugin'
|
||||
requirements:
|
||||
_permission: 'administer site configuration'
|
||||
_csrf_token: 'TRUE'
|
||||
|
||||
admin_toolbar_tools.flush_static:
|
||||
path: '/admin/flush/static-caches'
|
||||
defaults:
|
||||
_controller: '\Drupal\admin_toolbar_tools\Controller\ToolbarController::flushStatic'
|
||||
_title: 'Static caches'
|
||||
requirements:
|
||||
_permission: 'administer site configuration'
|
||||
_csrf_token: 'TRUE'
|
||||
|
||||
admin_toolbar_tools.flush_menu:
|
||||
path: '/admin/flush/menu'
|
||||
defaults:
|
||||
_controller: '\Drupal\admin_toolbar_tools\Controller\ToolbarController::flushMenu'
|
||||
_title: 'Menu'
|
||||
requirements:
|
||||
_permission: 'administer site configuration'
|
||||
_csrf_token: 'TRUE'
|
||||
|
||||
admin_toolbar_tools.flush_rendercache:
|
||||
path: '/admin/flush/rendercache'
|
||||
defaults:
|
||||
_controller: '\Drupal\admin_toolbar_tools\Controller\ToolbarController::cacheRender'
|
||||
_title: 'Render cache'
|
||||
requirements:
|
||||
_permission: 'administer site configuration'
|
||||
_csrf_token: 'TRUE'
|
||||
|
||||
admin_toolbar_tools.flush_views:
|
||||
path: '/admin/flush/views'
|
||||
defaults:
|
||||
_controller: '\Drupal\admin_toolbar_tools\Controller\ToolbarController::flushViews'
|
||||
_title: 'Views'
|
||||
requirements:
|
||||
_permission: 'administer site configuration'
|
||||
_csrf_token: 'TRUE'
|
||||
|
||||
admin_toolbar_tools.flush_twig:
|
||||
path: '/admin/flush/twig'
|
||||
defaults:
|
||||
_controller: '\Drupal\admin_toolbar_tools\Controller\ToolbarController::flushTwig'
|
||||
_title: 'Twig'
|
||||
requirements:
|
||||
_permission: 'administer site configuration'
|
||||
_csrf_token: 'TRUE'
|
||||
|
||||
admin_toolbar.run.cron:
|
||||
path: '/run-cron'
|
||||
defaults:
|
||||
_controller: '\Drupal\admin_toolbar_tools\Controller\ToolbarController::runCron'
|
||||
_title: 'Run cron'
|
||||
requirements:
|
||||
_permission: 'administer site configuration'
|
||||
_csrf_token: 'TRUE'
|
|
@ -0,0 +1,39 @@
|
|||
{
|
||||
"name": "drupal/admin_toolbar_tools",
|
||||
"description": "Adds menu links to the Admin Toolbar.",
|
||||
"type": "drupal-module",
|
||||
"keywords": ["Drupal", "Toolbar"],
|
||||
"homepage": "http://drupal.org/project/admin_toolbar",
|
||||
"license": "GPL-2.0+",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Wilfrid Roze (eme)",
|
||||
"homepage": "https://www.drupal.org/u/eme",
|
||||
"role": "Maintainer"
|
||||
},
|
||||
{
|
||||
"name": "Romain Jarraud (romainj)",
|
||||
"homepage": "https://www.drupal.org/u/romainj",
|
||||
"role": "Maintainer"
|
||||
},
|
||||
{
|
||||
"name": "Adrian Cid Almaguer (adriancid)",
|
||||
"email": "adriancid@gmail.com",
|
||||
"homepage": "https://www.drupal.org/u/adriancid",
|
||||
"role": "Maintainer"
|
||||
},
|
||||
{
|
||||
"name": "Mohamed Anis Taktak (matio89)",
|
||||
"homepage": "https://www.drupal.org/u/matio89",
|
||||
"role": "Maintainer"
|
||||
}
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://www.drupal.org/project/issues/admin_toolbar",
|
||||
"source": "http://cgit.drupalcode.org/admin_toolbar"
|
||||
},
|
||||
"require": {
|
||||
"drupal/admin_toolbar": "^1",
|
||||
"drupal/core": "~8.5"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
.toolbar-icon-admin-toolbar-tools-help {
|
||||
text-indent: -9999px;
|
||||
}
|
||||
|
||||
.toolbar-icon-admin-toolbar-tools-help:before {
|
||||
background-image: url(../misc/icons/ffffff/d8-item.svg);
|
||||
padding-bottom: 0;
|
||||
padding-left: 4px;
|
||||
padding-right: 8px;
|
||||
padding-top: 2px;
|
||||
}
|
||||
|
||||
.toolbar-icon-admin-toolbar-tools-help:active:before,
|
||||
.toolbar-icon-admin-toolbar-tools-help.active:before {
|
||||
background-image: url(../misc/icons/ffffff/d8-item.svg);
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?><svg xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg" version="1.1" preserveAspectRatio="xMinYMin" viewBox="0 0 611 646"><path fill="#2ba9e0" d="M 161.14248,607.07981 C 135.931,577.51327 120.7662,539.33875 120.7662,497.60876 c 0,-87.01545 66.15644,-158.68624 151.648,-168.60413 -14.59612,-20.95856 -23.31588,-46.40824 -23.31588,-73.72922 0,-71.85792 58.95316,-129.86822 131.7442,-129.86822 6.06592,0 11.94228,0.37426 17.62908,1.12278 C 355.44148,89.85249 312.41136,52.61362 278.48012,12.00641 295.73008,190.15417 114.1316,125.40719 46.8378,289.70733 1.91208,399.73977 42.47792,535.78328 161.14248,607.07981 Z m 143.1178,-351.8044 c 0,41.72999 34.31036,75.41339 76.39268,75.41339 42.08232,0 76.58224,-33.87053 76.58224,-75.41339 0,-41.72999 -34.31036,-75.41339 -76.39268,-75.41339 -42.08232,0 -76.58224,33.6834 -76.58224,75.41339 z m 112.97776,124.81571 c 29.57136,30.50219 47.76912,71.85792 47.76912,117.51764 0,57.82317 -29.19224,108.72253 -73.73884,139.41185 82.4586,-25.07542 150.7002,-86.26693 181.21936,-160.37041 42.27188,-102.54724 2.8434,-179.6448 -63.12348,-249.63142 2.08516,8.98224 3.22252,18.52587 3.22252,28.0695 -0.18956,59.50734 -40.37628,109.47105 -95.34868,125.00284 z m -124.35136,18.90013 c -55.16196,0 -99.89812,44.16268 -99.89812,98.61751 0,54.45483 44.73616,98.61751 99.89812,98.61751 55.16196,0 99.89812,-44.16268 99.89812,-98.61751 0,-54.45483 -44.73616,-98.61751 -99.89812,-98.61751 z" /></svg>
|
After Width: | Height: | Size: 1.5 KiB |
|
@ -0,0 +1,249 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\admin_toolbar_tools\Controller;
|
||||
|
||||
use Drupal\Component\Datetime\TimeInterface;
|
||||
use Drupal\Core\Cache\CacheBackendInterface;
|
||||
use Drupal\Core\Controller\ControllerBase;
|
||||
use Drupal\Core\CronInterface;
|
||||
use Drupal\Core\Menu\ContextualLinkManagerInterface;
|
||||
use Drupal\Core\Menu\LocalActionManagerInterface;
|
||||
use Drupal\Core\Menu\LocalTaskManagerInterface;
|
||||
use Drupal\Core\Menu\MenuLinkManagerInterface;
|
||||
use Drupal\Core\Plugin\CachedDiscoveryClearerInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||
use Symfony\Component\HttpFoundation\RequestStack;
|
||||
use Drupal\Core\PhpStorage\PhpStorageFactory;
|
||||
|
||||
/**
|
||||
* Class ToolbarController.
|
||||
*
|
||||
* @package Drupal\admin_toolbar_tools\Controller
|
||||
*/
|
||||
class ToolbarController extends ControllerBase {
|
||||
|
||||
/**
|
||||
* A cron instance.
|
||||
*
|
||||
* @var \Drupal\Core\CronInterface
|
||||
*/
|
||||
protected $cron;
|
||||
|
||||
/**
|
||||
* A menu link manager instance.
|
||||
*
|
||||
* @var \Drupal\Core\Menu\MenuLinkManagerInterface
|
||||
*/
|
||||
protected $menuLinkManager;
|
||||
|
||||
/**
|
||||
* A context link manager instance.
|
||||
*
|
||||
* @var \Drupal\Core\Menu\ContextualLinkManagerInterface
|
||||
*/
|
||||
protected $contextualLinkManager;
|
||||
|
||||
/**
|
||||
* A local task manager instance.
|
||||
*
|
||||
* @var \Drupal\Core\Menu\LocalTaskManagerInterface
|
||||
*/
|
||||
protected $localTaskLinkManager;
|
||||
|
||||
/**
|
||||
* A local action manager instance.
|
||||
*
|
||||
* @var \Drupal\Core\Menu\LocalActionManagerInterface
|
||||
*/
|
||||
protected $localActionLinkManager;
|
||||
|
||||
/**
|
||||
* A cache backend interface instance.
|
||||
*
|
||||
* @var \Drupal\Core\Cache\CacheBackendInterface
|
||||
*/
|
||||
protected $cacheRender;
|
||||
|
||||
/**
|
||||
* A date time instance.
|
||||
*
|
||||
* @var \Drupal\Component\Datetime\TimeInterface
|
||||
*/
|
||||
protected $time;
|
||||
|
||||
/**
|
||||
* A request stack symfony instance.
|
||||
*
|
||||
* @var \Symfony\Component\HttpFoundation\RequestStack
|
||||
*/
|
||||
protected $requestStack;
|
||||
|
||||
/**
|
||||
* A plugin cache clear instance.
|
||||
*
|
||||
* @var \Drupal\Core\Plugin\CachedDiscoveryClearerInterface
|
||||
*/
|
||||
protected $pluginCacheClearer;
|
||||
|
||||
/**
|
||||
* Constructs a ToolbarController object.
|
||||
*
|
||||
* @param \Drupal\Core\CronInterface $cron
|
||||
* A cron instance.
|
||||
* @param \Drupal\Core\Menu\MenuLinkManagerInterface $menuLinkManager
|
||||
* A menu link manager instance.
|
||||
* @param \Drupal\Core\Menu\ContextualLinkManagerInterface $contextualLinkManager
|
||||
* A context link manager instance.
|
||||
* @param \Drupal\Core\Menu\LocalTaskManagerInterface $localTaskLinkManager
|
||||
* A local task manager instance.
|
||||
* @param \Drupal\Core\Menu\LocalActionManagerInterface $localActionLinkManager
|
||||
* A local action manager instance.
|
||||
* @param \Drupal\Core\Cache\CacheBackendInterface $cacheRender
|
||||
* A cache backend interface instance.
|
||||
* @param \Drupal\Component\Datetime\TimeInterface $time
|
||||
* A date time instance.
|
||||
* @param \Symfony\Component\HttpFoundation\RequestStack $request_stack
|
||||
* A request stack symfony instance.
|
||||
* @param \Drupal\Core\Plugin\CachedDiscoveryClearerInterface $plugin_cache_clearer
|
||||
* A plugin cache clear instance.
|
||||
*/
|
||||
public function __construct(CronInterface $cron,
|
||||
MenuLinkManagerInterface $menuLinkManager,
|
||||
ContextualLinkManagerInterface $contextualLinkManager,
|
||||
LocalTaskManagerInterface $localTaskLinkManager,
|
||||
LocalActionManagerInterface $localActionLinkManager,
|
||||
CacheBackendInterface $cacheRender,
|
||||
TimeInterface $time,
|
||||
RequestStack $request_stack,
|
||||
CachedDiscoveryClearerInterface $plugin_cache_clearer) {
|
||||
$this->cron = $cron;
|
||||
$this->menuLinkManager = $menuLinkManager;
|
||||
$this->contextualLinkManager = $contextualLinkManager;
|
||||
$this->localTaskLinkManager = $localTaskLinkManager;
|
||||
$this->localActionLinkManager = $localActionLinkManager;
|
||||
$this->cacheRender = $cacheRender;
|
||||
$this->time = $time;
|
||||
$this->requestStack = $request_stack;
|
||||
$this->pluginCacheClearer = $plugin_cache_clearer;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function create(ContainerInterface $container) {
|
||||
return new static(
|
||||
$container->get('cron'),
|
||||
$container->get('plugin.manager.menu.link'),
|
||||
$container->get('plugin.manager.menu.contextual_link'),
|
||||
$container->get('plugin.manager.menu.local_task'),
|
||||
$container->get('plugin.manager.menu.local_action'),
|
||||
$container->get('cache.render'),
|
||||
$container->get('datetime.time'),
|
||||
$container->get('request_stack'),
|
||||
$container->get('plugin.cache_clearer')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reload the previous page.
|
||||
*/
|
||||
public function reloadPage() {
|
||||
$request = $this->requestStack->getCurrentRequest();
|
||||
if ($request->server->get('HTTP_REFERER')) {
|
||||
return $request->server->get('HTTP_REFERER');
|
||||
}
|
||||
else {
|
||||
return '/';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Flushes all caches.
|
||||
*/
|
||||
public function flushAll() {
|
||||
$this->messenger()->addMessage($this->t('All caches cleared.'));
|
||||
drupal_flush_all_caches();
|
||||
return new RedirectResponse($this->reloadPage());
|
||||
}
|
||||
|
||||
/**
|
||||
* Flushes css and javascript caches.
|
||||
*/
|
||||
public function flushJsCss() {
|
||||
$this->state()
|
||||
->set('system.css_js_query_string', base_convert($this->time->getCurrentTime(), 10, 36));
|
||||
$this->messenger()->addMessage($this->t('CSS and JavaScript cache cleared.'));
|
||||
return new RedirectResponse($this->reloadPage());
|
||||
}
|
||||
|
||||
/**
|
||||
* Flushes plugins caches.
|
||||
*/
|
||||
public function flushPlugins() {
|
||||
$this->pluginCacheClearer->clearCachedDefinitions();
|
||||
$this->messenger()->addMessage($this->t('Plugins cache cleared.'));
|
||||
return new RedirectResponse($this->reloadPage());
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets all static caches.
|
||||
*/
|
||||
public function flushStatic() {
|
||||
drupal_static_reset();
|
||||
$this->messenger()->addMessage($this->t('Static cache cleared.'));
|
||||
return new RedirectResponse($this->reloadPage());
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears all cached menu data.
|
||||
*/
|
||||
public function flushMenu() {
|
||||
menu_cache_clear_all();
|
||||
$this->menuLinkManager->rebuild();
|
||||
$this->contextualLinkManager->clearCachedDefinitions();
|
||||
$this->localTaskLinkManager->clearCachedDefinitions();
|
||||
$this->localActionLinkManager->clearCachedDefinitions();
|
||||
$this->messenger()->addMessage($this->t('Routing and links cache cleared.'));
|
||||
return new RedirectResponse($this->reloadPage());
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears all cached views data.
|
||||
*/
|
||||
public function flushViews() {
|
||||
views_invalidate_cache();
|
||||
$this->messenger()->addMessage($this->t('Views cache cleared.'));
|
||||
return new RedirectResponse($this->reloadPage());
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears the twig cache.
|
||||
*/
|
||||
public function flushTwig() {
|
||||
// @todo Update once Drupal 8.6 will be released.
|
||||
// @see https://www.drupal.org/node/2908461
|
||||
PhpStorageFactory::get('twig')->deleteAll();
|
||||
$this->messenger()->addMessage($this->t('Twig cache cleared.'));
|
||||
return new RedirectResponse($this->reloadPage());
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the cron.
|
||||
*/
|
||||
public function runCron() {
|
||||
$this->cron->run();
|
||||
$this->messenger()->addMessage($this->t('Cron ran successfully.'));
|
||||
return new RedirectResponse($this->reloadPage());
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the rendered cache.
|
||||
*/
|
||||
public function cacheRender() {
|
||||
$this->cacheRender->invalidateAll();
|
||||
$this->messenger()->addMessage($this->t('Render cache cleared.'));
|
||||
return new RedirectResponse($this->reloadPage());
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,54 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\admin_toolbar_tools\Functional;
|
||||
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
|
||||
/**
|
||||
* Tests for the existence of Admin Toolbar tools new links.
|
||||
*
|
||||
* @group admin_toolbar
|
||||
*/
|
||||
class AdminToolbarToolsAlterTest extends BrowserTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected static $modules = [
|
||||
'toolbar',
|
||||
'admin_toolbar',
|
||||
'admin_toolbar_tools',
|
||||
];
|
||||
|
||||
/**
|
||||
* A test user with permission to access the administrative toolbar.
|
||||
*
|
||||
* @var \Drupal\user\UserInterface
|
||||
*/
|
||||
protected $adminUser;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
// Create and log in an administrative user.
|
||||
$this->adminUser = $this->drupalCreateUser([
|
||||
'access toolbar',
|
||||
'access administration pages',
|
||||
'administer site configuration',
|
||||
]);
|
||||
$this->drupalLogin($this->adminUser);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests for the hover of sub menus.
|
||||
*/
|
||||
public function testAdminToolbarTools() {
|
||||
// Assert that special menu items are present in the HTML.
|
||||
$this->assertRaw('class="toolbar-icon toolbar-icon-admin-toolbar-tools-flush"');
|
||||
}
|
||||
|
||||
}
|
35
2017/web/modules/contrib/admin_toolbar/composer.json
Normal file
35
2017/web/modules/contrib/admin_toolbar/composer.json
Normal file
|
@ -0,0 +1,35 @@
|
|||
{
|
||||
"name": "drupal/admin_toolbar",
|
||||
"description": "Provides a drop-down menu interface to the core Drupal Toolbar.",
|
||||
"type": "drupal-module",
|
||||
"keywords": ["Drupal", "Toolbar"],
|
||||
"homepage": "http://drupal.org/project/admin_toolbar",
|
||||
"license": "GPL-2.0+",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Wilfrid Roze (eme)",
|
||||
"homepage": "https://www.drupal.org/u/eme",
|
||||
"role": "Maintainer"
|
||||
},
|
||||
{
|
||||
"name": "Romain Jarraud (romainj)",
|
||||
"homepage": "https://www.drupal.org/u/romainj",
|
||||
"role": "Maintainer"
|
||||
},
|
||||
{
|
||||
"name": "Adrian Cid Almaguer (adriancid)",
|
||||
"email": "adriancid@gmail.com",
|
||||
"homepage": "https://www.drupal.org/u/adriancid",
|
||||
"role": "Maintainer"
|
||||
},
|
||||
{
|
||||
"name": "Mohamed Anis Taktak (matio89)",
|
||||
"homepage": "https://www.drupal.org/u/matio89",
|
||||
"role": "Maintainer"
|
||||
}
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://www.drupal.org/project/issues/admin_toolbar",
|
||||
"source": "http://cgit.drupalcode.org/admin_toolbar"
|
||||
}
|
||||
}
|
211
2017/web/modules/contrib/admin_toolbar/css/admin.toolbar.css
Normal file
211
2017/web/modules/contrib/admin_toolbar/css/admin.toolbar.css
Normal file
|
@ -0,0 +1,211 @@
|
|||
.toolbar-tray-horizontal .menu-item:hover {
|
||||
background: #fff;
|
||||
}
|
||||
|
||||
.toolbar-tray-horizontal .menu-item a:focus {
|
||||
background: #abeae4;
|
||||
}
|
||||
|
||||
.toolbar-tray-horizontal .toolbar-menu:not(:first-child) li.menu-item--expanded > a:focus {
|
||||
background-position: center right;
|
||||
background-image: url('../misc/icons/0074bd/chevron-right.svg');
|
||||
background-repeat: no-repeat;
|
||||
}
|
||||
|
||||
.toolbar-tray-horizontal .menu-item--expanded .menu {
|
||||
background: #fff;
|
||||
width: auto;
|
||||
height: auto;
|
||||
}
|
||||
|
||||
.toolbar-tray-horizontal .menu-item--expanded {
|
||||
background-color: #f5f5f2;
|
||||
}
|
||||
|
||||
.toolbar-tray-horizontal ul li li.menu-item {
|
||||
border-top: none transparent;
|
||||
border-right: 1px solid #dddddd;
|
||||
border-bottom: 1px solid #dddddd;
|
||||
border-left: 1px solid #dddddd;
|
||||
}
|
||||
|
||||
.toolbar .toolbar-tray-horizontal .menu-item:last-child {
|
||||
border-left: 1px solid #dddddd;
|
||||
border-right: 1px solid #dddddd;
|
||||
}
|
||||
|
||||
.toolbar .toolbar-tray-horizontal ul ul li.menu-item:first-child {
|
||||
border-top: 1px solid #dddddd;
|
||||
}
|
||||
|
||||
.toolbar-tray-horizontal li.menu-item--expanded.hover-intent ul ul,
|
||||
.toolbar-tray-horizontal li.menu-item--expanded.hover-intent ul ul ul,
|
||||
.toolbar-tray-horizontal li.menu-item--expanded.hover-intent ul ul ul ul,
|
||||
.toolbar-tray-horizontal li.menu-item--expanded.hover-intent ul ul ul ul ul {
|
||||
display: none;
|
||||
left: -999em; /* LTR */
|
||||
}
|
||||
|
||||
/* Lists nested under hovered list items */
|
||||
.toolbar-tray-horizontal li.menu-item--expanded.hover-intent ul,
|
||||
.toolbar-tray-horizontal li li.menu-item--expanded.hover-intent ul,
|
||||
.toolbar-tray-horizontal li li li.menu-item--expanded.hover-intent ul,
|
||||
.toolbar-tray-horizontal li li li li.menu-item--expanded.hover-intent ul,
|
||||
.toolbar-tray-horizontal li li li li li.menu-item--expanded.hover-intent ul {
|
||||
display: block;
|
||||
left: auto; /* LTR */
|
||||
}
|
||||
|
||||
.toolbar-tray-horizontal .menu ul li a,
|
||||
.toolbar-tray-horizontal .menu ul .toolbar-icon {
|
||||
padding: 12px 15px 12px 12px;
|
||||
}
|
||||
|
||||
.toolbar-tray-horizontal ul li.menu-item--expanded.hover-intent ul {
|
||||
display: block;
|
||||
position: absolute;
|
||||
width: 200px;
|
||||
box-shadow: 2px 2px 3px hsla(0, 0%, 0%, 0.4);
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
.toolbar-tray-horizontal ul li.menu-item--expanded .menu-item > ul {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.toolbar-tray-horizontal ul li.menu-item--expanded ul li.menu-item--expanded {
|
||||
background-position: center right;
|
||||
background-image: url('../misc/icons/0074bd/chevron-right.svg');
|
||||
background-repeat: no-repeat;
|
||||
}
|
||||
|
||||
.toolbar-tray-horizontal ul li.menu-item--expanded .menu-item.hover-intent ul {
|
||||
display: block;
|
||||
margin: -40px 0 0 197px;
|
||||
}
|
||||
|
||||
.toolbar-tray-horizontal li:hover ul li {
|
||||
float: none;
|
||||
}
|
||||
|
||||
.toolbar-tray-horizontal li.hover-intent ul li {
|
||||
float: none;
|
||||
}
|
||||
|
||||
.toolbar-tray-horizontal .toolbar .level-2 > ul {
|
||||
position: absolute;
|
||||
padding-top: 0;
|
||||
top: 0;
|
||||
left: 200px;
|
||||
width: 200px;
|
||||
}
|
||||
|
||||
.toolbar .toolbar-tray-vertical li.open > ul.toolbar-menu.clearfix {
|
||||
display: block;
|
||||
}
|
||||
|
||||
[dir="rtl"] .toolbar-tray-horizontal .menu-item:hover {
|
||||
background: #fff;
|
||||
}
|
||||
|
||||
[dir="rtl"] .toolbar-tray-horizontal .menu-item a:focus {
|
||||
background: #abeae4;
|
||||
}
|
||||
|
||||
[dir="rtl"] .toolbar-tray-horizontal .toolbar-menu:not(:first-child) li.menu-item--expanded > a:focus {
|
||||
background-position: center right;
|
||||
background-image: url('../misc/icons/0074bd/chevron-right.svg');
|
||||
background-repeat: no-repeat;
|
||||
}
|
||||
|
||||
[dir="rtl"] .toolbar-tray-horizontal .menu-item--expanded .menu {
|
||||
background: #fff;
|
||||
width: auto;
|
||||
height: auto;
|
||||
}
|
||||
|
||||
[dir="rtl"] .toolbar-tray-horizontal .menu-item--expanded {
|
||||
background-color: #f5f5f2;
|
||||
}
|
||||
|
||||
[dir="rtl"] .toolbar-tray-horizontal ul li li.menu-item {
|
||||
border-top: none transparent;
|
||||
border-right: 1px solid #dddddd;
|
||||
border-bottom: 1px solid #dddddd;
|
||||
border-left: 1px solid #dddddd;
|
||||
}
|
||||
|
||||
[dir="rtl"] .toolbar .toolbar-tray-horizontal .menu-item:last-child {
|
||||
border-left: 1px solid #dddddd;
|
||||
border-right: 1px solid #dddddd;
|
||||
}
|
||||
|
||||
[dir="rtl"] .toolbar .toolbar-tray-horizontal ul ul li.menu-item:first-child {
|
||||
border-top: 1px solid #dddddd;
|
||||
}
|
||||
|
||||
[dir="rtl"] .toolbar-tray-horizontal li.menu-item--expanded.hover-intent ul ul,
|
||||
[dir="rtl"] .toolbar-tray-horizontal li.menu-item--expanded.hover-intent ul ul ul,
|
||||
[dir="rtl"] .toolbar-tray-horizontal li.menu-item--expanded.hover-intent ul ul ul ul,
|
||||
[dir="rtl"] .toolbar-tray-horizontal li.menu-item--expanded.hover-intent ul ul ul ul ul {
|
||||
display: none;
|
||||
left: -999em; /* LTR */
|
||||
}
|
||||
|
||||
/* Lists nested under hovered list items */
|
||||
[dir="rtl"] .toolbar-tray-horizontal li.menu-item--expanded.hover-intent ul,
|
||||
[dir="rtl"] .toolbar-tray-horizontal li li.menu-item--expanded.hover-intent ul,
|
||||
[dir="rtl"] .toolbar-tray-horizontal li li li.menu-item--expanded.hover-intent ul,
|
||||
[dir="rtl"] .toolbar-tray-horizontal li li li li.menu-item--expanded.hover-intent ul,
|
||||
[dir="rtl"] .toolbar-tray-horizontal li li li li li.menu-item--expanded.hover-intent ul {
|
||||
display: block;
|
||||
left: auto; /* LTR */
|
||||
}
|
||||
|
||||
[dir="rtl"] .toolbar-tray-horizontal .menu ul li a,
|
||||
[dir="rtl"] .toolbar-tray-horizontal .menu ul .toolbar-icon {
|
||||
padding: 12px 15px 12px 12px;
|
||||
}
|
||||
|
||||
[dir="rtl"] .toolbar-tray-horizontal ul li.menu-item--expanded.hover-intent ul {
|
||||
display: block;
|
||||
position: absolute;
|
||||
width: 200px;
|
||||
box-shadow: 2px 2px 3px hsla(0, 0%, 0%, 0.4);
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
[dir="rtl"] .toolbar-tray-horizontal ul li.menu-item--expanded .menu-item > ul {
|
||||
display: none;
|
||||
}
|
||||
|
||||
[dir="rtl"] .toolbar-tray-horizontal ul li.menu-item--expanded ul li.menu-item--expanded {
|
||||
background-position: center left;
|
||||
background-image: url('../misc/icons/0074bd/chevron-left.svg');
|
||||
background-repeat: no-repeat;
|
||||
}
|
||||
|
||||
[dir="rtl"] .toolbar-tray-horizontal ul li.menu-item--expanded .menu-item.hover-intent ul {
|
||||
display: block;
|
||||
margin: -40px 197px 0 0;
|
||||
}
|
||||
|
||||
[dir="rtl"] .toolbar-tray-horizontal li:hover ul li {
|
||||
float: none;
|
||||
}
|
||||
|
||||
[dir="rtl"] .toolbar-tray-horizontal li.hover-intent ul li {
|
||||
float: none;
|
||||
}
|
||||
|
||||
[dir="rtl"] .toolbar-tray-horizontal .toolbar .level-2 > ul {
|
||||
position: absolute;
|
||||
padding-top: 0;
|
||||
top: 0;
|
||||
left: 200px;
|
||||
width: 200px;
|
||||
}
|
||||
|
||||
[dir="rtl"] .toolbar .toolbar-tray-vertical li.open > ul.toolbar-menu.clearfix {
|
||||
display: block;
|
||||
}
|
53
2017/web/modules/contrib/admin_toolbar/js/admin_toolbar.js
Normal file
53
2017/web/modules/contrib/admin_toolbar/js/admin_toolbar.js
Normal file
|
@ -0,0 +1,53 @@
|
|||
(function ($, Drupal) {
|
||||
Drupal.behaviors.adminToolbar = {
|
||||
attach: function (context, settings) {
|
||||
|
||||
$('a.toolbar-icon', context).removeAttr('title');
|
||||
|
||||
$('.toolbar-tray li.menu-item--expanded, .toolbar-tray ul li.menu-item--expanded .menu-item', context).hoverIntent({
|
||||
over: function () {
|
||||
// At the current depth, we should delete all "hover-intent" classes.
|
||||
// Other wise we get unwanted behaviour where menu items are expanded while already in hovering other ones.
|
||||
$(this).parent().find('li').removeClass('hover-intent');
|
||||
$(this).addClass('hover-intent');
|
||||
},
|
||||
out: function () {
|
||||
$(this).removeClass('hover-intent');
|
||||
},
|
||||
timeout: 250
|
||||
});
|
||||
|
||||
// Make the toolbar menu navigable with keyboard.
|
||||
$('ul.toolbar-menu li.menu-item--expanded a', context).on('focusin', function () {
|
||||
$('li.menu-item--expanded', context).removeClass('hover-intent');
|
||||
$(this).parents('li.menu-item--expanded').addClass('hover-intent');
|
||||
});
|
||||
|
||||
$('ul.toolbar-menu li.menu-item a', context).keydown(function (e) {
|
||||
if ((e.shiftKey && (e.keyCode || e.which) == 9)) {
|
||||
if ($(this).parent('.menu-item').prev().hasClass('menu-item--expanded')) {
|
||||
$(this).parent('.menu-item').prev().addClass('hover-intent');
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
$('.toolbar-menu:first-child > .menu-item:not(.menu-item--expanded) a, .toolbar-tab > a', context).on('focusin', function () {
|
||||
$('.menu-item--expanded').removeClass('hover-intent');
|
||||
});
|
||||
|
||||
$('.toolbar-menu:first-child > .menu-item', context).on('hover', function () {
|
||||
$(this, 'a').css("background: #fff;");
|
||||
});
|
||||
|
||||
$('ul:not(.toolbar-menu)', context).on({
|
||||
mousemove: function () {
|
||||
$('li.menu-item--expanded').removeClass('hover-intent');
|
||||
},
|
||||
hover: function () {
|
||||
$('li.menu-item--expanded').removeClass('hover-intent');
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
};
|
||||
})(jQuery, Drupal);
|
158
2017/web/modules/contrib/admin_toolbar/js/jquery.hoverIntent.js
Normal file
158
2017/web/modules/contrib/admin_toolbar/js/jquery.hoverIntent.js
Normal file
|
@ -0,0 +1,158 @@
|
|||
/*!
|
||||
* hoverIntent v1.8.1 // 2014.08.11 // jQuery v1.9.1+
|
||||
* http://briancherne.github.io/jquery-hoverIntent/
|
||||
*
|
||||
* You may use hoverIntent under the terms of the MIT license. Basically that
|
||||
* means you are free to use hoverIntent as long as this header is left intact.
|
||||
* Copyright 2007, 2014 Brian Cherne
|
||||
*/
|
||||
|
||||
/* hoverIntent is similar to jQuery's built-in "hover" method except that
|
||||
* instead of firing the handlerIn function immediately, hoverIntent checks
|
||||
* to see if the user's mouse has slowed down (beneath the sensitivity
|
||||
* threshold) before firing the event. The handlerOut function is only
|
||||
* called after a matching handlerIn.
|
||||
*
|
||||
* // basic usage ... just like .hover()
|
||||
* .hoverIntent( handlerIn, handlerOut )
|
||||
* .hoverIntent( handlerInOut )
|
||||
*
|
||||
* // basic usage ... with event delegation!
|
||||
* .hoverIntent( handlerIn, handlerOut, selector )
|
||||
* .hoverIntent( handlerInOut, selector )
|
||||
*
|
||||
* // using a basic configuration object
|
||||
* .hoverIntent( config )
|
||||
*
|
||||
* @param handlerIn function OR configuration object
|
||||
* @param handlerOut function OR selector for delegation OR undefined
|
||||
* @param selector selector OR undefined
|
||||
* @author Brian Cherne <brian(at)cherne(dot)net>
|
||||
*/
|
||||
|
||||
;(function(factory) {
|
||||
'use strict';
|
||||
if (typeof define === 'function' && define.amd) {
|
||||
define(['jquery'], factory);
|
||||
} else if (jQuery && !jQuery.fn.hoverIntent) {
|
||||
factory(jQuery);
|
||||
}
|
||||
})(function($) {
|
||||
'use strict';
|
||||
|
||||
// default configuration values
|
||||
var _cfg = {
|
||||
interval: 100,
|
||||
sensitivity: 6,
|
||||
timeout: 0
|
||||
};
|
||||
|
||||
// counter used to generate an ID for each instance
|
||||
var INSTANCE_COUNT = 0;
|
||||
|
||||
// current X and Y position of mouse, updated during mousemove tracking (shared across instances)
|
||||
var cX, cY;
|
||||
|
||||
// saves the current pointer position coordinates based on the given mousemove event
|
||||
var track = function(ev) {
|
||||
cX = ev.pageX;
|
||||
cY = ev.pageY;
|
||||
};
|
||||
|
||||
// compares current and previous mouse positions
|
||||
var compare = function(ev,$el,s,cfg) {
|
||||
// compare mouse positions to see if pointer has slowed enough to trigger `over` function
|
||||
if ( Math.sqrt( (s.pX-cX)*(s.pX-cX) + (s.pY-cY)*(s.pY-cY) ) < cfg.sensitivity ) {
|
||||
$el.off(s.event,track);
|
||||
delete s.timeoutId;
|
||||
// set hoverIntent state as active for this element (permits `out` handler to trigger)
|
||||
s.isActive = true;
|
||||
// overwrite old mouseenter event coordinates with most recent pointer position
|
||||
ev.pageX = cX; ev.pageY = cY;
|
||||
// clear coordinate data from state object
|
||||
delete s.pX; delete s.pY;
|
||||
return cfg.over.apply($el[0],[ev]);
|
||||
} else {
|
||||
// set previous coordinates for next comparison
|
||||
s.pX = cX; s.pY = cY;
|
||||
// use self-calling timeout, guarantees intervals are spaced out properly (avoids JavaScript timer bugs)
|
||||
s.timeoutId = setTimeout( function(){compare(ev, $el, s, cfg);} , cfg.interval );
|
||||
}
|
||||
};
|
||||
|
||||
// triggers given `out` function at configured `timeout` after a mouseleave and clears state
|
||||
var delay = function(ev,$el,s,out) {
|
||||
delete $el.data('hoverIntent')[s.id];
|
||||
return out.apply($el[0],[ev]);
|
||||
};
|
||||
|
||||
$.fn.hoverIntent = function(handlerIn,handlerOut,selector) {
|
||||
// instance ID, used as a key to store and retrieve state information on an element
|
||||
var instanceId = INSTANCE_COUNT++;
|
||||
|
||||
// extend the default configuration and parse parameters
|
||||
var cfg = $.extend({}, _cfg);
|
||||
if ( $.isPlainObject(handlerIn) ) {
|
||||
cfg = $.extend(cfg, handlerIn);
|
||||
if ( !$.isFunction(cfg.out) ) {
|
||||
cfg.out = cfg.over;
|
||||
}
|
||||
} else if ( $.isFunction(handlerOut) ) {
|
||||
cfg = $.extend(cfg, { over: handlerIn, out: handlerOut, selector: selector } );
|
||||
} else {
|
||||
cfg = $.extend(cfg, { over: handlerIn, out: handlerIn, selector: handlerOut } );
|
||||
}
|
||||
|
||||
// A private function for handling mouse 'hovering'
|
||||
var handleHover = function(e) {
|
||||
// cloned event to pass to handlers (copy required for event object to be passed in IE)
|
||||
var ev = $.extend({},e);
|
||||
|
||||
// the current target of the mouse event, wrapped in a jQuery object
|
||||
var $el = $(this);
|
||||
|
||||
// read hoverIntent data from element (or initialize if not present)
|
||||
var hoverIntentData = $el.data('hoverIntent');
|
||||
if (!hoverIntentData) { $el.data('hoverIntent', (hoverIntentData = {})); }
|
||||
|
||||
// read per-instance state from element (or initialize if not present)
|
||||
var state = hoverIntentData[instanceId];
|
||||
if (!state) { hoverIntentData[instanceId] = state = { id: instanceId }; }
|
||||
|
||||
// state properties:
|
||||
// id = instance ID, used to clean up data
|
||||
// timeoutId = timeout ID, reused for tracking mouse position and delaying "out" handler
|
||||
// isActive = plugin state, true after `over` is called just until `out` is called
|
||||
// pX, pY = previously-measured pointer coordinates, updated at each polling interval
|
||||
// event = string representing the namespaced event used for mouse tracking
|
||||
|
||||
// clear any existing timeout
|
||||
if (state.timeoutId) { state.timeoutId = clearTimeout(state.timeoutId); }
|
||||
|
||||
// namespaced event used to register and unregister mousemove tracking
|
||||
var mousemove = state.event = 'mousemove.hoverIntent.hoverIntent'+instanceId;
|
||||
|
||||
// handle the event, based on its type
|
||||
if (e.type === 'mouseenter') {
|
||||
// do nothing if already active
|
||||
if (state.isActive) { return; }
|
||||
// set "previous" X and Y position based on initial entry point
|
||||
state.pX = ev.pageX; state.pY = ev.pageY;
|
||||
// update "current" X and Y position based on mousemove
|
||||
$el.off(mousemove,track).on(mousemove,track);
|
||||
// start polling interval (self-calling timeout) to compare mouse coordinates over time
|
||||
state.timeoutId = setTimeout( function(){compare(ev,$el,state,cfg);} , cfg.interval );
|
||||
} else { // "mouseleave"
|
||||
// do nothing if not already active
|
||||
if (!state.isActive) { return; }
|
||||
// unbind expensive mousemove event
|
||||
$el.off(mousemove,track);
|
||||
// if hoverIntent state is true, then call the mouseOut function after the specified delay
|
||||
state.timeoutId = setTimeout( function(){delay(ev,$el,state,cfg.out);} , cfg.timeout );
|
||||
}
|
||||
};
|
||||
|
||||
// listen for mouseenter and mouseleave
|
||||
return this.on({'mouseenter.hoverIntent':handleHover,'mouseleave.hoverIntent':handleHover}, cfg.selector);
|
||||
};
|
||||
});
|
|
@ -0,0 +1 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16"><path fill="#0074bd" d="M7.951 7.645c-.193.196-.193.516 0 .71l3.258 3.29c.193.193.191.519-.002.709l-1.371 1.371c-.193.192-.512.191-.707 0l-5.335-5.371c-.194-.194-.194-.514 0-.708l5.335-5.369c.195-.195.514-.195.707-.001l1.371 1.371c.193.194.195.513.002.709l-3.258 3.289z"/></svg>
|
After Width: | Height: | Size: 342 B |
|
@ -0,0 +1 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16"><path fill="#0074bd" d="M8.053 8.355c.193-.195.193-.517 0-.711l-3.26-3.289c-.193-.195-.192-.514.002-.709l1.371-1.371c.194-.194.512-.193.706.001l5.335 5.369c.195.195.195.515 0 .708l-5.335 5.37c-.194.192-.512.193-.706.002l-1.371-1.371c-.194-.195-.195-.514-.002-.709l3.26-3.29z"/></svg>
|
After Width: | Height: | Size: 347 B |
|
@ -0,0 +1 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16"><path fill="#0074bd" d="M8.053 8.355c.193-.195.193-.517 0-.711l-3.26-3.289c-.193-.195-.192-.514.002-.709l1.371-1.371c.194-.194.512-.193.706.001l5.335 5.369c.195.195.195.515 0 .708l-5.335 5.37c-.194.192-.512.193-.706.002l-1.371-1.371c-.194-.195-.195-.514-.002-.709l3.26-3.29z"/></svg>
|
After Width: | Height: | Size: 347 B |
|
@ -0,0 +1,54 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\admin_toolbar\Functional;
|
||||
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
|
||||
/**
|
||||
* Test the existence of Admin Toolbar module.
|
||||
*
|
||||
* @group admin_toolbar
|
||||
*/
|
||||
class AdminToolbarAlterTest extends BrowserTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected static $modules = [
|
||||
'toolbar',
|
||||
'breakpoint',
|
||||
'admin_toolbar',
|
||||
];
|
||||
|
||||
/**
|
||||
* A test user with permission to access the administrative toolbar.
|
||||
*
|
||||
* @var \Drupal\user\UserInterface
|
||||
*/
|
||||
protected $adminUser;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
// Create and log in an administrative user.
|
||||
$this->adminUser = $this->drupalCreateUser([
|
||||
'access toolbar',
|
||||
'access administration pages',
|
||||
]);
|
||||
$this->drupalLogin($this->adminUser);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests for a the hover of sub menus.
|
||||
*/
|
||||
public function testAdminToolbar() {
|
||||
// Assert that expanded links are present in the HTML.
|
||||
$this->assertRaw('class="toolbar-icon toolbar-icon-user-admin-index"');
|
||||
}
|
||||
|
||||
}
|
339
2017/web/modules/contrib/ctools/LICENSE.txt
Normal file
339
2017/web/modules/contrib/ctools/LICENSE.txt
Normal file
|
@ -0,0 +1,339 @@
|
|||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 2, June 1991
|
||||
|
||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
License is intended to guarantee your freedom to share and change free
|
||||
software--to make sure the software is free for all its users. This
|
||||
General Public License applies to most of the Free Software
|
||||
Foundation's software and to any other program whose authors commit to
|
||||
using it. (Some other Free Software Foundation software is covered by
|
||||
the GNU Lesser General Public License instead.) You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
this service if you wish), that you receive source code or can get it
|
||||
if you want it, that you can change the software or use pieces of it
|
||||
in new free programs; and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
anyone to deny you these rights or to ask you to surrender the rights.
|
||||
These restrictions translate to certain responsibilities for you if you
|
||||
distribute copies of the software, or if you modify it.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must give the recipients all the rights that
|
||||
you have. You must make sure that they, too, receive or can get the
|
||||
source code. And you must show them these terms so they know their
|
||||
rights.
|
||||
|
||||
We protect your rights with two steps: (1) copyright the software, and
|
||||
(2) offer you this license which gives you legal permission to copy,
|
||||
distribute and/or modify the software.
|
||||
|
||||
Also, for each author's protection and ours, we want to make certain
|
||||
that everyone understands that there is no warranty for this free
|
||||
software. If the software is modified by someone else and passed on, we
|
||||
want its recipients to know that what they have is not the original, so
|
||||
that any problems introduced by others will not reflect on the original
|
||||
authors' reputations.
|
||||
|
||||
Finally, any free program is threatened constantly by software
|
||||
patents. We wish to avoid the danger that redistributors of a free
|
||||
program will individually obtain patent licenses, in effect making the
|
||||
program proprietary. To prevent this, we have made it clear that any
|
||||
patent must be licensed for everyone's free use or not licensed at all.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License applies to any program or other work which contains
|
||||
a notice placed by the copyright holder saying it may be distributed
|
||||
under the terms of this General Public License. The "Program", below,
|
||||
refers to any such program or work, and a "work based on the Program"
|
||||
means either the Program or any derivative work under copyright law:
|
||||
that is to say, a work containing the Program or a portion of it,
|
||||
either verbatim or with modifications and/or translated into another
|
||||
language. (Hereinafter, translation is included without limitation in
|
||||
the term "modification".) Each licensee is addressed as "you".
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running the Program is not restricted, and the output from the Program
|
||||
is covered only if its contents constitute a work based on the
|
||||
Program (independent of having been made by running the Program).
|
||||
Whether that is true depends on what the Program does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Program's
|
||||
source code as you receive it, in any medium, provided that you
|
||||
conspicuously and appropriately publish on each copy an appropriate
|
||||
copyright notice and disclaimer of warranty; keep intact all the
|
||||
notices that refer to this License and to the absence of any warranty;
|
||||
and give any other recipients of the Program a copy of this License
|
||||
along with the Program.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy, and
|
||||
you may at your option offer warranty protection in exchange for a fee.
|
||||
|
||||
2. You may modify your copy or copies of the Program or any portion
|
||||
of it, thus forming a work based on the Program, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) You must cause the modified files to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
b) You must cause any work that you distribute or publish, that in
|
||||
whole or in part contains or is derived from the Program or any
|
||||
part thereof, to be licensed as a whole at no charge to all third
|
||||
parties under the terms of this License.
|
||||
|
||||
c) If the modified program normally reads commands interactively
|
||||
when run, you must cause it, when started running for such
|
||||
interactive use in the most ordinary way, to print or display an
|
||||
announcement including an appropriate copyright notice and a
|
||||
notice that there is no warranty (or else, saying that you provide
|
||||
a warranty) and that users may redistribute the program under
|
||||
these conditions, and telling the user how to view a copy of this
|
||||
License. (Exception: if the Program itself is interactive but
|
||||
does not normally print such an announcement, your work based on
|
||||
the Program is not required to print an announcement.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Program,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Program, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Program.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Program
|
||||
with the Program (or with a work based on the Program) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may copy and distribute the Program (or a work based on it,
|
||||
under Section 2) in object code or executable form under the terms of
|
||||
Sections 1 and 2 above provided that you also do one of the following:
|
||||
|
||||
a) Accompany it with the complete corresponding machine-readable
|
||||
source code, which must be distributed under the terms of Sections
|
||||
1 and 2 above on a medium customarily used for software interchange; or,
|
||||
|
||||
b) Accompany it with a written offer, valid for at least three
|
||||
years, to give any third party, for a charge no more than your
|
||||
cost of physically performing source distribution, a complete
|
||||
machine-readable copy of the corresponding source code, to be
|
||||
distributed under the terms of Sections 1 and 2 above on a medium
|
||||
customarily used for software interchange; or,
|
||||
|
||||
c) Accompany it with the information you received as to the offer
|
||||
to distribute corresponding source code. (This alternative is
|
||||
allowed only for noncommercial distribution and only if you
|
||||
received the program in object code or executable form with such
|
||||
an offer, in accord with Subsection b above.)
|
||||
|
||||
The source code for a work means the preferred form of the work for
|
||||
making modifications to it. For an executable work, complete source
|
||||
code means all the source code for all modules it contains, plus any
|
||||
associated interface definition files, plus the scripts used to
|
||||
control compilation and installation of the executable. However, as a
|
||||
special exception, the source code distributed need not include
|
||||
anything that is normally distributed (in either source or binary
|
||||
form) with the major components (compiler, kernel, and so on) of the
|
||||
operating system on which the executable runs, unless that component
|
||||
itself accompanies the executable.
|
||||
|
||||
If distribution of executable or object code is made by offering
|
||||
access to copy from a designated place, then offering equivalent
|
||||
access to copy the source code from the same place counts as
|
||||
distribution of the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
4. You may not copy, modify, sublicense, or distribute the Program
|
||||
except as expressly provided under this License. Any attempt
|
||||
otherwise to copy, modify, sublicense or distribute the Program is
|
||||
void, and will automatically terminate your rights under this License.
|
||||
However, parties who have received copies, or rights, from you under
|
||||
this License will not have their licenses terminated so long as such
|
||||
parties remain in full compliance.
|
||||
|
||||
5. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Program or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Program (or any work based on the
|
||||
Program), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Program or works based on it.
|
||||
|
||||
6. Each time you redistribute the Program (or any work based on the
|
||||
Program), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute or modify the Program subject to
|
||||
these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties to
|
||||
this License.
|
||||
|
||||
7. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Program at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Program by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Program.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under
|
||||
any particular circumstance, the balance of the section is intended to
|
||||
apply and the section as a whole is intended to apply in other
|
||||
circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system, which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
8. If the distribution and/or use of the Program is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Program under this License
|
||||
may add an explicit geographical distribution limitation excluding
|
||||
those countries, so that distribution is permitted only in or among
|
||||
countries not thus excluded. In such case, this License incorporates
|
||||
the limitation as if written in the body of this License.
|
||||
|
||||
9. The Free Software Foundation may publish revised and/or new versions
|
||||
of the General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Program
|
||||
specifies a version number of this License which applies to it and "any
|
||||
later version", you have the option of following the terms and conditions
|
||||
either of that version or of any later version published by the Free
|
||||
Software Foundation. If the Program does not specify a version number of
|
||||
this License, you may choose any version ever published by the Free Software
|
||||
Foundation.
|
||||
|
||||
10. If you wish to incorporate parts of the Program into other free
|
||||
programs whose distribution conditions are different, write to the author
|
||||
to ask for permission. For software which is copyrighted by the Free
|
||||
Software Foundation, write to the Free Software Foundation; we sometimes
|
||||
make exceptions for this. Our decision will be guided by the two goals
|
||||
of preserving the free status of all derivatives of our free software and
|
||||
of promoting the sharing and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
|
||||
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
|
||||
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
|
||||
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
|
||||
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
|
||||
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
|
||||
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
|
||||
REPAIR OR CORRECTION.
|
||||
|
||||
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
||||
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
|
||||
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
|
||||
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
|
||||
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
|
||||
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
convey the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program is interactive, make it output a short notice like this
|
||||
when it starts in an interactive mode:
|
||||
|
||||
Gnomovision version 69, Copyright (C) year name of author
|
||||
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, the commands you use may
|
||||
be called something other than `show w' and `show c'; they could even be
|
||||
mouse-clicks or menu items--whatever suits your program.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or your
|
||||
school, if any, to sign a "copyright disclaimer" for the program, if
|
||||
necessary. Here is a sample; alter the names:
|
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
|
||||
`Gnomovision' (which makes passes at compilers) written by James Hacker.
|
||||
|
||||
<signature of Ty Coon>, 1 April 1989
|
||||
Ty Coon, President of Vice
|
||||
|
||||
This General Public License does not permit incorporating your program into
|
||||
proprietary programs. If your program is a subroutine library, you may
|
||||
consider it more useful to permit linking proprietary applications with the
|
||||
library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License.
|
40
2017/web/modules/contrib/ctools/composer.json
Normal file
40
2017/web/modules/contrib/ctools/composer.json
Normal file
|
@ -0,0 +1,40 @@
|
|||
{
|
||||
"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+",
|
||||
"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": "http://cgit.drupalcode.org/ctools"
|
||||
},
|
||||
"require": {}
|
||||
}
|
|
@ -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]
|
11
2017/web/modules/contrib/ctools/ctools.info.yml
Normal file
11
2017/web/modules/contrib/ctools/ctools.info.yml
Normal file
|
@ -0,0 +1,11 @@
|
|||
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: 8.x
|
||||
|
||||
# Information added by Drupal.org packaging script on 2017-04-28
|
||||
version: '8.x-3.0'
|
||||
core: '8.x'
|
||||
project: 'ctools'
|
||||
datestamp: 1493401747
|
64
2017/web/modules/contrib/ctools/ctools.module
Normal file
64
2017/web/modules/contrib/ctools/ctools.module
Normal file
|
@ -0,0 +1,64 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Implements hook_theme().
|
||||
*/
|
||||
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,
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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 \Drupal\Core\Url($wizard->getRouteName(), $parameters),
|
||||
];
|
||||
}
|
||||
$variables['trail'] = $trail;
|
||||
}
|
||||
|
||||
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';
|
||||
}
|
||||
}
|
38
2017/web/modules/contrib/ctools/ctools.services.yml
Normal file
38
2017/web/modules/contrib/ctools/ctools.services.yml
Normal file
|
@ -0,0 +1,38 @@
|
|||
services:
|
||||
ctools.wizard.form:
|
||||
class: Drupal\ctools\Controller\WizardFormController
|
||||
arguments: ['@controller_resolver', '@form_builder', '@ctools.wizard.factory']
|
||||
ctools.wizard.entity.form:
|
||||
class: Drupal\ctools\Controller\WizardEntityFormController
|
||||
arguments: ['@controller_resolver', '@form_builder', '@ctools.wizard.factory', '@entity.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']
|
||||
ctools.paramconverter.tempstore:
|
||||
class: Drupal\ctools\ParamConverter\TempstoreConverter
|
||||
arguments: ['@user.shared_tempstore', '@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: ['@user.shared_tempstore']
|
||||
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', '%user.tempstore.expire%']
|
||||
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,14 @@
|
|||
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)
|
||||
# version: 3.x
|
||||
# core: 8.x
|
||||
dependencies:
|
||||
- ctools
|
||||
|
||||
# Information added by Drupal.org packaging script on 2017-04-28
|
||||
version: '8.x-3.0'
|
||||
core: '8.x'
|
||||
project: 'ctools'
|
||||
datestamp: 1493401747
|
|
@ -0,0 +1,376 @@
|
|||
<?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\Cache\CacheableMetadata;
|
||||
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\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' => $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
|
||||
*/
|
||||
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
|
||||
*/
|
||||
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,
|
||||
]);
|
||||
}
|
||||
|
||||
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\ContextDefinition;
|
||||
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->entityManager->getEntityTypeLabels();
|
||||
foreach ($this->entityManager->getFieldMap() as $entity_type_id => $entity_field_map) {
|
||||
foreach ($this->entityManager->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->entityManager->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'] = [
|
||||
'entity' => new ContextDefinition('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,20 @@
|
|||
name: 'Chaos tools blocks test'
|
||||
type: module
|
||||
description: 'Support module for Chaos tools blocks tests.'
|
||||
# core: 8.x
|
||||
package: Testing
|
||||
# version: 8.0.1
|
||||
dependencies:
|
||||
- image
|
||||
- menu_ui
|
||||
- node
|
||||
- path
|
||||
- text
|
||||
- user
|
||||
features: true
|
||||
|
||||
# Information added by Drupal.org packaging script on 2017-04-28
|
||||
version: '8.x-3.0'
|
||||
core: '8.x'
|
||||
project: 'ctools'
|
||||
datestamp: 1493401747
|
|
@ -0,0 +1,132 @@
|
|||
<?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'];
|
||||
|
||||
/**
|
||||
* 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() {
|
||||
$source = \Drupal::moduleHandler()->getModule('image')->getPath() . '/sample.png';
|
||||
file_unmanaged_copy($source, 'public://sample.png');
|
||||
|
||||
/** @var \Drupal\file\FileInterface $file */
|
||||
$file = \Drupal::entityTypeManager()
|
||||
->getStorage('file')
|
||||
->create([
|
||||
'uri' => 'public://sample.png',
|
||||
]);
|
||||
$file->save();
|
||||
|
||||
/** @var \Drupal\field\FieldConfigInterface $field */
|
||||
$field = \Drupal::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,15 @@
|
|||
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: 8.x
|
||||
dependencies:
|
||||
- block
|
||||
- views
|
||||
|
||||
# Information added by Drupal.org packaging script on 2017-04-28
|
||||
version: '8.x-3.0'
|
||||
core: '8.x'
|
||||
project: 'ctools'
|
||||
datestamp: 1493401747
|
|
@ -0,0 +1,104 @@
|
|||
<?php
|
||||
|
||||
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,438 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\ctools_views\Plugin\Display;
|
||||
|
||||
use Drupal\Core\Form\FormState;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\views\Plugin\Block\ViewsBlock;
|
||||
use Drupal\views\Plugin\views\display\Block as CoreBlock;
|
||||
use Drupal\views\Plugin\views\filter\InOperator;
|
||||
|
||||
/**
|
||||
* Provides a Block display plugin that allows for greater control over Views
|
||||
* block settings.
|
||||
*/
|
||||
class Block extends CoreBlock {
|
||||
|
||||
/**
|
||||
* {@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'] = array(
|
||||
'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);
|
||||
$options = $form['allow']['#options'];
|
||||
$options['offset'] = $this->t('Pager offset');
|
||||
$options['pager'] = $this->t('Pager type');
|
||||
$options['hide_fields'] = $this->t('Hide fields');
|
||||
$options['sort_fields'] = $this->t('Reorder fields');
|
||||
$options['disable_filters'] = $this->t('Disable filters');
|
||||
$options['configure_sorts'] = $this->t('Configure sorts');
|
||||
$form['allow']['#options'] = $options;
|
||||
// Update the items_per_page if set.
|
||||
$defaults = array_filter($form['allow']['#default_value']);
|
||||
if (isset($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' => array(),
|
||||
];
|
||||
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'] : '';
|
||||
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 = array(
|
||||
'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'] = array(
|
||||
'#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(array('override', 'items_per_page')))) {
|
||||
$form_state->setValue(array('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'])) {
|
||||
$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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected function getFilterOptionsValue(array $filter, array $config) {
|
||||
$plugin_definition = \Drupal::service('plugin.manager.views.filter')->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_name => $filter) {
|
||||
if ($filter->isExposed() && !empty($filter->exposedInfo())) {
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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'] = \Drupal::request()->getRequestUri();
|
||||
}
|
||||
return parent::elementPreRender($element);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sort field config array by weight.
|
||||
*
|
||||
* @param $a
|
||||
* @param $b
|
||||
* @return int
|
||||
*/
|
||||
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,350 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\ctools_views\Tests;
|
||||
|
||||
use Drupal\views_ui\Tests\UITestBase;
|
||||
use Drupal\views\Tests\ViewTestData;
|
||||
use Drupal\Core\StringTranslation\StringTranslationTrait;
|
||||
|
||||
/**
|
||||
* Tests the ctools_views block display plugin
|
||||
* overriding 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 = array('ctools_views', 'ctools_views_test_views');
|
||||
|
||||
/**
|
||||
* Views used by this test.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $testViews = array('ctools_views_test_view');
|
||||
|
||||
/**
|
||||
* The block storage.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityStorageInterface
|
||||
*/
|
||||
protected $storage;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
ViewTestData::createTestViews(get_class($this), array('ctools_views_test_views'));
|
||||
$this->storage = $this->container->get('entity.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->assertFieldByXPath('//input[@type="number" and @name="settings[override][items_per_page]"]', NULL, 'items_per_page setting is a number field');
|
||||
// Add block to sidebar_first region with default settings.
|
||||
$edit = array();
|
||||
$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->assertEqual((string) $result[0], 'CTools Views Pager Block');
|
||||
$this->assertRaw('Showing 3 records on page 1');
|
||||
$this->assertEqual(3, count($this->xpath('//div[contains(@class, "view-display-id-block_pager")]//table/tbody/tr')));
|
||||
|
||||
// Override items per page settings.
|
||||
$edit = array();
|
||||
$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->assertEqual(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->assertEqual((string) $result[0], 'CTools Views Pager Block');
|
||||
$this->assertRaw('Showing 2 records on page 1');
|
||||
$this->assertEqual(2, count($this->xpath('//div[contains(@class, "view-display-id-block_pager")]//table/tbody/tr')));
|
||||
$this->assertEqual([1, 2], $this->xpath('//div[contains(@class, "view-display-id-block_pager")]//table//tr//td[contains(@class, "views-field-id")]'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 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->assertFieldByXPath('//input[@type="number" and @name="settings[override][pager_offset]"]', NULL, 'items_per_page setting is a number field');
|
||||
// Add block to sidebar_first region with default settings.
|
||||
$edit = array();
|
||||
$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>');
|
||||
$this->assertEqual([1, 2, 3], $this->xpath('//div[contains(@class, "view-display-id-block_pager")]//table//tr//td[contains(@class, "views-field-id")]'));
|
||||
|
||||
// Override pager offset settings.
|
||||
$edit = array();
|
||||
$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->assertEqual(1, $config['pager_offset'], "'Pager offset' is properly saved.");
|
||||
|
||||
// Assert pager offset overridden settings.
|
||||
$this->drupalGet('<front>');
|
||||
$this->assertEqual([2, 3, 4], $this->xpath('//div[contains(@class, "view-display-id-block_pager")]//table//tr//td[contains(@class, "views-field-id")]'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 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->assertFieldById('edit-settings-override-pager-view', 'view');
|
||||
$this->assertFieldById('edit-settings-override-pager-some');
|
||||
$this->assertFieldById('edit-settings-override-pager-none');
|
||||
|
||||
// Add block to sidebar_first region with default settings.
|
||||
$edit = array();
|
||||
$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->assertText('Page 1');
|
||||
$this->assertText('Next ›');
|
||||
|
||||
// Override pager settings to 'some'.
|
||||
$edit = array();
|
||||
$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->assertEqual('some', $config['pager'], "'Pager' setting is properly saved.");
|
||||
|
||||
// Assert pager overridden settings to 'some', showing no pager.
|
||||
$this->drupalGet('<front>');
|
||||
$this->assertEqual(3, count($this->xpath('//div[contains(@class, "view-display-id-block_pager")]//table/tbody/tr')));
|
||||
$this->assertNoText('Page 1');
|
||||
$this->assertNoText('Next ›');
|
||||
|
||||
// Override pager settings to 'none'.
|
||||
$edit = array();
|
||||
$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->assertEqual('none', $config['pager'], "'Pager' setting is properly saved.");
|
||||
|
||||
// Assert pager overridden settings to 'some', showing no pager.
|
||||
$this->drupalGet('<front>');
|
||||
$this->assertEqual(5, count($this->xpath('//div[contains(@class, "view-display-id-block_pager")]//table/tbody/tr')));
|
||||
$this->assertNoText('Page 1');
|
||||
$this->assertNoText('Next ›');
|
||||
}
|
||||
|
||||
/**
|
||||
* 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->assertFieldById('edit-settings-override-order-fields-id-hide');
|
||||
|
||||
// Add block to sidebar_first region with default settings.
|
||||
$edit = array();
|
||||
$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->assertEqual(5, count($this->xpath('//div[contains(@class, "view-display-id-block_fields")]//table//td[contains(@class, "views-field-id")]')));
|
||||
|
||||
// Override hide_fields settings.
|
||||
$edit = array();
|
||||
$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->assertEqual(1, $config['fields']['id']['hide'], "'hide_fields' setting is properly saved.");
|
||||
$this->assertEqual(0, $config['fields']['name']['hide'], "'hide_fields' setting is properly saved.");
|
||||
|
||||
// Assert hide_fields overridden settings.
|
||||
$this->drupalGet('<front>');
|
||||
$this->assertEqual(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->assertFieldById('edit-settings-override-order-fields-id-weight', 0);
|
||||
|
||||
// Add block to sidebar_first region with default settings.
|
||||
$edit = array();
|
||||
$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->assertEqual(0, count($this->xpath('count(//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 = array();
|
||||
$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->assertEqual(-46, $config['fields']['id']['weight'], "'sort_fields' setting is properly saved.");
|
||||
$this->assertEqual(-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->assertEqual(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 outpu
|
||||
$name1_element = $this->xpath('//div[contains(@class, "view-display-id-block_fields")]//table//tr[1]/td[contains(@class, "views-field-name")]/text()');
|
||||
$name1 = (string) $name1_element[0];
|
||||
$this->assertEqual("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")]/text()');
|
||||
$name2 = (string) $name2_element[0];
|
||||
$this->assertEqual("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->assertFieldById('edit-settings-override-filters-status-disable');
|
||||
$this->assertFieldById('edit-settings-override-filters-job-disable');
|
||||
|
||||
// Add block to sidebar_first region with default settings.
|
||||
$edit = array();
|
||||
$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->assertFieldByXPath('//select[@name="status"]');
|
||||
$this->assertFieldByXPath('//input[@name="job"]');
|
||||
|
||||
// Override disable_filters settings.
|
||||
$edit = array();
|
||||
$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->assertEqual(1, $config['filter']['status']['disable'], "'disable_filters' setting is properly saved.");
|
||||
$this->assertEqual(1, $config['filter']['job']['disable'], "'disable_filters' setting is properly saved.");
|
||||
|
||||
// Assert disable_filters overridden settings.
|
||||
$this->drupalGet('<front>');
|
||||
$this->assertNoFieldByXPath('//select[@name="status"]');
|
||||
$this->assertNoFieldByXPath('//input[@name="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->assertFieldByXPath('//input[@name="settings[override][sort][id][order]"]');
|
||||
|
||||
// Add block to sidebar_first region with default settings.
|
||||
$edit = array();
|
||||
$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]/text()');
|
||||
$value = (string) $element[0];
|
||||
$this->assertEqual("1", trim($value));
|
||||
|
||||
// Override configure_sorts settings.
|
||||
$edit = array();
|
||||
$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->assertEqual("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]/text()');
|
||||
$value = (string) $element[0];
|
||||
$this->assertEqual("5", trim($value));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
name: 'CTools Views test views'
|
||||
type: module
|
||||
description: 'Provides default views for CTools Views tests.'
|
||||
package: Testing
|
||||
# core: 8.x
|
||||
dependencies:
|
||||
- views
|
||||
- block
|
||||
- entity_test
|
||||
- ctools_views
|
||||
- text
|
||||
- user
|
||||
- node
|
||||
- taxonomy
|
||||
|
||||
# Information added by Drupal.org packaging script on 2017-04-28
|
||||
version: '8.x-3.0'
|
||||
core: '8.x'
|
||||
project: 'ctools'
|
||||
datestamp: 1493401747
|
|
@ -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: true
|
||||
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: true
|
||||
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: true
|
||||
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: true
|
||||
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: true
|
||||
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,9 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\ctools\Access;
|
||||
|
||||
use Drupal\Core\Session\AccountInterface;
|
||||
|
||||
interface AccessInterface {
|
||||
public function access(AccountInterface $account);
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\ctools\Access;
|
||||
|
||||
|
||||
use Drupal\Core\Access\AccessResult;
|
||||
use Drupal\Core\Routing\Access\AccessInterface as CoreAccessInterface;
|
||||
use Drupal\Core\Routing\RouteMatch;
|
||||
use Drupal\Core\Session\AccountInterface;
|
||||
use Drupal\ctools\Access\AccessInterface as CToolsAccessInterface;
|
||||
use Drupal\user\SharedTempStoreFactory;
|
||||
use Symfony\Component\Routing\Route;
|
||||
|
||||
class TempstoreAccess implements CoreAccessInterface {
|
||||
|
||||
/**
|
||||
* The shared tempstore factory.
|
||||
*
|
||||
* @var \Drupal\user\SharedTempStoreFactory
|
||||
*/
|
||||
protected $tempstore;
|
||||
|
||||
public function __construct(SharedTempStoreFactory $tempstore) {
|
||||
$this->tempstore = $tempstore;
|
||||
}
|
||||
|
||||
protected function getTempstore() {
|
||||
return $this->tempstore;
|
||||
}
|
||||
|
||||
public function access(Route $route, RouteMatch $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,23 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\ctools\Ajax;
|
||||
|
||||
use Drupal\Core\Ajax\OpenModalDialogCommand;
|
||||
|
||||
class OpenModalWizardCommand extends OpenModalDialogCommand {
|
||||
|
||||
public function __construct($object, $tempstore_id, array $parameters = array(), array $dialog_options = array(), $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 = array());
|
||||
|
||||
/**
|
||||
* Removes constraints for this condition from the injected contexts.
|
||||
*
|
||||
* @param \Drupal\Core\Plugin\Context\ContextInterface[] $contexts
|
||||
*
|
||||
* @return NULL
|
||||
*/
|
||||
public function removeConstraints(array $contexts = array());
|
||||
|
||||
}
|
|
@ -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;
|
||||
|
||||
/**
|
||||
* @todo.
|
||||
*/
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
50
2017/web/modules/contrib/ctools/src/ContextMapper.php
Normal file
50
2017/web/modules/contrib/ctools/src/ContextMapper.php
Normal file
|
@ -0,0 +1,50 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\ctools;
|
||||
|
||||
use Drupal\Core\Entity\EntityRepositoryInterface;
|
||||
use Drupal\Core\Plugin\Context\Context;
|
||||
use Drupal\Core\Plugin\Context\ContextDefinition;
|
||||
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) {
|
||||
$context_definition = new ContextDefinition($context_configuration['type'], $context_configuration['label'], TRUE, FALSE, $context_configuration['description']);
|
||||
if (strpos($context_configuration['type'], 'entity:') === 0) {
|
||||
$context = new EntityLazyLoadContext($context_definition, $this->entityRepository, $context_configuration['value']);
|
||||
}
|
||||
else {
|
||||
$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\Controller\ControllerResolverInterface;
|
||||
use Drupal\Core\Entity\EntityManagerInterface;
|
||||
use Drupal\Core\Form\FormBuilderInterface;
|
||||
use Drupal\Core\Routing\RouteMatchInterface;
|
||||
use Drupal\ctools\Wizard\WizardFactoryInterface;
|
||||
|
||||
/**
|
||||
* Wrapping controller for wizard forms that serve as the main page body.
|
||||
*/
|
||||
class WizardEntityFormController extends WizardFormController {
|
||||
|
||||
/**
|
||||
* The entity manager service.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityManagerInterface
|
||||
*/
|
||||
protected $entityManager;
|
||||
|
||||
/**
|
||||
* @param \Drupal\Core\Controller\ControllerResolverInterface $controller_resolver
|
||||
* The controller 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\EntityManagerInterface $manager
|
||||
* The entity manager.
|
||||
*/
|
||||
public function __construct(ControllerResolverInterface $controller_resolver, FormBuilderInterface $form_builder, WizardFactoryInterface $wizard_factory, EntityManagerInterface $manager) {
|
||||
parent::__construct($controller_resolver, $form_builder, $wizard_factory);
|
||||
$this->entityManager = $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->entityManager->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,82 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\ctools\Controller;
|
||||
|
||||
use Drupal\Core\Controller\ControllerResolverInterface;
|
||||
use Drupal\Core\Controller\FormController;
|
||||
use Drupal\Core\Form\FormBuilderInterface;
|
||||
use Drupal\Core\Routing\RouteMatchInterface;
|
||||
use Drupal\ctools\Wizard\FormWizardInterface;
|
||||
use Drupal\ctools\Wizard\WizardFactoryInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
/**
|
||||
* 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\user\SharedTempStoreFactory
|
||||
*/
|
||||
protected $tempstore;
|
||||
|
||||
/**
|
||||
* The event dispatcher.
|
||||
*
|
||||
* @var \Symfony\Component\EventDispatcher\EventDispatcherInterface
|
||||
*/
|
||||
protected $dispatcher;
|
||||
|
||||
/**
|
||||
* @param \Drupal\Core\Controller\ControllerResolverInterface $controller_resolver
|
||||
* The controller resolver.
|
||||
* @param \Drupal\Core\Form\FormBuilderInterface $form_builder
|
||||
* The form builder.
|
||||
* @param \Drupal\ctools\Wizard\WizardFactoryInterface $wizard_factory
|
||||
* The wizard factory.
|
||||
*/
|
||||
public function __construct(ControllerResolverInterface $controller_resolver, FormBuilderInterface $form_builder, WizardFactoryInterface $wizard_factory) {
|
||||
parent::__construct($controller_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);
|
||||
}
|
||||
|
||||
}
|
41
2017/web/modules/contrib/ctools/src/Event/WizardEvent.php
Normal file
41
2017/web/modules/contrib/ctools/src/Event/WizardEvent.php
Normal file
|
@ -0,0 +1,41 @@
|
|||
<?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;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
43
2017/web/modules/contrib/ctools/src/Form/AjaxFormTrait.php
Normal file
43
2017/web/modules/contrib/ctools/src/Form/AjaxFormTrait.php
Normal file
|
@ -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',
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
182
2017/web/modules/contrib/ctools/src/Form/ConditionConfigure.php
Normal file
182
2017/web/modules/contrib/ctools/src/Form/ConditionConfigure.php
Normal file
|
@ -0,0 +1,182 @@
|
|||
<?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\user\SharedTempStoreFactory;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
/**
|
||||
* Base class for condition configur operations.
|
||||
*/
|
||||
abstract class ConditionConfigure extends FormBase {
|
||||
|
||||
/**
|
||||
* @var \Drupal\user\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('user.shared_tempstore'), $container->get('plugin.manager.condition'));
|
||||
}
|
||||
|
||||
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);
|
||||
$response->addCommand(new RedirectCommand($this->url($route_name, $route_parameters)));
|
||||
$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);
|
||||
|
||||
}
|
210
2017/web/modules/contrib/ctools/src/Form/ConditionDelete.php
Normal file
210
2017/web/modules/contrib/ctools/src/Form/ConditionDelete.php
Normal file
|
@ -0,0 +1,210 @@
|
|||
<?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\user\SharedTempStoreFactory;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
abstract class ConditionDelete extends ConfirmFormBase {
|
||||
|
||||
/**
|
||||
* @var \Drupal\user\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('user.shared_tempstore'), $container->get('plugin.manager.condition'));
|
||||
}
|
||||
|
||||
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'] = array('#markup' => $this->getDescription());
|
||||
$form [$this->getFormName()] = array('#type' => 'hidden', '#value' => 1);
|
||||
|
||||
// By default, render the form using theme_confirm_form().
|
||||
if (!isset($form ['#theme'])) {
|
||||
$form ['#theme'] = 'confirm_form';
|
||||
}
|
||||
$form['actions'] = array('#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?', array(
|
||||
'@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 array(
|
||||
'submit' => array(
|
||||
'#type' => 'submit',
|
||||
'#value' => $this->getConfirmText(),
|
||||
'#validate' => array(
|
||||
array($this, 'validateForm'),
|
||||
),
|
||||
'#submit' => array(
|
||||
array($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);
|
||||
|
||||
}
|
254
2017/web/modules/contrib/ctools/src/Form/ContextConfigure.php
Normal file
254
2017/web/modules/contrib/ctools/src/Form/ContextConfigure.php
Normal file
|
@ -0,0 +1,254 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\ctools\Form;
|
||||
|
||||
|
||||
use Drupal\Core\Ajax\AjaxResponse;
|
||||
use Drupal\Core\Ajax\CloseModalDialogCommand;
|
||||
use Drupal\Core\Ajax\RedirectCommand;
|
||||
use Drupal\Core\Entity\Entity;
|
||||
use Drupal\Core\Entity\Plugin\DataType\EntityAdapter;
|
||||
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\Url;
|
||||
use Drupal\user\SharedTempStoreFactory;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
abstract class ContextConfigure extends FormBase {
|
||||
|
||||
/**
|
||||
* @var \Drupal\user\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('user.shared_tempstore'));
|
||||
}
|
||||
|
||||
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_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 {
|
||||
$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 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');
|
||||
$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 = \Drupal::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);
|
||||
|
||||
}
|
85
2017/web/modules/contrib/ctools/src/Form/ContextDelete.php
Normal file
85
2017/web/modules/contrib/ctools/src/Form/ContextDelete.php
Normal file
|
@ -0,0 +1,85 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\ctools\Form;
|
||||
|
||||
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\Core\Form\ConfirmFormBase;
|
||||
use Drupal\user\SharedTempStoreFactory;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
/**
|
||||
* Provides a form for deleting an contexts and relationships.
|
||||
*/
|
||||
abstract class ContextDelete extends ConfirmFormBase {
|
||||
|
||||
/**
|
||||
* @var \Drupal\user\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('user.shared_tempstore'));
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
224
2017/web/modules/contrib/ctools/src/Form/ManageConditions.php
Normal file
224
2017/web/modules/contrib/ctools/src/Form/ManageConditions.php
Normal file
|
@ -0,0 +1,224 @@
|
|||
<?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;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $machine_name;
|
||||
|
||||
public static function create(ContainerInterface $container) {
|
||||
return new static($container->get('plugin.manager.condition'));
|
||||
}
|
||||
|
||||
function __construct(PluginManagerInterface $manager) {
|
||||
$this->manager = $manager;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@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'] = array(
|
||||
'#type' => 'markup',
|
||||
'#prefix' => '<div id="configured-conditions">',
|
||||
'#suffix' => '</div>',
|
||||
'#theme' => 'table',
|
||||
'#header' => array($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 = \Drupal::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'));
|
||||
$content['submit']['#attached']['drupalSettings']['ajax'][$content['submit']['#id']]['url'] = $this->url($this->getAddRoute($cached_values), $route_parameters, ['query' => [FormBuilderInterface::AJAX_FORM_REQUEST => TRUE]]);
|
||||
$response = new AjaxResponse();
|
||||
$response->addCommand(new OpenModalDialogCommand($this->t('Configure Required Context'), $content, array('width' => '700')));
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $cached_values
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function renderRows($cached_values) {
|
||||
$configured_conditions = array();
|
||||
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 = array(
|
||||
'#type' => 'operations',
|
||||
'#links' => $this->getOperations($route_name, $route_parameters),
|
||||
);
|
||||
$configured_conditions[] = array(
|
||||
$instance->getPluginId(),
|
||||
$instance->summary(),
|
||||
'operations' => [
|
||||
'data' => $build,
|
||||
],
|
||||
);
|
||||
}
|
||||
return $configured_conditions;
|
||||
}
|
||||
|
||||
protected function getOperations($route_name_base, array $route_parameters = array()) {
|
||||
$operations['edit'] = array(
|
||||
'title' => $this->t('Edit'),
|
||||
'url' => new Url($route_name_base . '.edit', $route_parameters),
|
||||
'weight' => 10,
|
||||
'attributes' => array(
|
||||
'class' => ['use-ajax'],
|
||||
'data-dialog-type' => 'modal',
|
||||
'data-dialog-options' => Json::encode([
|
||||
'width' => 700,
|
||||
]),
|
||||
),
|
||||
);
|
||||
$route_parameters['id'] = $route_parameters['condition'];
|
||||
$operations['delete'] = array(
|
||||
'title' => $this->t('Delete'),
|
||||
'url' => new Url($route_name_base . '.delete', $route_parameters),
|
||||
'weight' => 100,
|
||||
'attributes' => array(
|
||||
'class' => array('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 appeneded 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);
|
||||
|
||||
}
|
327
2017/web/modules/contrib/ctools/src/Form/ManageContext.php
Normal file
327
2017/web/modules/contrib/ctools/src/Form/ManageContext.php
Normal file
|
@ -0,0 +1,327 @@
|
|||
<?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 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;
|
||||
|
||||
/**
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function create(ContainerInterface $container) {
|
||||
return new static($container->get('typed_data_manager'), $container->get('form_builder'));
|
||||
}
|
||||
|
||||
/**
|
||||
* ManageContext constructor.
|
||||
*
|
||||
* @param \Drupal\Core\TypedData\TypedDataManagerInterface $typed_data_manager
|
||||
* The typed data manager.
|
||||
* @param \Drupal\Core\Form\FormBuilderInterface $form_builder
|
||||
* The form builder.
|
||||
*/
|
||||
public function __construct(TypedDataManagerInterface $typed_data_manager, FormBuilderInterface $form_builder) {
|
||||
$this->typedDataManager = $typed_data_manager;
|
||||
$this->formBuilder = $form_builder;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* {@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'] = array(
|
||||
'#type' => 'markup',
|
||||
'#prefix' => '<div id="configured-contexts">',
|
||||
'#suffix' => '</div>',
|
||||
'#theme' => 'table',
|
||||
'#header' => array($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);
|
||||
$content['submit']['#attached']['drupalSettings']['ajax'][$content['submit']['#id']]['url'] = $this->url($this->getContextAddRoute($cached_values), $route_parameters, ['query' => [FormBuilderInterface::AJAX_FORM_REQUEST => TRUE]]);
|
||||
$response = new AjaxResponse();
|
||||
$response->addCommand(new OpenModalDialogCommand($this->t('Add new context'), $content, array('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);
|
||||
$content['submit']['#attached']['drupalSettings']['ajax'][$content['submit']['#id']]['url'] = $this->url($this->getRelationshipAddRoute($cached_values), $route_parameters, ['query' => [FormBuilderInterface::AJAX_FORM_REQUEST => TRUE]]);
|
||||
$response = new AjaxResponse();
|
||||
$response->addCommand(new OpenModalDialogCommand($this->t('Configure Relationship'), $content, array('width' => '700')));
|
||||
return $response;
|
||||
}
|
||||
|
||||
protected function getAvailableRelationships($cached_values) {
|
||||
/** @var \Drupal\ctools\TypedDataResolver $resolver */
|
||||
$resolver = \Drupal::service('ctools.typed_data.resolver');
|
||||
return $resolver->getTokensForContexts($this->getContexts($cached_values));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $cached_values
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function renderRows($cached_values) {
|
||||
$contexts = array();
|
||||
foreach ($this->getContexts($cached_values) as $row => $context) {
|
||||
list($route_name, $route_parameters) = $this->getContextOperationsRouteInfo($cached_values, $this->machine_name, $row);
|
||||
$build = array(
|
||||
'#type' => 'operations',
|
||||
'#links' => $this->getOperations($cached_values, $row, $route_name, $route_parameters),
|
||||
);
|
||||
$contexts[$row] = array(
|
||||
$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 = array()) {
|
||||
$operations = [];
|
||||
if ($this->isEditableContext($cached_values, $row)) {
|
||||
$operations['edit'] = array(
|
||||
'title' => $this->t('Edit'),
|
||||
'url' => new Url($route_name_base . '.edit', $route_parameters),
|
||||
'weight' => 10,
|
||||
'attributes' => array(
|
||||
'class' => ['use-ajax'],
|
||||
'data-dialog-type' => 'modal',
|
||||
'data-dialog-options' => Json::encode([
|
||||
'width' => 700,
|
||||
]),
|
||||
),
|
||||
);
|
||||
$operations['delete'] = array(
|
||||
'title' => $this->t('Delete'),
|
||||
'url' => new Url($route_name_base . '.delete', $route_parameters),
|
||||
'weight' => 100,
|
||||
'attributes' => array(
|
||||
'class' => array('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,205 @@
|
|||
<?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;
|
||||
|
||||
abstract class ManageResolverRelationships extends FormBase {
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $machine_name;
|
||||
|
||||
/**
|
||||
* An array of property types that are eligible as relationships.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $property_types = [];
|
||||
|
||||
/**
|
||||
* {@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'] = array(
|
||||
'#type' => 'markup',
|
||||
'#prefix' => '<div id="configured-relationships">',
|
||||
'#suffix' => '</div>',
|
||||
'#theme' => 'table',
|
||||
'#header' => array($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);
|
||||
}
|
||||
}
|
||||
|
||||
public function addRelationship(array &$form, FormStateInterface $form_state) {
|
||||
$relationship = $form_state->getValue('relationships');
|
||||
$content = \Drupal::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);
|
||||
$content['submit']['#attached']['drupalSettings']['ajax'][$content['submit']['#id']]['url'] = $this->url($this->getAddRoute($cached_values), $route_parameters, ['query' => [FormBuilderInterface::AJAX_FORM_REQUEST => TRUE]]);
|
||||
$response = new AjaxResponse();
|
||||
$response->addCommand(new OpenModalDialogCommand($this->t('Configure Relationship'), $content, array('width' => '700')));
|
||||
return $response;
|
||||
}
|
||||
|
||||
protected function getAvailableRelationships($cached_values) {
|
||||
/** @var \Drupal\ctools\TypedDataResolver $resolver */
|
||||
$resolver = \Drupal::service('ctools.typed_data.resolver');
|
||||
return $resolver->getTokensForContexts($this->getContexts($cached_values));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $cached_values
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function renderRows($cached_values) {
|
||||
$contexts = array();
|
||||
foreach ($this->getContexts($cached_values) as $row => $context) {
|
||||
list($route_name, $route_parameters) = $this->getRelationshipOperationsRouteInfo($cached_values, $this->machine_name, $row);
|
||||
$build = array(
|
||||
'#type' => 'operations',
|
||||
'#links' => $this->getOperations($cached_values, $row, $route_name, $route_parameters),
|
||||
);
|
||||
$contexts[$row] = array(
|
||||
$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 = array()) {
|
||||
// Base contexts will not be a : separated and generated relationships should have 3 parts.
|
||||
if (count(explode(':', $row)) < 2) {
|
||||
return [];
|
||||
}
|
||||
$operations['edit'] = array(
|
||||
'title' => $this->t('Edit'),
|
||||
'url' => new Url($route_name_base . '.edit', $route_parameters),
|
||||
'weight' => 10,
|
||||
'attributes' => array(
|
||||
'class' => ['use-ajax'],
|
||||
'data-dialog-type' => 'modal',
|
||||
'data-dialog-options' => Json::encode([
|
||||
'width' => 700,
|
||||
]),
|
||||
),
|
||||
);
|
||||
$route_parameters['id'] = $route_parameters['context'];
|
||||
$operations['delete'] = array(
|
||||
'title' => $this->t('Delete'),
|
||||
'url' => new Url($route_name_base . '.delete', $route_parameters),
|
||||
'weight' => 100,
|
||||
'attributes' => array(
|
||||
'class' => array('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
|
||||
*/
|
||||
abstract protected function getContextClass($cached_values);
|
||||
|
||||
/**
|
||||
* The route to which relationship 'add' actions should submit.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
abstract protected function getAddRoute($cached_values);
|
||||
|
||||
/**
|
||||
* Provide the tempstore id for your specified use case.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
abstract protected function getTempstoreId();
|
||||
|
||||
/**
|
||||
* @param $cached_values
|
||||
*
|
||||
* @return \Drupal\Core\Plugin\Context\ContextInterface[]
|
||||
*/
|
||||
abstract protected function getContexts($cached_values);
|
||||
|
||||
/**
|
||||
* @param string $cached_values
|
||||
* @param string $machine_name
|
||||
* @param string $row
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
abstract protected function getRelationshipOperationsRouteInfo($cached_values, $machine_name, $row);
|
||||
|
||||
}
|
|
@ -0,0 +1,152 @@
|
|||
<?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\user\SharedTempStoreFactory;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
abstract class RelationshipConfigure extends FormBase {
|
||||
|
||||
/**
|
||||
* @var \Drupal\user\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('user.shared_tempstore'), $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();
|
||||
$response->addCommand(new RedirectCommand($this->url($route_name, $route_parameters)));
|
||||
$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);
|
||||
|
||||
}
|
212
2017/web/modules/contrib/ctools/src/Form/RequiredContext.php
Normal file
212
2017/web/modules/contrib/ctools/src/Form/RequiredContext.php
Normal file
|
@ -0,0 +1,212 @@
|
|||
<?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;
|
||||
|
||||
abstract class RequiredContext extends FormBase {
|
||||
|
||||
/**
|
||||
* @var \Drupal\Core\TypedData\TypedDataManager
|
||||
*/
|
||||
protected $typedDataManager;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $machine_name;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function create(ContainerInterface $container) {
|
||||
return new static($container->get('typed_data_manager'));
|
||||
}
|
||||
|
||||
public function __construct(PluginManagerInterface $typed_data_manager) {
|
||||
$this->typedDataManager = $typed_data_manager;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@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'] = array(
|
||||
'#type' => 'markup',
|
||||
'#prefix' => '<div id="configured-contexts">',
|
||||
'#suffix' => '</div>',
|
||||
'#theme' => 'table',
|
||||
'#header' => array($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 = \Drupal::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, array('width' => '700')));
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $cached_values
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function renderContexts($cached_values) {
|
||||
$configured_contexts = array();
|
||||
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 = array(
|
||||
'#type' => 'operations',
|
||||
'#links' => $this->getOperations($route_name, $route_parameters),
|
||||
);
|
||||
$configured_contexts[] = array(
|
||||
$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 = array()) {
|
||||
$operations['edit'] = array(
|
||||
'title' => $this->t('Edit'),
|
||||
'url' => new Url($route_name_base . '.edit', $route_parameters),
|
||||
'weight' => 10,
|
||||
'attributes' => array(
|
||||
'class' => array('use-ajax'),
|
||||
'data-accepts' => 'application/vnd.drupal-modal',
|
||||
'data-dialog-options' => json_encode(array(
|
||||
'width' => 700,
|
||||
)),
|
||||
),
|
||||
'ajax' => [
|
||||
''
|
||||
],
|
||||
);
|
||||
$route_parameters['id'] = $route_parameters['context'];
|
||||
$operations['delete'] = array(
|
||||
'title' => $this->t('Delete'),
|
||||
'url' => new Url($route_name_base . '.delete', $route_parameters),
|
||||
'weight' => 100,
|
||||
'attributes' => array(
|
||||
'class' => array('use-ajax'),
|
||||
'data-accepts' => 'application/vnd.drupal-modal',
|
||||
'data-dialog-options' => json_encode(array(
|
||||
'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 appeneded 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\user\SharedTempStoreFactory;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
/**
|
||||
* Base class for adding a required contexts step to your wizard.
|
||||
*/
|
||||
abstract class RequiredContextDelete extends ConfirmFormBase {
|
||||
|
||||
/**
|
||||
* @var \Drupal\user\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('user.shared_tempstore'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Drupal\user\SharedTempStoreFactory $tempstore
|
||||
*/
|
||||
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'] = array('#markup' => $this->getDescription());
|
||||
$form [$this->getFormName()] = array('#type' => 'hidden', '#value' => 1);
|
||||
|
||||
// By default, render the form using theme_confirm_form().
|
||||
if (!isset($form ['#theme'])) {
|
||||
$form ['#theme'] = 'confirm_form';
|
||||
}
|
||||
$form['actions'] = array('#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?', array(
|
||||
'@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 array(
|
||||
'submit' => array(
|
||||
'#type' => 'submit',
|
||||
'#value' => $this->getConfirmText(),
|
||||
'#validate' => array(
|
||||
array($this, 'validate'),
|
||||
),
|
||||
'#submit' => array(
|
||||
array($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,182 @@
|
|||
<?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\user\SharedTempStoreFactory;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
abstract class ResolverRelationshipConfigure extends FormBase {
|
||||
|
||||
/**
|
||||
* @var \Drupal\user\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('user.shared_tempstore'));
|
||||
}
|
||||
|
||||
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);
|
||||
$response->addCommand(new RedirectCommand($this->url($route_name, $route_parameters)));
|
||||
$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\user\SharedTempStoreFactory;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
abstract class ResolverRelationshipDelete extends ConfirmFormBase {
|
||||
|
||||
/**
|
||||
* @var \Drupal\user\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('user.shared_tempstore'), $container->get('ctools.typed_data.resolver'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Drupal\user\SharedTempStoreFactory $tempstore
|
||||
* The shared tempstore.
|
||||
* @param \Drupal\ctools\TypedDataResolver $resolver
|
||||
* The 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'] = array('#markup' => $this->getDescription());
|
||||
$form [$this->getFormName()] = array('#type' => 'hidden', '#value' => 1);
|
||||
|
||||
// By default, render the form using theme_confirm_form().
|
||||
if (!isset($form ['#theme'])) {
|
||||
$form ['#theme'] = 'confirm_form';
|
||||
}
|
||||
$form['actions'] = array('#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 array(
|
||||
'submit' => array(
|
||||
'#type' => 'submit',
|
||||
'#value' => $this->getConfirmText(),
|
||||
'#validate' => array(
|
||||
array($this, 'validate'),
|
||||
),
|
||||
'#submit' => array(
|
||||
array($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,169 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\ctools\ParamConverter;
|
||||
|
||||
use Drupal\Component\Utility\NestedArray;
|
||||
use Drupal\Core\Entity\EntityInterface;
|
||||
use Drupal\Core\Entity\EntityTypeManagerInterface;
|
||||
use Drupal\Core\ParamConverter\ParamConverterInterface;
|
||||
use Drupal\user\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\user\SharedTempStoreFactory
|
||||
*/
|
||||
protected $tempstore;
|
||||
|
||||
/**
|
||||
* The entity type manager.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
|
||||
*/
|
||||
protected $entityTypeManager;
|
||||
|
||||
/**
|
||||
* Constructs a TempstoreConverter.
|
||||
*
|
||||
* @param \Drupal\user\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;
|
||||
}
|
||||
|
||||
}
|
105
2017/web/modules/contrib/ctools/src/Plugin/Block/EntityView.php
Normal file
105
2017/web/modules/contrib/ctools/src/Plugin/Block/EntityView.php
Normal file
|
@ -0,0 +1,105 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\ctools\Plugin\Block;
|
||||
|
||||
use Drupal\Core\Block\BlockBase;
|
||||
use Drupal\Core\Cache\CacheableMetadata;
|
||||
use Drupal\Core\Entity\EntityManagerInterface;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
|
||||
use Drupal\Core\Plugin\ContextAwarePluginInterface;
|
||||
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 manager.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityManagerInterface
|
||||
*/
|
||||
protected $entityManager;
|
||||
|
||||
/**
|
||||
* 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\EntityManagerInterface $entity_manager
|
||||
* The entity manager.
|
||||
*/
|
||||
public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityManagerInterface $entity_manager) {
|
||||
parent::__construct($configuration, $plugin_id, $plugin_definition);
|
||||
|
||||
$this->entityManager = $entity_manager;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
|
||||
return new static(
|
||||
$configuration,
|
||||
$plugin_id,
|
||||
$plugin_definition,
|
||||
$container->get('entity.manager')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function defaultConfiguration() {
|
||||
return [
|
||||
'view_mode' => 'default',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function blockForm($form, FormStateInterface $form_state) {
|
||||
$form['view_mode'] = [
|
||||
'#type' => 'select',
|
||||
'#options' => $this->entityManager->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 build() {
|
||||
/** @var $entity \Drupal\Core\Entity\EntityInterface */
|
||||
$entity = $this->getContextValue('entity');
|
||||
|
||||
$view_builder = $this->entityManager->getViewBuilder($entity->getEntityTypeId());
|
||||
$build = $view_builder->view($entity, $this->configuration['view_mode']);
|
||||
|
||||
CacheableMetadata::createFromObject($this->getContext('entity'))
|
||||
->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);
|
||||
|
||||
}
|
130
2017/web/modules/contrib/ctools/src/Plugin/BlockVariantTrait.php
Normal file
130
2017/web/modules/contrib/ctools/src/Plugin/BlockVariantTrait.php
Normal file
|
@ -0,0 +1,130 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\ctools\Plugin;
|
||||
|
||||
/**
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* @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);
|
||||
return $configuration['uuid'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @see \Drupal\ctools\Plugin\BlockVariantInterface::removeBlock()
|
||||
*/
|
||||
public function removeBlock($block_id) {
|
||||
$this->getBlockCollection()->removeInstanceId($block_id);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see \Drupal\ctools\Plugin\BlockVariantInterface::updateBlock()
|
||||
*/
|
||||
public function updateBlock($block_id, array $configuration) {
|
||||
$existing_configuration = $this->getBlock($block_id)->getConfiguration();
|
||||
$this->getBlockCollection()->setInstanceConfiguration($block_id, $configuration + $existing_configuration);
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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,160 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\ctools\Plugin\Condition;
|
||||
|
||||
use Drupal\Core\Condition\ConditionPluginBase;
|
||||
use Drupal\Core\Entity\EntityTypeBundleInfoInterface;
|
||||
use Drupal\Core\Entity\EntityTypeManagerInterface;
|
||||
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 = array();
|
||||
$bundles = $this->entityTypeBundleInfo->getBundleInfo($this->bundleOf->id());
|
||||
foreach ($bundles as $id => $info) {
|
||||
$options[$id] = $info['label'];
|
||||
}
|
||||
$form['bundles'] = array(
|
||||
'#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());
|
||||
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', array('@bundle_type' => $this->bundleOf->getBundleLabel(), '@bundles' => $bundles, '@last' => $last));
|
||||
}
|
||||
$bundle = reset($this->configuration['bundles']);
|
||||
return $this->t('@bundle_type is @bundle', array('@bundle_type' => $this->bundleOf->getBundleLabel(), '@bundle' => $bundle));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function defaultConfiguration() {
|
||||
return array('bundles' => array()) + parent::defaultConfiguration();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @param \Drupal\Core\Plugin\Context\ContextInterface[] $contexts
|
||||
*/
|
||||
public function applyConstraints(array $contexts = array()) {
|
||||
// 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 = array()) {
|
||||
// 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,41 @@
|
|||
<?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 = array()) {
|
||||
// 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 = array()) {
|
||||
// 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\ContextDefinition;
|
||||
|
||||
/**
|
||||
* Deriver that creates a condition for each entity type with bundles.
|
||||
*/
|
||||
class EntityBundle extends EntityDeriverBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getDerivativeDefinitions($base_plugin_definition) {
|
||||
foreach ($this->entityManager->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'] = [
|
||||
"$entity_type_id" => new ContextDefinition('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->entityManager->getDefinition($bundle_entity_type)->getLabel();
|
||||
}
|
||||
|
||||
return $this->t('@label bundle', ['@label' => $fallback]);
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\ctools\Plugin\Deriver;
|
||||
|
||||
|
||||
use Drupal\Component\Plugin\Derivative\DeriverBase;
|
||||
use Drupal\Core\Entity\EntityManagerInterface;
|
||||
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 manager.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityManagerInterface
|
||||
*/
|
||||
protected $entityManager;
|
||||
|
||||
/**
|
||||
* Constructs new EntityViewDeriver.
|
||||
*
|
||||
* @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
|
||||
* The entity manager.
|
||||
* @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation
|
||||
* The string translation service.
|
||||
*/
|
||||
public function __construct(EntityManagerInterface $entity_manager, TranslationInterface $string_translation) {
|
||||
$this->entityManager = $entity_manager;
|
||||
$this->stringTranslation = $string_translation;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function create(ContainerInterface $container, $base_plugin_id) {
|
||||
return new static(
|
||||
$container->get('entity.manager'),
|
||||
$container->get('string_translation')
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\ctools\Plugin\Deriver;
|
||||
|
||||
use Drupal\Core\Plugin\Context\ContextDefinition;
|
||||
|
||||
/**
|
||||
* Provides entity view block definitions for each entity type.
|
||||
*/
|
||||
class EntityViewDeriver extends EntityDeriverBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getDerivativeDefinitions($base_plugin_definition) {
|
||||
foreach ($this->entityManager->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'] = [
|
||||
'entity' => new ContextDefinition('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,113 @@
|
|||
<?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,75 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\ctools\Plugin\Deriver;
|
||||
|
||||
|
||||
use Drupal\Core\Plugin\Context\ContextDefinition;
|
||||
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;
|
||||
$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'] = [
|
||||
'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']['base'];
|
||||
$bundles = $context_definition->getConstraint('Bundle') ?: [];
|
||||
$bundles = array_merge($bundles, $base_definition->getConstraint('Bundle'));
|
||||
$context_definition->addConstraint('Bundle', $bundles);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,226 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\ctools\Plugin\DisplayVariant;
|
||||
|
||||
use Drupal\Component\Uuid\UuidInterface;
|
||||
use Drupal\Core\Block\BlockManager;
|
||||
use Drupal\Core\Cache\RefinableCacheableDependencyInterface;
|
||||
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\Render\Element;
|
||||
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, RefinableCacheableDependencyInterface {
|
||||
|
||||
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\BlockManager $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, BlockManager $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);
|
||||
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show more
Reference in a new issue