diff --git a/composer.json b/composer.json index ba0a421ac6de756a22d36fbc73adc156419f37c0..7e429471e31a4f55e1693cd4b983ec43dbe3fd37 100644 --- a/composer.json +++ b/composer.json @@ -148,6 +148,7 @@ "drupal/mobile_detect_twig_extensions": "1.5", "drupal/mobile_device_detection": "3.2", "drupal/module_filter": "3.1", + "drupal/multiple_fields_remove_button": "^1.0@alpha", "drupal/pantheon_advanced_page_cache": "1.1", "drupal/paragraphs": "1.12", "drupal/pathauto": "1.8", diff --git a/composer.lock b/composer.lock index e8737d4217bfc1cc2067f853bf3adf071ae882ac..0a1fab0b28a5b0bcbaf835fe10553ae1fd19c211 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "cc2d25c444bb240901cdfc8717674c23", + "content-hash": "a38ef5c9575d3782158036e8e6afd6b5", "packages": [ { "name": "alchemy/zippy", @@ -6421,6 +6421,54 @@ "source": "http://cgit.drupalcode.org/module_filter" } }, + { + "name": "drupal/multiple_fields_remove_button", + "version": "1.0.0-alpha13", + "source": { + "type": "git", + "url": "https://git.drupalcode.org/project/multiple_fields_remove_button.git", + "reference": "8.x-1.0-alpha13" + }, + "dist": { + "type": "zip", + "url": "https://ftp.drupal.org/files/projects/multiple_fields_remove_button-8.x-1.0-alpha13.zip", + "reference": "8.x-1.0-alpha13", + "shasum": "d7171a7c1cba940320c271432f8e7c432a539989" + }, + "require": { + "drupal/core": "^8 || ^9" + }, + "type": "drupal-module", + "extra": { + "drupal": { + "version": "8.x-1.0-alpha13", + "datestamp": "1590964821", + "security-coverage": { + "status": "not-covered", + "message": "Alpha releases are not covered by Drupal security advisories." + } + } + }, + "notification-url": "https://packages.drupal.org/8/downloads", + "license": [ + "GPL-2.0-or-later" + ], + "authors": [ + { + "name": "asghar", + "homepage": "https://www.drupal.org/user/415797" + }, + { + "name": "semjuel", + "homepage": "https://www.drupal.org/user/2426534" + } + ], + "description": "Add remove button for multi showing fields.", + "homepage": "https://www.drupal.org/project/multiple_fields_remove_button", + "support": { + "source": "https://git.drupalcode.org/project/multiple_fields_remove_button" + } + }, { "name": "drupal/pantheon_advanced_page_cache", "version": "1.1.0", @@ -13439,7 +13487,9 @@ "packages-dev": [], "aliases": [], "minimum-stability": "dev", - "stability-flags": [], + "stability-flags": { + "drupal/multiple_fields_remove_button": 15 + }, "prefer-stable": true, "prefer-lowest": false, "platform": { diff --git a/vendor/composer/installed.json b/vendor/composer/installed.json index 15df9ebe028ebcace0928e7de928824c8d30490b..6041a8df397efdddeae3aeaa83b6afe4dd183dd3 100644 --- a/vendor/composer/installed.json +++ b/vendor/composer/installed.json @@ -6617,6 +6617,56 @@ "source": "http://cgit.drupalcode.org/module_filter" } }, + { + "name": "drupal/multiple_fields_remove_button", + "version": "1.0.0-alpha13", + "version_normalized": "1.0.0.0-alpha13", + "source": { + "type": "git", + "url": "https://git.drupalcode.org/project/multiple_fields_remove_button.git", + "reference": "8.x-1.0-alpha13" + }, + "dist": { + "type": "zip", + "url": "https://ftp.drupal.org/files/projects/multiple_fields_remove_button-8.x-1.0-alpha13.zip", + "reference": "8.x-1.0-alpha13", + "shasum": "d7171a7c1cba940320c271432f8e7c432a539989" + }, + "require": { + "drupal/core": "^8 || ^9" + }, + "type": "drupal-module", + "extra": { + "drupal": { + "version": "8.x-1.0-alpha13", + "datestamp": "1590964821", + "security-coverage": { + "status": "not-covered", + "message": "Alpha releases are not covered by Drupal security advisories." + } + } + }, + "installation-source": "dist", + "notification-url": "https://packages.drupal.org/8/downloads", + "license": [ + "GPL-2.0-or-later" + ], + "authors": [ + { + "name": "asghar", + "homepage": "https://www.drupal.org/user/415797" + }, + { + "name": "semjuel", + "homepage": "https://www.drupal.org/user/2426534" + } + ], + "description": "Add remove button for multi showing fields.", + "homepage": "https://www.drupal.org/project/multiple_fields_remove_button", + "support": { + "source": "https://git.drupalcode.org/project/multiple_fields_remove_button" + } + }, { "name": "drupal/pantheon_advanced_page_cache", "version": "1.1.0", diff --git a/web/modules/multiple_fields_remove_button/LICENSE.txt b/web/modules/multiple_fields_remove_button/LICENSE.txt new file mode 100644 index 0000000000000000000000000000000000000000..d159169d1050894d3ea3b98e1c965c4058208fe1 --- /dev/null +++ b/web/modules/multiple_fields_remove_button/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/multiple_fields_remove_button/README.txt b/web/modules/multiple_fields_remove_button/README.txt new file mode 100644 index 0000000000000000000000000000000000000000..8da1683150f52287262752b46962d56721f64bd6 --- /dev/null +++ b/web/modules/multiple_fields_remove_button/README.txt @@ -0,0 +1,9 @@ +Description: + +Multiple fields remove button add functionality to remove unlimited input fields +from node form. + +Configurations: +Enable this module and select unlimited option in field form. +Go to node form and you will see Remove button against each field for which you +were selected "unlimited" option. diff --git a/web/modules/multiple_fields_remove_button/css/multiple-fields-remove-button-icon-hover.svg b/web/modules/multiple_fields_remove_button/css/multiple-fields-remove-button-icon-hover.svg new file mode 100644 index 0000000000000000000000000000000000000000..6b45a1d5726e5a305022173b9dd062b4bb375153 --- /dev/null +++ b/web/modules/multiple_fields_remove_button/css/multiple-fields-remove-button-icon-hover.svg @@ -0,0 +1 @@ +<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16"><path fill="#ee0000" d="M3.51 13.925c.194.194.512.195.706.001l3.432-3.431c.194-.194.514-.194.708 0l3.432 3.431c.192.194.514.193.707-.001l1.405-1.417c.191-.195.189-.514-.002-.709l-3.397-3.4c-.192-.193-.192-.514-.002-.708l3.401-3.43c.189-.195.189-.515 0-.709l-1.407-1.418c-.195-.195-.513-.195-.707-.001l-3.43 3.431c-.195.194-.516.194-.708 0l-3.432-3.431c-.195-.195-.512-.194-.706.001l-1.407 1.417c-.194.195-.194.515 0 .71l3.403 3.429c.193.195.193.514-.001.708l-3.4 3.399c-.194.195-.195.516-.001.709l1.406 1.419z"/></svg> diff --git a/web/modules/multiple_fields_remove_button/css/multiple-fields-remove-button-icon.svg b/web/modules/multiple_fields_remove_button/css/multiple-fields-remove-button-icon.svg new file mode 100644 index 0000000000000000000000000000000000000000..ca0d409dc5972dd461904a87ad39dd22f17a0b3e --- /dev/null +++ b/web/modules/multiple_fields_remove_button/css/multiple-fields-remove-button-icon.svg @@ -0,0 +1 @@ +<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16"><path fill="#787878" d="M3.51 13.925c.194.194.512.195.706.001l3.432-3.431c.194-.194.514-.194.708 0l3.432 3.431c.192.194.514.193.707-.001l1.405-1.417c.191-.195.189-.514-.002-.709l-3.397-3.4c-.192-.193-.192-.514-.002-.708l3.401-3.43c.189-.195.189-.515 0-.709l-1.407-1.418c-.195-.195-.513-.195-.707-.001l-3.43 3.431c-.195.194-.516.194-.708 0l-3.432-3.431c-.195-.195-.512-.194-.706.001l-1.407 1.417c-.194.195-.194.515 0 .71l3.403 3.429c.193.195.193.514-.001.708l-3.4 3.399c-.194.195-.195.516-.001.709l1.406 1.419z"/></svg> diff --git a/web/modules/multiple_fields_remove_button/css/multiple-fields-remove-button.widget.css b/web/modules/multiple_fields_remove_button/css/multiple-fields-remove-button.widget.css new file mode 100644 index 0000000000000000000000000000000000000000..be9fc4cce0f46f639906fe7383c9c7789bad7d33 --- /dev/null +++ b/web/modules/multiple_fields_remove_button/css/multiple-fields-remove-button.widget.css @@ -0,0 +1,41 @@ +.has-multiple-fields-remove-button { + position: relative; + padding-right: 32px !important; +} + +.has-multiple-fields-remove-button .multiple-fields-remove-button, +.has-multiple-fields-remove-button .multiple-fields-remove-button:hover, +.has-multiple-fields-remove-button .multiple-fields-remove-button:focus { + position: absolute; + right: 8px; + top: 50%; + margin: -8px 0 0 !important; + padding: 0 !important; + border: 0 !important; + box-shadow: none !important; + text-indent: -9999px; + width: 16px; + height: 16px; + background: url('multiple-fields-remove-button-icon.svg') no-repeat 50% 50%, url('multiple-fields-remove-button-icon-hover.svg') no-repeat 50% 50%; +} + +.has-multiple-fields-remove-button .multiple-fields-remove-button:hover, +.has-multiple-fields-remove-button .multiple-fields-remove-button:focus { + background-image: url('multiple-fields-remove-button-icon-hover.svg'); +} + +.has-multiple-fields-remove-button .multiple-fields-remove-button[disabled] { + background: none !important; +} + +.has-multiple-fields-remove-button .multiple-fields-remove-button + .ajax-progress { + position: absolute; + right: 4px; + top: 50%; + margin: -8px 0 0 !important; +} + +.has-multiple-fields-remove-button .multiple-fields-remove-button + .ajax-progress .message { + text-indent: -9999px; + position: absolute; +} diff --git a/web/modules/multiple_fields_remove_button/multiple_fields_remove_button.api.php b/web/modules/multiple_fields_remove_button/multiple_fields_remove_button.api.php new file mode 100644 index 0000000000000000000000000000000000000000..f88aea496d3edb36c231ffe2ac2d787619ecf147 --- /dev/null +++ b/web/modules/multiple_fields_remove_button/multiple_fields_remove_button.api.php @@ -0,0 +1,55 @@ +<?php + +/** + * @file + * Multiple fields remove button API documentation. + */ + +/** + * @addtogroup hooks + * @{ + */ + +/** + * Modify field types for which remove button will be added. + * + * @param array $fieldTypes + * A list with field types. + */ +function hook_multiple_field_remove_button_field_types_alter(array &$fieldTypes) { + $fieldTypes[] = "custom_field_type"; +} + +/** + * Modify field types for which remove button will not be added. + * + * @param array $skipTypes + * A list with field types. + */ +function hook_multiple_field_remove_button_skip_types_alter(array &$skipTypes) { + $skipTypes[] = "custom_field_type"; +} + +/** + * Modify field widgets for which remove button will not be added. + * + * @param array $skipWidgets + * A list with field widgets. + */ +function hook_multiple_field_remove_button_skip_widgets_alter(array &$skipWidgets) { + $skipWidgets[] = "custom_field_widget"; +} + +/** + * Modify field names for which remove button will be added. + * + * @param array $includedFields + * A list with field names. + */ +function hook_multiple_field_remove_button_field_alter(array &$includedFields) { + $includedFields = []; +} + +/** + * @} End of "addtogroup hooks". + */ diff --git a/web/modules/multiple_fields_remove_button/multiple_fields_remove_button.info.yml b/web/modules/multiple_fields_remove_button/multiple_fields_remove_button.info.yml new file mode 100644 index 0000000000000000000000000000000000000000..d2e07bef242ec9fd372aa75cf288b0eca0e3815e --- /dev/null +++ b/web/modules/multiple_fields_remove_button/multiple_fields_remove_button.info.yml @@ -0,0 +1,13 @@ +name: Multiple Fields Remove Button +type: module +description: Add remove button for multi showing fields. +core: 8.x +core_version_requirement: ^8 || ^9 +package: Fields +dependencies: + - drupal:field + +# Information added by Drupal.org packaging script on 2020-05-31 +version: '8.x-1.0-alpha13' +project: 'multiple_fields_remove_button' +datestamp: 1590964822 diff --git a/web/modules/multiple_fields_remove_button/multiple_fields_remove_button.libraries.yml b/web/modules/multiple_fields_remove_button/multiple_fields_remove_button.libraries.yml new file mode 100644 index 0000000000000000000000000000000000000000..3f781054857937e4d5abf4f26f43f9ab32d57bc9 --- /dev/null +++ b/web/modules/multiple_fields_remove_button/multiple_fields_remove_button.libraries.yml @@ -0,0 +1,4 @@ +multiple_fields_remove_button.widget: + css: + theme: + css/multiple-fields-remove-button.widget.css: {} diff --git a/web/modules/multiple_fields_remove_button/multiple_fields_remove_button.module b/web/modules/multiple_fields_remove_button/multiple_fields_remove_button.module new file mode 100644 index 0000000000000000000000000000000000000000..84414897278077d35ba6aa9ed946979d6be63d2e --- /dev/null +++ b/web/modules/multiple_fields_remove_button/multiple_fields_remove_button.module @@ -0,0 +1,509 @@ +<?php + +/** + * @file + * In this file we use widget hooks to extend their functionality. + * + * We use drupal hooks and add remove button for fields remove. + */ + +use Drupal\Core\Form\FormStateInterface; +use Drupal\Core\Field\FieldStorageDefinitionInterface; +use Drupal\Core\Language\Language; +use Drupal\Component\Utility\NestedArray; +use Drupal\Core\Field\WidgetBase; +use Drupal\Core\Render\Element; + +/** + * Ajax callback remove field when remove click is trigger. + * + * In this callback we will replace field items. Main job + * to delete field item we will done into submit handler. + * + * @param array $form + * The complete form structure. + * @param FormStateInterface $form_state + * The current state of the form. + * + * @return array + * Array element. + */ +function multiple_fields_remove_button_js(array $form, FormStateInterface &$form_state) { + $button = $form_state->getTriggeringElement(); + $address = array_slice($button['#array_parents'], 0, -2); + // Go one level up in the form, to the widgets container. + $parent_element = NestedArray::getValue($form, $address); + $field_name = $parent_element['#field_name']; + $parents = $parent_element['#field_parents']; + $widget_state = WidgetBase::getWidgetState($parents, $field_name, $form_state); + // Go one level up in the form, to the widgets container. + $element = NestedArray::getValue($form, array_slice($button['#array_parents'], 0, -3)); + $element['#id'] = $widget_state['wrapper_id']; + $element['#prefix'] = '<div class="ajax-new-content">' . (isset($element['#prefix']) ? $element['#prefix'] : ''); + $element['#suffix'] = (isset($element['#suffix']) ? $element['#suffix'] : '') . '</div>'; + + return $element; +} + +/** + * Ajax callback to empty individual values of limited-cardinality fields. + * + * @param array $form + * The complete form structure. + * @param FormStateInterface $form_state + * The current state of the form. + * + * @return \Drupal\Core\Ajax\AjaxResponse + * An Ajax response. + */ +function multiple_fields_remove_button_clear_value_js(array $form, FormStateInterface &$form_state) { + $button = $form_state->getTriggeringElement(); + // Get the container element. + $element = NestedArray::getValue($form, array_slice($button['#array_parents'], 0, -3)); + return $element; +} + +/** + * Implements hook_element_info_alter(). + */ +function multiple_fields_remove_button_element_info_alter(array &$info) { + if (isset($info['container'])) { + $info['container']['#process'][] = 'multiple_fields_remove_button_process_container'; + } +} + +/** + * Add correct wrapper to the element. + * + * @param array $element + * Reference to the Form API form element we're operating on. + * + * @return array + * Array element. + */ +function multiple_fields_remove_button_process_container(&$element) { + if (isset($element['widget']['add_more']['#ajax']['wrapper'])) { + $children = Element::children($element['widget']); + $wrapperId = $element['widget']['add_more']['#ajax']['wrapper']; + + foreach ($children as $child) { + if (isset($element['widget'][$child]['remove_button'])) { + $element['widget'][$child]['remove_button']['#ajax']['wrapper'] = $wrapperId; + } + } + } + else if (isset($element['widget'][0]['remove_button'])) { + $children = Element::children($element['widget']); + foreach ($children as $child) { + if (isset($element['widget'][$child]['remove_button'])) { + $element['widget'][$child]['remove_button']['#ajax']['wrapper'] = $element['#id']; + } + } + } + return $element; +} + +/** + * Implements hook_field_widget_form_alter(). + */ +function multiple_fields_remove_button_field_widget_form_alter(&$element, FormStateInterface $form_state, $context) { + // Add remove button for the following field types. + $fieldTypes = [ + 'addressfield_standard', + 'address', + 'date_popup', + 'date_text', + 'datetime', + 'decimal', + 'dynamic_entity_reference', + 'email', + 'entity_reference', + 'entity_reference_autocomplete', + 'float', + 'integer', + 'link', + 'location', + 'multiple_selects', + 'number', + 'property_reference', + 'string', + 'string_long', + 'smartdate', + 'telephone', + 'text', + 'text_long', + 'text_with_summary', + 'timestamp', + ]; + + // Add extra types with the help of others modules. + \Drupal::moduleHandler() + ->alter('multiple_field_remove_button_field_types', $fieldTypes); + + /** @var \Drupal\Core\Field\FieldItemListInterface $items */ + $items = $context['items']; + $fieldDefinition = $items->getFieldDefinition(); + $storage = $fieldDefinition->getFieldStorageDefinition(); + $type = $storage->getType(); + $cardinality = $storage->getCardinality(); + + // Don't do anything for single-value fields. + if ($cardinality == 1) { + return; + } + + // Don't add 'Remove' button to some field types - issue #2925978. + $skipTypes = [ + 'checkboxes', + ]; + // Allow other modules extends the list. + \Drupal::moduleHandler() + ->alter('multiple_field_remove_button_skip_types', $skipTypes); + $elementType = isset($element['#type']) ? $element['#type'] : []; + + // Don't add 'Remove' button to some widget types - issue #2925978. + $skipWidgets = [ + 'entity_reference_autocomplete_tags', + 'autocomplete_deluxe', + 'media_library_widget', + 'entity_reference_tree', + ]; + // Allow other modules extends the list. + \Drupal::moduleHandler() + ->alter('multiple_field_remove_button_skip_widgets', $skipWidgets); + $element_widget = []; + if ($context['widget'] && $context['widget'] instanceof WidgetBase) { + $element_widget = $context['widget']->getPluginId() ?? []; + } + + // Optionally, only include certain fields. + $includedFields = []; + \Drupal::moduleHandler() + ->alter('multiple_field_remove_button_included_fields', $includedFields); + + $is_cardinality_unlimited = $cardinality == FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED; + + if ( + in_array($type, $fieldTypes) && + !in_array($elementType, $skipTypes) && + !in_array($element_widget, $skipWidgets) + ) { + + $field_parents = isset($element['#field_parents']) ? $element['#field_parents'] : []; + $field_name = $fieldDefinition->getName(); + if (!empty($includedFields) && !in_array($field_name, $includedFields)) { + return; + } + $language = isset($element['#language']) ? $element['#language'] : Language::LANGCODE_NOT_SPECIFIED; + $delta = _multiple_fields_remove_button_get_delta($element); + + // Get parent which will we use into Remove Button Element. + $parents = array_merge($field_parents, [ + $field_name, + $language, + $delta, + ]); + $remove_btn_name = implode('_', $parents) . '_remove_button'; + + $callback = $is_cardinality_unlimited + ? 'multiple_fields_remove_button_js' + : 'multiple_fields_remove_button_clear_value_js'; + + $element['remove_button'] = [ + '#delta' => $delta, + '#name' => $remove_btn_name, + '#type' => 'submit', + '#value' => t('Remove'), + '#validate' => [], + '#attributes' => [ + 'class' => [ + 'multiple-fields-remove-button', + ], + ], + '#submit' => ['multiple_fields_remove_button_fixed_submit_handler'], + '#limit_validation_errors' => [], + '#ajax' => [ + 'callback' => $callback, + ], + '#weight' => 1000, + ]; + if ($is_cardinality_unlimited) { + $element['remove_button']['#submit'] = ['multiple_fields_remove_button_submit_handler']; + $element['remove_button']['#ajax']['effect'] = 'fade'; + } + } +} + +/** + * Submit callback to clear field values for fixed cardinality fields. + * + * @param array $form + * The complete form structure. + * @param FormStateInterface $form_state + * The current state of the form. + */ +function multiple_fields_remove_button_fixed_submit_handler(array $form, FormStateInterface $form_state) { + $formValues = $form_state->getValues(); + $formInputs = $form_state->getUserInput(); + $button = $form_state->getTriggeringElement(); + $delta = $button['#delta']; + // Where in the form we'll find the parent element. + $address = array_slice($button['#array_parents'], 0, -2); + + // Go one level up in the form, to the widgets container. + $parent_element = NestedArray::getValue($form, $address); + $field_name = $parent_element['#field_name']; + $parents = $parent_element['#field_parents']; + $field_state = WidgetBase::getWidgetState($parents, $field_name, $form_state); + + // Shift up the following values. + $cardinality = $parent_element['#cardinality']; + $i = $delta; + while ($i < $cardinality - 1) { + $old_element_address = array_merge($address, [$i + 1]); + $new_element_address = array_merge($address, [$i]); + + $moving_element = NestedArray::getValue($form, $old_element_address); + $keys = array_keys($old_element_address, 'widget', TRUE); + foreach ($keys as $key) { + unset($old_element_address[$key]); + } + $moving_element_value = NestedArray::getValue($formValues, $old_element_address); + $moving_element_input = NestedArray::getValue($formInputs, $old_element_address); + + $keys = array_keys($new_element_address, 'widget', TRUE); + foreach ($keys as $key) { + unset($new_element_address[$key]); + } + // Tell the element where it's being moved to. + $moving_element['#parents'] = $new_element_address; + + // Move the element around. + NestedArray::setValue($formValues, $moving_element['#parents'], $moving_element_value, TRUE); + NestedArray::setValue($formInputs, $moving_element['#parents'], $moving_element_input); + + // Save new element values. + foreach ($formValues as $key => $value) { + $form_state->setValue($key, $value); + } + $form_state->setUserInput($formInputs); + $i++; + } + + // Set the last value to be blank. + $old_element_address = array_merge($address, [$cardinality - 1]); + $moving_element = NestedArray::getValue($form, $old_element_address); + NestedArray::setValue($formInputs, $moving_element['#parents'], [ + 'target_id' => '', + '_weight' => $cardinality - 1, + ]); + + // Re-set the weights. + + // Fix the weights. Field UI lets the weights be in a range of + // (-1 * item_count) to (item_count). This means that when we remove one, + // the range shrinks; weights outside of that range then get set to + // the first item in the select by the browser, floating them to the top. + // We use a brute force method because we lost weights on both ends + // and if the user has moved things around, we have to cascade because + // if I have items weight weights 3 and 4, and I change 4 to 3 but leave + // the 3, the order of the two 3s now is undefined and may not match what + // the user had selected. + $address = array_slice($button['#array_parents'], 0, -2); + $keys = array_keys($address, 'widget', TRUE); + foreach ($keys as $key) { + unset($address[$key]); + } + $input = NestedArray::getValue($formInputs, $address); + + if ($input && is_array($input)) { + // Sort by weight. + uasort($input, '_field_multiple_value_form_sort_helper'); + + // Reweight everything in the correct order. + $weight = -1 * $field_state['items_count']; + foreach ($input as $key => $item) { + if ($item) { + $input[$key]['_weight'] = $weight++; + } + } + NestedArray::setValue($formInputs, $address, $input); + $form_state->setUserInput($formInputs); + } + + $form_state->setRebuild(); +} + +/** + * Submit callback to remove an item from the field UI multiple wrapper. + * + * When a remove button is submitted, we need to find the item that it + * referenced and delete it. Since field UI has the deltas as a straight + * unbroken array key, we have to renumber everything down. Since we do this + * we *also* need to move all the deltas around in the $form_state['values'] + * and $form_state['input'] so that user changed values follow. This is a bit + * of a complicated process. + * + * @param array $form + * The complete form structure. + * @param FormStateInterface $form_state + * The current state of the form. + */ +function multiple_fields_remove_button_submit_handler(array $form, FormStateInterface $form_state) { + $formValues = $form_state->getValues(); + $formInputs = $form_state->getUserInput(); + $button = $form_state->getTriggeringElement(); + $delta = $button['#delta']; + // Where in the form we'll find the parent element. + $address = array_slice($button['#array_parents'], 0, -2); + + // Go one level up in the form, to the widgets container. + $parent_element = NestedArray::getValue($form, $address); + $field_name = $parent_element['#field_name']; + $parents = $parent_element['#field_parents']; + $field_state = WidgetBase::getWidgetState($parents, $field_name, $form_state); + + // Go ahead and renumber everything from our delta to the last + // item down one. This will overwrite the item being removed. + for ($i = $delta; $i <= $field_state['items_count']; $i++) { + $old_element_address = array_merge($address, [$i + 1]); + $new_element_address = array_merge($address, [$i]); + + $moving_element = NestedArray::getValue($form, $old_element_address); + $keys = array_keys($old_element_address, 'widget', TRUE); + foreach ($keys as $key) { + unset($old_element_address[$key]); + } + $moving_element_value = NestedArray::getValue($formValues, $old_element_address); + $moving_element_input = NestedArray::getValue($formInputs, $old_element_address); + + $keys = array_keys($new_element_address, 'widget', TRUE); + foreach ($keys as $key) { + unset($new_element_address[$key]); + } + // Tell the element where it's being moved to. + $moving_element['#parents'] = $new_element_address; + + // Delete default value for the last deleted element. + if ($field_state['items_count'] == 0) { + $struct_key = NestedArray::getValue($formInputs, $new_element_address); + if (is_null($moving_element_value)) { + foreach ($struct_key as &$key) { + $key = ''; + } + $moving_element_value = $struct_key; + } + if (is_null($moving_element_input)) { + $moving_element_input = $moving_element_value; + } + } + + // Move the element around. + NestedArray::setValue($formValues, $moving_element['#parents'], $moving_element_value, TRUE); + NestedArray::setValue($formInputs, $moving_element['#parents'], $moving_element_input); + + // Save new element values. + foreach ($formValues as $key => $value) { + $form_state->setValue($key, $value); + } + $form_state->setUserInput($formInputs); + + // Move the entity in our saved state. + if (isset($field_state['original_deltas'][$i + 1])) { + $field_state['original_deltas'][$i] = $field_state['original_deltas'][$i + 1]; + } + else { + unset($field_state['original_deltas'][$i]); + } + } + + // Replace the deleted entity with an empty one. This helps to ensure that + // trying to add a new entity won't resurrect a deleted entity + // from the trash bin. + // $count = count($field_state['entity']); + // Then remove the last item. But we must not go negative. + if ($field_state['items_count'] > 0) { + $field_state['items_count']--; + } + + // Fix the weights. Field UI lets the weights be in a range of + // (-1 * item_count) to (item_count). This means that when we remove one, + // the range shrinks; weights outside of that range then get set to + // the first item in the select by the browser, floating them to the top. + // We use a brute force method because we lost weights on both ends + // and if the user has moved things around, we have to cascade because + // if I have items weight weights 3 and 4, and I change 4 to 3 but leave + // the 3, the order of the two 3s now is undefined and may not match what + // the user had selected. + $address = array_slice($button['#array_parents'], 0, -2); + $keys = array_keys($address, 'widget', TRUE); + foreach ($keys as $key) { + unset($address[$key]); + } + $input = NestedArray::getValue($formInputs, $address); + + if ($input && is_array($input)) { + // Sort by weight. + uasort($input, '_field_multiple_value_form_sort_helper'); + + // Reweight everything in the correct order. + $weight = -1 * $field_state['items_count']; + foreach ($input as $key => $item) { + if ($item) { + $input[$key]['_weight'] = $weight++; + } + } + NestedArray::setValue($formInputs, $address, $input); + $form_state->setUserInput($formInputs); + } + + $element_id = isset($form[$field_name]['#id']) ? $form[$field_name]['#id'] : ''; + if (!$element_id) { + $element_id = $parent_element['#id']; + } + $field_state['wrapper_id'] = $element_id; + WidgetBase::setWidgetState($parents, $field_name, $form_state, $field_state); + + $form_state->setRebuild(); +} + +/** + * Implements hook_preprocess_field_multiple_value_form(). + */ +function multiple_fields_remove_button_preprocess_field_multiple_value_form(&$variables) { + // Add wrapper class and stylesheet. + if (!empty($variables['multiple']) && isset($variables['element']['#cardinality']) + && $variables['element']['#cardinality'] != 1) { + $variables['table']['#attached']['library'][] = 'multiple_fields_remove_button/multiple_fields_remove_button.widget'; + foreach ($variables['table']['#rows'] as &$row) { + $row['data'][1]['class'][] = 'has-multiple-fields-remove-button'; + } + } +} + +/** + * Helper function to get element delta. + * + * @param array $element + * Form element we're operating on. + * + * @return int + * Element delta. + */ +function _multiple_fields_remove_button_get_delta($element) { + $delta = 0; + + if (isset($element['#delta'])) { + $delta = $element['#delta']; + } + elseif (isset($element['target_id']['#delta'])) { + // Handle delta for entity reference field. + $delta = $element['target_id']['#delta']; + } + elseif (isset($element['value']['#delta'])) { + // Handle delta for integer field. + $delta = $element['value']['#delta']; + } + + return $delta; +}