diff --git a/composer.json b/composer.json index c5ee74440dd445c33755615609a5ebbc0b92db44..64108d4c45b2ae4bbd8b9b80fc81e590ba669996 100644 --- a/composer.json +++ b/composer.json @@ -114,6 +114,7 @@ "drupal/media_entity_browser": "2.0-alpha1", "drupal/media_entity_twitter": "2.0-alpha2", "drupal/menu_block": "1.4", + "drupal/menu_breadcrumb": "^1.7", "drupal/metatag": "^1.7", "drupal/migrate_plus": "4.0", "drupal/migrate_tools": "4.0", diff --git a/composer.lock b/composer.lock index 04547775f4b96d0ea2f794e957bb6e93a80a79bd..7d111757328b028dc652d38f195f2624c1c2b468 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "content-hash": "83a94eb61f75186d89855ca8fa185b2e", + "content-hash": "ea81419b7788ac165090f6f773f17c7a", "packages": [ { "name": "alchemy/zippy", @@ -4523,6 +4523,73 @@ "source": "http://cgit.drupalcode.org/menu_block" } }, + { + "name": "drupal/menu_breadcrumb", + "version": "1.7.0", + "source": { + "type": "git", + "url": "https://git.drupal.org/project/menu_breadcrumb", + "reference": "8.x-1.7" + }, + "dist": { + "type": "zip", + "url": "https://ftp.drupal.org/files/projects/menu_breadcrumb-8.x-1.7.zip", + "reference": "8.x-1.7", + "shasum": "998c7908bd411afe745f91c725b39483e6dd693f" + }, + "require": { + "drupal/core": "~8.0" + }, + "type": "drupal-module", + "extra": { + "branch-alias": { + "dev-1.x": "1.x-dev" + }, + "drupal": { + "version": "8.x-1.7", + "datestamp": "1539197280", + "security-coverage": { + "status": "covered", + "message": "Covered by Drupal's security advisory policy" + } + } + }, + "notification-url": "https://packages.drupal.org/8/downloads", + "license": [ + "GPL-2.0-or-later" + ], + "authors": [ + { + "name": "RyanPrice", + "homepage": "https://www.drupal.org/user/873848" + }, + { + "name": "aaron", + "homepage": "https://www.drupal.org/user/33420" + }, + { + "name": "gdevlugt", + "homepage": "https://www.drupal.org/user/167273" + }, + { + "name": "rphair", + "homepage": "https://www.drupal.org/user/3196607" + }, + { + "name": "vaibhavjain", + "homepage": "https://www.drupal.org/user/1159692" + }, + { + "name": "xurizaemon", + "homepage": "https://www.drupal.org/user/76026" + } + ], + "description": "Create breadcrumbs from nested menu titles and/or taxonomy membership.", + "homepage": "https://www.drupal.org/project/menu_breadcrumb", + "support": { + "source": "http://cgit.drupalcode.org/menu_breadcrumb" + } + }, { "name": "drupal/metatag", "version": "1.7.0", diff --git a/vendor/composer/installed.json b/vendor/composer/installed.json index 33368fa438711006c029e170dd0f64fac6e7dd0b..7289005d30f9fd8f9aaae128d190cfa8f0de4049 100644 --- a/vendor/composer/installed.json +++ b/vendor/composer/installed.json @@ -4662,6 +4662,75 @@ "source": "http://cgit.drupalcode.org/menu_block" } }, + { + "name": "drupal/menu_breadcrumb", + "version": "1.7.0", + "version_normalized": "1.7.0.0", + "source": { + "type": "git", + "url": "https://git.drupal.org/project/menu_breadcrumb", + "reference": "8.x-1.7" + }, + "dist": { + "type": "zip", + "url": "https://ftp.drupal.org/files/projects/menu_breadcrumb-8.x-1.7.zip", + "reference": "8.x-1.7", + "shasum": "998c7908bd411afe745f91c725b39483e6dd693f" + }, + "require": { + "drupal/core": "~8.0" + }, + "type": "drupal-module", + "extra": { + "branch-alias": { + "dev-1.x": "1.x-dev" + }, + "drupal": { + "version": "8.x-1.7", + "datestamp": "1539197280", + "security-coverage": { + "status": "covered", + "message": "Covered by Drupal's security advisory policy" + } + } + }, + "installation-source": "dist", + "notification-url": "https://packages.drupal.org/8/downloads", + "license": [ + "GPL-2.0-or-later" + ], + "authors": [ + { + "name": "RyanPrice", + "homepage": "https://www.drupal.org/user/873848" + }, + { + "name": "aaron", + "homepage": "https://www.drupal.org/user/33420" + }, + { + "name": "gdevlugt", + "homepage": "https://www.drupal.org/user/167273" + }, + { + "name": "rphair", + "homepage": "https://www.drupal.org/user/3196607" + }, + { + "name": "vaibhavjain", + "homepage": "https://www.drupal.org/user/1159692" + }, + { + "name": "xurizaemon", + "homepage": "https://www.drupal.org/user/76026" + } + ], + "description": "Create breadcrumbs from nested menu titles and/or taxonomy membership.", + "homepage": "https://www.drupal.org/project/menu_breadcrumb", + "support": { + "source": "http://cgit.drupalcode.org/menu_breadcrumb" + } + }, { "name": "drupal/metatag", "version": "1.7.0", diff --git a/web/modules/menu_breadcrumb/LICENSE.txt b/web/modules/menu_breadcrumb/LICENSE.txt new file mode 100644 index 0000000000000000000000000000000000000000..d159169d1050894d3ea3b98e1c965c4058208fe1 --- /dev/null +++ b/web/modules/menu_breadcrumb/LICENSE.txt @@ -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. diff --git a/web/modules/menu_breadcrumb/README.txt b/web/modules/menu_breadcrumb/README.txt new file mode 100644 index 0000000000000000000000000000000000000000..8b1b8fe27e266e7592ffe5cca896c4b457319f55 --- /dev/null +++ b/web/modules/menu_breadcrumb/README.txt @@ -0,0 +1,60 @@ + +MENU BREADCRUMBS +================ + +Introduction +------------ +The Drupal 7 version of this module implemented the Drupal 6 behaviour of +using the menu position of the current page for the breadcrumb. It also +added an option to append the page title to the breadcrumb (either as +a clickable url or not), saving the trouble of doing this in the theme, +and hiding the breadcrumb if it only contains the link to the front page. + +The Drupal 8 version also supports "Taxonomy Attachment" for each +menu, which provides the same breadcrumb trail to the current +page as to a taxonomy of which it is a member: effectively giving +menu based breadcrumbs to items that aren't on a menu (e.g., blog +entries). Effectively these are "attached" to the breadcrumb trail by +taxonomy membership, inheriting the breadcrumbs of their taxonomy. + +Options in the Drupal 8 version therefore also include the ability to +add the current page title, linked or not, as an additional breadcrumb +when a taxonomy attachment has taken place. More detailed options are +given for dealing with the front page, allowing it to be added or removed. + +Installation +------------ +1. Copy the menu_breadcrumb folder to your modules/contrib directory. +2. At Administer -> Extend (admin/modules) enable the module. +3. Configure the module settings at Administer -> Configuration -> + User Interface (admin/config/user-interface/menu-breadcrumb). + +Upgrading +--------- +Recommended: install drush and run "drush up" + +Manually: replace the older menu_breadcrumb folder with the newer version; +then run "update.php" if present (to install any configuration changes). + +NOTES if you have installed a Drupal 8 development version: +If upgrading from the Alpha to the Beta version of the module, or to a +newer Beta, if option settings are not producing the desired effect: + +- Try clearing the cache, which fixes breacrumb on taxonomy pages (since this + module's breadcrumb builder needs to be acknolwedged as higher priority). +- Clearing the cache (at least the router cache) should clear up messages about + any services missing (known issue upgrading beta1 to beta2). +- If all else fails, try uninstalling & reinstalling the module. + + +Features +-------- +- For a high-level description, see the Drupal 8 Help screen for this module. +- All other features are described by each checkbox on the Configuration page, + and in the notes on the re-orderable menu list below. + +Issues / Feature requests +------------------------- +If you find a bug, or have a feature request, please go to : + +http://drupal.org/project/issues/menu_breadcrumb diff --git a/web/modules/menu_breadcrumb/config/install/menu_breadcrumb.settings.yml b/web/modules/menu_breadcrumb/config/install/menu_breadcrumb.settings.yml new file mode 100644 index 0000000000000000000000000000000000000000..9387c5ba5463423ee610f97d6dae65e10af8547a --- /dev/null +++ b/web/modules/menu_breadcrumb/config/install/menu_breadcrumb.settings.yml @@ -0,0 +1,16 @@ +determine_menu: true +disable_admin_page: true +append_current_page: true +current_page_as_link: false +append_member_page: false +member_page_as_link: false +remove_home: false +add_home: false +home_as_site_name: false +exclude_empty_url: false +# as of Beta, this option is obsolete: +# hide_on_single_item: false +menu_breadcrumb_menus: + main: + enabled: 1 + weight: -10 diff --git a/web/modules/menu_breadcrumb/config/schema/menu_breadcrumb.schema.yml b/web/modules/menu_breadcrumb/config/schema/menu_breadcrumb.schema.yml new file mode 100644 index 0000000000000000000000000000000000000000..5dbbc9009bea61b513e53859dd33e53d711abb17 --- /dev/null +++ b/web/modules/menu_breadcrumb/config/schema/menu_breadcrumb.schema.yml @@ -0,0 +1,52 @@ +menu_breadcrumb.settings: + type: config_object + label: 'Menu Breadcrumb Settings' + mapping: + determine_menu: + type: boolean + label: 'Use menu the page belongs to, or the page for the taxonomy of which it is a member, for the breadcrumb.' + disable_admin_page: + type: boolean + label: 'Do not build menu-based breadcrumbs for admin pages.' + append_current_page: + type: boolean + label: 'Include the current page in the breadcrumb trail if it is in the menu.' + current_page_as_link: + type: boolean + label: 'If the current page in the breadcrumb trail should be a link.' + append_member_page: + type: boolean + label: 'This option affects breadcrumb display when the current page is a member of a taxonomy whose term is on a menu with "Taxonomy Attachment" selected.' + member_page_as_link: + type: boolean + label: 'Set TRUE to show the attached final breadcrumb as a link.' + remove_home: + type: boolean + label: 'Remove the home link.' + add_home: + type: boolean + label: 'Ensure that the very first link is the designated <front> page link.' + home_as_site_name: + type: boolean + label: 'Use the site name from the configuration settings.' + exclude_empty_url: + type: boolean + label: 'Exclude menu items with empty URLs.' + menu_breadcrumb_menus: + type: sequence + label: 'Menu Breadcrumb Menu Configurations' + sequence: + type: mapping + mapping: + enabled: + type: integer + label: 'Enabled' + weight: + type: integer + label: 'Weight' + taxattach: + type: integer + label: 'Taxonomy Attachment' + langhandle: + type: integer + label: 'Language Handling' diff --git a/web/modules/menu_breadcrumb/menu_breadcrumb.info.yml b/web/modules/menu_breadcrumb/menu_breadcrumb.info.yml new file mode 100644 index 0000000000000000000000000000000000000000..a828765403a897b15144d6aefa2299d9410559c2 --- /dev/null +++ b/web/modules/menu_breadcrumb/menu_breadcrumb.info.yml @@ -0,0 +1,11 @@ +name: Menu Breadcrumb +type: module +description: 'Create breadcrumbs from nested menu titles and/or taxonomy membership.' +# core: '8.x' +configure: menu_breadcrumb.settings + +# Information added by Drupal.org packaging script on 2018-10-10 +version: '8.x-1.7' +core: '8.x' +project: 'menu_breadcrumb' +datestamp: 1539197292 diff --git a/web/modules/menu_breadcrumb/menu_breadcrumb.links.menu.yml b/web/modules/menu_breadcrumb/menu_breadcrumb.links.menu.yml new file mode 100644 index 0000000000000000000000000000000000000000..b55eb985ae770f2fb3f0abd989d4a37eed2e3123 --- /dev/null +++ b/web/modules/menu_breadcrumb/menu_breadcrumb.links.menu.yml @@ -0,0 +1,5 @@ +menu_breadcrumb.settings: + title: Menu Breadcrumb + description: 'Configure Menu Breadcrumb settings' + route_name: menu_breadcrumb.settings + parent: system.admin_config_ui diff --git a/web/modules/menu_breadcrumb/menu_breadcrumb.module b/web/modules/menu_breadcrumb/menu_breadcrumb.module new file mode 100644 index 0000000000000000000000000000000000000000..bb82e8a07edd89c851c1856c516e4e9929a9b8d0 --- /dev/null +++ b/web/modules/menu_breadcrumb/menu_breadcrumb.module @@ -0,0 +1,105 @@ +<?php + +/** + * @file + * menu_breadcrumb.module + */ + +use Drupal\Core\Routing\RouteMatchInterface; + +/** + * Implements hook_help(). + */ +function menu_breadcrumb_help($route_name, RouteMatchInterface $route_match) { + $output = ''; + switch ($route_name) { + // (this serves path = admin/help/menu_breadcrumb) + case 'help.page.menu_breadcrumb': + $output = <<<EOT +<h5> +Menu Breadcrumb: Generate breadcrumbs based on menu position/titles. +</h5> +<p> +On the module Settings page, select options regarding the apperarance of breadcrumbs, +and select menus on which to generate menu-based breadcrumbs. +This basic behaviour is similar to the Drupal 7 version, +which in Drupal 8 is extended as follows: +</p> +<ul> + <li> +If the "Taxonomy Attachment" option is selected for a menu, +and if the current page belongs to a taxonomy that is on that menu, +it will inherit the taxonomy page's menu breadcrumbs (e.g., to provide +breadcrumbs for blog entries that aren't on menus themselves). + </li> + <li> +If the "Language Handling" option is selected for a menu, +the menu will not be breadcrumbed unless its defined language matches +the current content language (recommended when you use a separate menu per language). + </li> + <li> +When the current page cannot be breadcrumbed according to the menu selections, +it will not generate a breadcrumb at all, and another breadcrumb builder of lower +priority will be free to generate the breadcrumb. + </li> +</ul> +<p> +When a "taxonomy attachment" is found, the breadcrumbs will reflect the menus +only and NOT the any hierarchy within the taxonomy: yet if those taxonomy terms +are posted in a hierarchical menu then they will breadcrumb in the same way. +(For menus based automatically on a taxonomy hierarchy, +with breadcrumbs reflecting the same hierarchy, +you could use the Taxonomy Menu module.) +</p> +<h5> +Implementation Notes +</h5> +<p> +If the current page exists on more than one menu, +or has more than one possible taxonomy attachment, +it uses the first box selected in the ordered list of menus. +The order in which menus are scanned can be changed by +dragging & dropping the menus on that list. +</p> +<p> +Taxonomy terms are searched in the order that their entity reference fields +appear in the current page's field listing. +One way to change an unwanted taxonomy term taking precendence over the one +you want to "attach" on would be to change the order of those fields. +</p> +<p> +When the current page is displaying the breadcrumbs of its taxonomy parent, +the breadcrumb for that taxonomy is <u>always</u> a link regardless of the +"Show current page as link" option. (This can be confusing until we remember +that this breadcrumb <u>is not</u> for the current page, and must be a link +because the current page is no anchored at all in the menu… unlike a +breacrumb that isn't taxonomy-attached.) +</p> +EOT; + break; + + // (this serves path = admin/config/user-interface/menu_breadcrumb) + case 'menu_breadcrumb.settings': + $output = <<<EOT +<p> +Select the first option to enable the Menu Breadcrumb module, +which will generate a breadcrumb trail the first match +in the selected menu below: first looking for the current page on a menu +(unless avoiding that menu due to language settings), +and then seeing if the current page belongs to a taxonomy on that menu +(whose breadcrumbs it will then inherit). +</p> +<p> +If it cannot find a menu path or a taxonomy-based path for the current page, +a breadcrumb will neither be generated nor cached and another breadcrumb builder +(e.g., the default path-based breadcrumb builder) +will be free to set the breadcrumb. +</p> +<p> +For more details, see <a href="/admin/help/menu_breadcrumb">Menu Breadcrumb Help</a>. +</p> +EOT; + break; + } + return $output; +} diff --git a/web/modules/menu_breadcrumb/menu_breadcrumb.routing.yml b/web/modules/menu_breadcrumb/menu_breadcrumb.routing.yml new file mode 100644 index 0000000000000000000000000000000000000000..a1cf4b55ff230bb9186114ae3ec1bfc611d4512c --- /dev/null +++ b/web/modules/menu_breadcrumb/menu_breadcrumb.routing.yml @@ -0,0 +1,7 @@ +menu_breadcrumb.settings: + path: '/admin/config/user-interface/menu-breadcrumb' + defaults: + _title: 'Menu Breadcrumb' + _form: '\Drupal\menu_breadcrumb\Form\SettingsForm' + requirements: + _permission: 'administer site configuration' diff --git a/web/modules/menu_breadcrumb/menu_breadcrumb.services.yml b/web/modules/menu_breadcrumb/menu_breadcrumb.services.yml new file mode 100644 index 0000000000000000000000000000000000000000..f1cc4e3a71c42452b714750f19af1b295f9d2557 --- /dev/null +++ b/web/modules/menu_breadcrumb/menu_breadcrumb.services.yml @@ -0,0 +1,8 @@ +services: + menu_breadcrumb.breadcrumb.default: + class: Drupal\menu_breadcrumb\MenuBasedBreadcrumbBuilder + arguments: ['@config.factory', '@menu.active_trail', '@plugin.manager.menu.link', '@router.admin_context', '@title_resolver', '@request_stack', '@language_manager', '@entity_type.manager'] + tags: + # The priority must be higher than core taxonomy builder (priority: 1002) + # see https://www.drupal.org/node/1495510 + - { name: breadcrumb_builder, priority: 1010 } diff --git a/web/modules/menu_breadcrumb/src/Form/SettingsForm.php b/web/modules/menu_breadcrumb/src/Form/SettingsForm.php new file mode 100644 index 0000000000000000000000000000000000000000..53e82400808837e07757e039ff6abc6577b62d0c --- /dev/null +++ b/web/modules/menu_breadcrumb/src/Form/SettingsForm.php @@ -0,0 +1,283 @@ +<?php + +namespace Drupal\menu_breadcrumb\Form; + +use Drupal\Component\Utility\SortArray; +use Drupal\Core\Config\ConfigFactoryInterface; +use Drupal\Core\Extension\ModuleHandlerInterface; +use Drupal\Core\Form\ConfigFormBase; +use Drupal\Core\Form\FormStateInterface; +use Symfony\Component\DependencyInjection\ContainerInterface; + +/** + * {@inheritdoc} + */ +class SettingsForm extends ConfigFormBase { + + /** + * Services used by the form generator. + * + * @var \Drupal\Core\Extension\ModuleHandlerInterface + */ + protected $moduleHandler; + + /** + * SettingsForm constructor. + * + * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory + * Used to obtain configuration information. + * @param \Drupal\Core\Extension\ModuleHandlerInterface $moduleHandler + * Used to determined whether the Menu UI module is installed. + */ + public function __construct( + ConfigFactoryInterface $config_factory, + ModuleHandlerInterface $moduleHandler + ) { + parent::__construct($config_factory); + $this->moduleHandler = $moduleHandler; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container) { + return new static( + $container->get('config.factory'), + $container->get('module_handler') + ); + } + + /** + * {@inheritdoc} + */ + protected function getEditableConfigNames() { + return ['menu_breadcrumb.settings']; + } + + /** + * {@inheritdoc} + */ + public function buildForm(array $form, FormStateInterface $form_state) { + $config = $this->config('menu_breadcrumb.settings'); + // Renamed from the now meaningless option "determine_menu": + $form['determine_menu'] = [ + '#type' => 'checkbox', + '#title' => $this->t('Enable the Menu Breadcrumb module'), + '#description' => $this->t( + 'Use menu the page belongs to, or the page for the taxonomy of which it is a member, for the breadcrumb. If unset, no breadcrumbs are generated or cached by this module and all settings below are ignored.' + ), + '#default_value' => $config->get('determine_menu'), + ]; + + $form['disable_admin_page'] = [ + '#type' => 'checkbox', + '#title' => $this->t('Disable for admin pages'), + '#description' => $this->t('Do not build menu-based breadcrumbs for admin pages.'), + '#default_value' => $config->get('disable_admin_page'), + ]; + + $form['append_current_page'] = [ + '#type' => 'checkbox', + '#title' => $this->t('Append current page to breadcrumb'), + '#description' => $this->t('If current page is on a menu, include it in the breadcrumb trail.'), + '#default_value' => $config->get('append_current_page'), + ]; + + $form['current_page_as_link'] = [ + '#type' => 'checkbox', + '#title' => $this->t('Show current page as link'), + '#description' => $this->t('Set TRUE if the current page in the breadcrumb trail should be a link (otherwise it will be plain text).'), + '#default_value' => $config->get('current_page_as_link'), + '#states' => [ + 'visible' => [ + ':input[name="append_current_page"]' => ['checked' => TRUE], + ], + ], + ]; + + $form['append_member_page'] = [ + '#type' => 'checkbox', + '#title' => $this->t('Attach taxonomy member page to breadcrumb'), + '#description' => $this->t('This option affects breadcrumb display when the current page is a member of a taxonomy whose term is on a menu with "Taxonomy Attachment" selected, when it "attaches" to the menu-based breadcrumbs of that taxonomy term. In this case that term\'s menu title will show as a link regardless of the "current page" options above. Set this option TRUE to also show the the current ("attached") <i>page</i> title as the final breadcrumb.'), + '#default_value' => $config->get('append_member_page'), + ]; + + $form['member_page_as_link'] = [ + '#type' => 'checkbox', + '#title' => $this->t('Show attached current page as link'), + '#description' => $this->t('Set TRUE to show the attached final breadcrumb as a link (otherwise it will be plain text).'), + '#default_value' => $config->get('member_page_as_link'), + '#states' => [ + 'visible' => [ + ':input[name="append_member_page"]' => ['checked' => TRUE], + ], + ], + ]; + + // Removed option "hide_on_single_item" - makes no sense when the taxonomy + // attachment feature is added, especially now that this module reverts to + // other breadcrumb builders (e.g., the path-based system breadcrumb) when + // it doesn't apply (can be reconsidered if there is a valid use case). + // $form['hide_on_single_item'] ... + // + $form['remove_home'] = [ + '#type' => 'checkbox', + '#title' => $this->t('Remove "Home" link'), + '#default_value' => $config->get('remove_home'), + '#description' => $this->t('Regardless of option settings, this module always checks if the first breadcrumb is also the <front> page. Without this option set, it will always replace the link for that node- or view- based path of the <front> page (e.g., /node/1 or /node) with a link to the site home. Set this option TRUE to <i>delete</i> the <front> breadcrumb rather than replacing it.'), + ]; + + $form['add_home'] = [ + '#type' => 'checkbox', + '#title' => $this->t('Add "Home" link'), + '#default_value' => $config->get('add_home'), + '#description' => $this->t('If TRUE will add a link to the <front> page if it doesn\'t already begin the breadcrumb trail: ensuring that the first breadcrumb of every page is the site home. If both "add" and "remove" are set, when displaying the <front> page and its menu children the "remove" option will take precedence.'), + ]; + + $form['home_as_site_name'] = [ + '#type' => 'checkbox', + '#title' => $this->t('Use site name instead of "Home" link'), + '#description' => $this->t('Uses the site name from the configuration settings: if this option is not set, a translated value for "Home" will be used.'), + '#default_value' => $config->get('home_as_site_name'), + ]; + + $form['exclude_empty_url'] = [ + '#type' => 'checkbox', + '#title' => $this->t('Exclude menu items with empty URLs'), + '#description' => $this->t('If TRUE, menu items whose Link fields resolves to an empty string (like in the case "<none>" was used) will not be included in the breadcrumb trail.'), + '#default_value' => $config->get('exclude_empty_url'), + ]; + + $form['include_exclude'] = [ + '#type' => 'fieldset', + '#title' => $this->t('Enable / Disable Menus'), + '#description' => $this->t('<b>Order of operation:</b> The breadcrumb will be generated from the first match it finds: "Enabled" to look for the current item on the menu, then "Taxonomy Attachment" to look for its taxonomy term. Re-order the list to change the priority of each menu.<br><b>Language Handling:</b> If set, skip this menu when the defined menu language does not match the current content language: recommended setting when you use a separate menu per language. This has no effect on taxonomy attachment.'), + ]; + $form['include_exclude']['note_about_navigation'] = [ + '#markup' => '<p class="description">' . $this->t("Note: If none of the selected menus contain an item for a given page, Drupal will look in the 'Navigation' menu by default, even if it is 'disabled' here.") . '</p>', + ]; + + // Orderable list of menu selections. + $form['include_exclude']['menu_breadcrumb_menus'] = [ + '#type' => 'table', + '#header' => [ + $this->t('Menu'), + $this->t('Enabled'), + $this->t('Taxonomy Attachment'), + $this->t('Language Handling'), + $this->t('Weight'), + ], + '#empty' => $this->t('There are no menus yet.'), + '#tabledrag' => [ + [ + 'action' => 'order', + 'relationship' => 'sibling', + 'group' => 'menus-order-weight', + ], + ], + ]; + + foreach ($this->getSortedMenus() as $menu_name => $menu_config) { + + $form['include_exclude']['menu_breadcrumb_menus'][$menu_name] = [ + '#attributes' => [ + 'class' => ['draggable'], + ], + '#weight' => $menu_config['weight'], + 'title' => [ + '#plain_text' => $menu_config['label'], + ], + 'enabled' => [ + '#type' => 'checkbox', + '#default_value' => $menu_config['enabled'], + ], + 'taxattach' => [ + '#type' => 'checkbox', + '#default_value' => $menu_config['taxattach'], + ], + 'langhandle' => [ + '#type' => 'checkbox', + '#default_value' => $menu_config['langhandle'], + ], + 'weight' => [ + '#type' => 'weight', + '#default_value' => $menu_config['weight'], + '#attributes' => ['class' => ['menus-order-weight']], + ], + ]; + } + // Removed description of a "Default setting" selection which was never + // implemeneted in the current D8 version of Menu Breadcrumb. + // TODO perhaps find out if this option would be worth preserving + // (applied to default tick boxes for new menus added in the future). + return parent::buildForm($form, $form_state); + } + + /** + * {@inheritdoc} + */ + public function submitForm(array &$form, FormStateInterface $form_state) { + $this->config('menu_breadcrumb.settings') + ->set('determine_menu', (boolean) $form_state->getValue('determine_menu')) + ->set('disable_admin_page', (boolean) $form_state->getValue('disable_admin_page')) + ->set('append_current_page', (boolean) $form_state->getValue('append_current_page')) + ->set('current_page_as_link', (boolean) $form_state->getValue('current_page_as_link')) + ->set('append_member_page', (boolean) $form_state->getValue('append_member_page')) + ->set('member_page_as_link', (boolean) $form_state->getValue('member_page_as_link')) + ->set('home_as_site_name', (boolean) $form_state->getValue('home_as_site_name')) + ->set('remove_home', (boolean) $form_state->getValue('remove_home')) + ->set('add_home', (boolean) $form_state->getValue('add_home')) + ->set('menu_breadcrumb_menus', $form_state->getValue('menu_breadcrumb_menus')) + ->set('exclude_empty_url', $form_state->getValue('exclude_empty_url')) + ->save(); + + parent::submitForm($form, $form_state); + } + + /** + * {@inheritdoc} + */ + public function getFormId() { + return 'menu_breadcrumb_settings'; + } + + /** + * Get Sorted Menus. + * + * Returns array of menus with properties (enabled, taxattach, langhandle, + * weight, label) sorted by weight, initializing those properties if needed. + */ + protected function getSortedMenus() { + $menu_enabled = $this->moduleHandler->moduleExists('menu_ui'); + $menus = $menu_enabled ? menu_ui_get_menus() : menu_list_system_menus(); + $menu_breadcrumb_menus = $this->config('menu_breadcrumb.settings')->get('menu_breadcrumb_menus'); + + foreach ($menus as $menu_name => &$menu) { + if (!empty($menu_breadcrumb_menus[$menu_name])) { + $menu = $menu_breadcrumb_menus[$menu_name] + ['label' => $menu]; + // Earlier versions of the module might not have these array keys set. + // TODO Maybe set these for existing menu definitions in upgrade script? + if (!isset($menu['taxattach'])) { + $menu['taxattach'] = 0; + } + if (!isset($menu['langhandle'])) { + $menu['langhandle'] = 0; + } + } + else { + $menu = [ + 'weight' => 0, + 'enabled' => 0, + 'taxattach' => 0, + 'langhandle' => 0, + 'label' => $menu, + ]; + } + } + uasort($menus, function ($a, $b) { + return SortArray::sortByWeightElement($a, $b); + }); + return $menus; + } + +} diff --git a/web/modules/menu_breadcrumb/src/MenuBasedBreadcrumbBuilder.php b/web/modules/menu_breadcrumb/src/MenuBasedBreadcrumbBuilder.php new file mode 100644 index 0000000000000000000000000000000000000000..315ad43c813a29b238b8b4d29bd5f728635913c0 --- /dev/null +++ b/web/modules/menu_breadcrumb/src/MenuBasedBreadcrumbBuilder.php @@ -0,0 +1,463 @@ +<?php + +namespace Drupal\menu_breadcrumb; + +use Drupal\Component\Utility\SortArray; +use Drupal\Core\Breadcrumb\Breadcrumb; +use Drupal\Core\Breadcrumb\BreadcrumbBuilderInterface; +use Drupal\Core\Config\ConfigFactoryInterface; +use Drupal\Core\Controller\TitleResolverInterface; +use Drupal\Core\Entity\EntityTypeManagerInterface; +use Drupal\Core\Entity\FieldableEntityInterface; +use Drupal\Core\Language\Language; +use Drupal\Core\Language\LanguageInterface; +use Drupal\Core\Language\LanguageManagerInterface; +use Drupal\Core\Link; +use Drupal\Core\Menu\MenuActiveTrailInterface; +use Drupal\Core\Menu\MenuLinkManagerInterface; +use Drupal\Core\Routing\AdminContext; +use Drupal\Core\Routing\RouteMatchInterface; +use Drupal\Core\Url; +use Drupal\menu_link_content\Plugin\Menu\MenuLinkContent; +use Drupal\node\NodeInterface; +use Symfony\Component\HttpFoundation\RequestStack; + +/** + * {@inheritdoc} + */ +class MenuBasedBreadcrumbBuilder implements BreadcrumbBuilderInterface { + use \Drupal\Core\StringTranslation\StringTranslationTrait; + + /** + * The configuration object generator. + * + * @var \Drupal\Core\Config\ConfigFactory + */ + protected $configFactory; + + /** + * The menu active trail interface. + * + * @var \Drupal\Core\Menu\MenuActiveTrailInterface + */ + protected $menuActiveTrail; + + /** + * The menu link manager interface. + * + * @var \Drupal\Core\Menu\MenuLinkManagerInterface + */ + protected $menuLinkManager; + + /** + * The admin context generator. + * + * @var \Drupal\Core\Routing\AdminContext + */ + protected $adminContext; + + /** + * The title resolver. + * + * @var \Drupal\Core\Controller\TitleResolverInterface + */ + protected $titleResolver; + + /** + * The current request. + * + * @var \Symfony\Component\HttpFoundation\Request + */ + protected $currentRequest; + + /** + * The language manager. + * + * @var \Drupal\Core\Language\LanguageManager + */ + protected $languageManager; + + /** + * The entity type manager. + * + * @var \Drupal\Core\Entity\EntityTypeManagerInterface + */ + protected $entityTypeManager; + + /** + * The Menu Breadcrumbs configuration. + * + * @var \Drupal\Core\Config\Config + */ + protected $config; + + /** + * The menu where the current page or taxonomy match has taken place. + * + * @var string + */ + private $menuName; + + /** + * The menu trail leading to this match. + * + * @var string + */ + private $menuTrail; + + /** + * Node of current path if taxonomy attached. + * + * @var \Drupal\node\Entity\Node + */ + private $taxonomyAttachment; + + /** + * Content language code (used in both applies() and build()). + * + * @var string + */ + private $contentLanguage; + + /** + * {@inheritdoc} + */ + public function __construct( + ConfigFactoryInterface $config_factory, + MenuActiveTrailInterface $menu_active_trail, + MenuLinkManagerInterface $menu_link_manager, + AdminContext $admin_context, + TitleResolverInterface $title_resolver, + RequestStack $request_stack, + LanguageManagerInterface $language_manager, + EntityTypeManagerInterface $entity_type_manager + ) { + $this->configFactory = $config_factory; + $this->menuActiveTrail = $menu_active_trail; + $this->menuLinkManager = $menu_link_manager; + $this->adminContext = $admin_context; + $this->titleResolver = $title_resolver; + $this->currentRequest = $request_stack->getCurrentRequest(); + $this->languageManager = $language_manager; + $this->entityTypeManager = $entity_type_manager; + $this->config = $this->configFactory->get('menu_breadcrumb.settings'); + } + + /** + * {@inheritdoc} + */ + public function applies(RouteMatchInterface $route_match) { + // This may look heavyweight for applies() but we have to check all ways the + // current path could be attached to the selected menus before turning over + // breadcrumb building (and caching) to another builder. Generally this + // should not be a problem since it will then fall back to the system (path + // based) breadcrumb builder which caches a breadcrumb no matter what. + if (!$this->config->get('determine_menu')) { + return FALSE; + } + // Don't breadcrumb the admin pages, if disabled on config options: + if ($this->config->get('disable_admin_page') && $this->adminContext->isAdminRoute($route_match->getRouteObject())) { + return FALSE; + } + // No route name means no active trail: + $route_name = $route_match->getRouteName(); + if (!$route_name) { + return FALSE; + } + + // This might be a "node" with no fields, e.g. a route to a "revision" URL, + // so we don't check for taxonomy fields on unfieldable nodes: + $node_object = $route_match->getParameters()->get('node'); + $node_is_fieldable = $node_object instanceof FieldableEntityInterface; + + // Make sure menus are selected, and breadcrumb text strings, are displayed + // in the content rather than the (default) interface language: + $this->contentLanguage = $this->languageManager + ->getCurrentLanguage(LanguageInterface::TYPE_CONTENT)->getId(); + + // Check each selected menu, in turn, until a menu or taxonomy match found: + // then cache its state for building & caching in build() and exit. + $menus = $this->config->get('menu_breadcrumb_menus'); + uasort($menus, function ($a, $b) { + return SortArray::sortByWeightElement($a, $b); + }); + foreach ($menus as $menu_name => $params) { + + // Look for current path on any enabled menu. + if (!empty($params['enabled'])) { + + // Skip over any menu that's not in the current content language, + // if and only if the "language handling" option set for that menu. + // NOTE this menu option is added late, so we check its existence first. + if (array_key_exists('langhandle', $params) && $params['langhandle']) { + $menu_objects = $this->entityTypeManager->getStorage('menu') + ->loadByProperties(['id' => $menu_name]); + if ($menu_objects) { + $menu_language = reset($menu_objects)->language()->getId(); + if ($menu_language != $this->contentLanguage && + $menu_language !== Language::LANGCODE_NOT_SPECIFIED && + $menu_language !== Language::LANGCODE_NOT_APPLICABLE) { + continue; + } + } + } + + $trail_ids = $this->menuActiveTrail->getActiveTrailIds($menu_name); + $trail_ids = array_filter($trail_ids); + if ($trail_ids) { + $this->menuName = $menu_name; + $this->menuTrail = $trail_ids; + $this->taxonomyAttachment = NULL; + return TRUE; + } + } + + // Look for a "taxonomy attachment" by node field, regardless of language. + if (!empty($params['taxattach']) && $node_is_fieldable) { + + // Check all taxonomy terms applying to the current page. + foreach ($node_object->getFields() as $field) { + if ($field->getSetting('target_type') == 'taxonomy_term') { + + // In general these entity references will support multiple + // values so we check all terms in the order they are listed. + foreach ($field->referencedEntities() as $term) { + $url = $term->toUrl(); + $route_links = $this->menuLinkManager->loadLinksByRoute($url->getRouteName(), $url->getRouteParameters(), $menu_name); + if (!empty($route_links)) { + // Successfully found taxonomy attachment, so pass to build(): + // - the menu in in which we have found the attachment + // - the effective menu trail of the taxonomy-attached node + // - the node itself (in build() we will find its title & URL) + $taxonomy_term_link = reset($route_links); + $taxonomy_term_id = $taxonomy_term_link->getPluginId(); + $this->menuName = $menu_name; + $this->menuTrail = $this->menuLinkManager->getParentIds($taxonomy_term_id); + $this->taxonomyAttachment = $node_object; + return TRUE; + } + } + } + } + } + } + // No more menus to check... + return FALSE; + } + + /** + * {@inheritdoc} + */ + public function build(RouteMatchInterface $route_match) { + $breadcrumb = new Breadcrumb(); + // Breadcrumbs accumulate in this array, with lowest index being the root + // (i.e., the reverse of the assigned breadcrumb trail): + $links = []; + // (https://www.drupal.org/docs/develop/standards/coding-standards#array) + // + if ($this->languageManager->isMultilingual()) { + $breadcrumb->addCacheContexts(['languages:language_content']); + } + + // Changing the <front> page will invalidate any breadcrumb generated here: + $site_config = $this->configFactory->get('system.site'); + $breadcrumb->addCacheableDependency($site_config); + + // Changing any module settings will invalidate the breadcrumb: + $breadcrumb->addCacheableDependency($this->config); + + // Changing the active trail or URL, of either the current path or the + // taxonomy-attached path, on this menu will invalidate this breadcrumb: + $breadcrumb->addCacheContexts(['route.menu_active_trails:' . $this->menuName]); + $breadcrumb->addCacheContexts(['url.path']); + + // Generate basic breadcrumb trail from active trail. + // Keep same link ordering as Menu Breadcrumb (so also reverses menu trail) + foreach (array_reverse($this->menuTrail) as $id) { + $plugin = $this->menuLinkManager->createInstance($id); + + // Skip items that have an empty URL if the option is set. + if ($this->config->get('exclude_empty_url') && empty($plugin->getUrlObject()->toString())) { + continue; + } + + $links[] = Link::fromTextAndUrl($plugin->getTitle(), $plugin->getUrlObject()); + $breadcrumb->addCacheableDependency($plugin); + // In the last line, MenuLinkContent plugin is not providing cache tags. + // Until this is fixed in core add the tags here: + if ($plugin instanceof MenuLinkContent) { + $uuid = $plugin->getDerivativeId(); + $entities = $this->entityTypeManager->getStorage('menu_link_content')->loadByProperties(['uuid' => $uuid]); + if ($entity = reset($entities)) { + $breadcrumb->addCacheableDependency($entity); + } + } + } + $this->addMissingCurrentPage($links, $route_match); + + // Create a breadcrumb for <front> which may be either added or replaced: + $langcode = $this->contentLanguage; + $label = $this->config->get('home_as_site_name') ? + $this->configFactory->get('system.site')->get('name') : + $this->t('Home', [], ['langcode' => $langcode]); + // (https://www.drupal.org/docs/develop/standards/coding-standards#array) + $home_link = Link::createFromRoute($label, '<front>'); + + // The first link from the menu trail, being the root, may be the + // <front> so first compare those two routes to see if they are identical. + // (Though in general a link deeper in the menu could be <front>, in that + // case it's arguable that the node-based pathname would be preferred.) + $front_page = $site_config->get('page.front'); + $front_url = Url::fromUri("internal:$front_page"); + $first_url = $links[0]->getUrl(); + // If options are set to remove <front>, strip off that link, otherwise + // replace it with a breadcrumb named according to option settings: + if (($first_url->isRouted() && $front_url->isRouted()) && + ($front_url->getRouteName() === $first_url->getRouteName()) && + ($front_url->getRouteParameters() === $first_url->getRouteParameters())) { + + // According to the confusion hopefully cleared up in issue 2754521, the + // sense of "remove_home" is slightly different than in Menu Breadcrumb: + // we remove any match with <front> rather than replacing it. + if ($this->config->get('remove_home')) { + array_shift($links); + } + else { + $links[0] = $home_link; + } + } + else { + // If trail *doesn't* begin with the home page, add it if that option set. + if ($this->config->get('add_home')) { + array_unshift($links, $home_link); + } + } + + if (!empty($links)) { + $page_type = $this->taxonomyAttachment ? 'member_page' : 'current_page'; + // Display the last item of the breadcrumbs trail as the options indicate. + /** @var \Drupal\Core\Link $current */ + $current = array_pop($links); + if ($this->config->get('append_' . $page_type)) { + if (!$this->config->get($page_type . '_as_link')) { + $current->setUrl(new Url('<none>')); + } + array_push($links, $current); + } + } + return $breadcrumb->setLinks($links); + } + + /** + * If the current page is missing from the breadcrumb links, add it. + * + * @param \Drupal\Core\Link[] $links + * The breadcrumb links. + * @param \Drupal\Core\Routing\RouteMatchInterface $route_match + * The current route match. + */ + protected function addMissingCurrentPage(array &$links, RouteMatchInterface $route_match) { + // Check if the current page is already present. + if (!empty($links)) { + $last_url = end($links)->getUrl(); + if ($last_url->isRouted() && + $last_url->getRouteName() === $route_match->getRouteName() && + $last_url->getRouteParameters() === $route_match->getRawParameters()->all() + ) { + // We already have a link, no need to add one. + return; + } + } + + // If we got here, the current page is missing from the breadcrumb links. + // This can happen if the active trail is only partial, and doesn't reach + // the current page, or if a taxonomy attachment is used. + $title = $this->titleResolver->getTitle($this->currentRequest, + $route_match->getRouteObject()); + if (isset($title)) { + $links[] = Link::fromTextAndUrl($title, + Url::fromRouteMatch($route_match)); + } + } + + /** + * The getter function for $menuName property. + * + * @return string + * The menu name. + */ + public function getMenuName() { + return $this->menuName; + } + + /** + * The setter function for $menuName property. + * + * @param string $menu_name + * The menu name. + */ + public function setMenuName($menu_name) { + $this->menuName = $menu_name; + } + + /** + * The getter function for $menuTrail property. + * + * @return string + * The menu trail. + */ + public function getMenuTrail() { + return $this->menuTrail; + } + + /** + * The setter function for $menuTrail property. + * + * @param string $menu_trail + * The menu trail. + */ + public function setMenuTrail($menu_trail) { + $this->menuTrail = $menu_trail; + } + + /** + * The getter function for $taxonomyAttachment property. + * + * @return \Drupal\node\NodeInterface + * The taxonomy attachment. + */ + public function getTaxonomyAttachment() { + return $this->taxonomyAttachment; + } + + /** + * The setter function for $taxonomyAttachment property. + * + * @param \Drupal\node\NodeInterface $taxonomy_attachment + * The taxonomy attachment. + */ + public function setTaxonomyAttachment(NodeInterface $taxonomy_attachment) { + $this->taxonomyAttachment = $taxonomy_attachment; + } + + /** + * The getter function for $contentLanguage property. + * + * @return string + * The content language. + */ + public function getContentLanguage() { + return $this->contentLanguage; + } + + /** + * The setter function for $contentLanguage property. + * + * @param string $contentLanguage + * The content language. + */ + public function setContentLanguage($contentLanguage) { + $this->contentLanguage = $contentLanguage; + } + +}