From 6e3974574f21b78ed0cf602efd25f22a9f1e7c6e Mon Sep 17 00:00:00 2001 From: Guillaume Bartolini Date: Fri, 30 Mar 2012 18:53:38 +1100 Subject: [PATCH] new module --- .../user.guillaumebartolini.espressostorage | 6 +- drupal/sites/all/.DS_Store | Bin 6148 -> 6148 bytes .../all/modules/field_group/CHANGELOG.txt | 40 + .../sites/all/modules/field_group/LICENSE.txt | 339 ++++ .../sites/all/modules/field_group/README.txt | 37 + .../modules/field_group/field_group.api.php | 435 ++++ .../all/modules/field_group/field_group.css | 32 + .../field_group/field_group.features.inc | 48 + .../field_group/field_group.field_ui.css | 14 + .../field_group/field_group.field_ui.inc | 815 ++++++++ .../field_group/field_group.field_ui.js | 137 ++ .../all/modules/field_group/field_group.info | 18 + .../modules/field_group/field_group.install | 258 +++ .../all/modules/field_group/field_group.js | 195 ++ .../modules/field_group/field_group.module | 1778 +++++++++++++++++ .../all/modules/field_group/field_group.test | 116 ++ .../horizontal-tabs/horizontal-tabs.css | 98 + .../horizontal-tabs/horizontal-tabs.js | 205 ++ .../field_group/multipage/multipage.css | 125 ++ .../field_group/multipage/multipage.js | 241 +++ 20 files changed, 4934 insertions(+), 3 deletions(-) create mode 100755 drupal/sites/all/modules/field_group/CHANGELOG.txt create mode 100644 drupal/sites/all/modules/field_group/LICENSE.txt create mode 100755 drupal/sites/all/modules/field_group/README.txt create mode 100755 drupal/sites/all/modules/field_group/field_group.api.php create mode 100755 drupal/sites/all/modules/field_group/field_group.css create mode 100755 drupal/sites/all/modules/field_group/field_group.features.inc create mode 100755 drupal/sites/all/modules/field_group/field_group.field_ui.css create mode 100755 drupal/sites/all/modules/field_group/field_group.field_ui.inc create mode 100755 drupal/sites/all/modules/field_group/field_group.field_ui.js create mode 100644 drupal/sites/all/modules/field_group/field_group.info create mode 100755 drupal/sites/all/modules/field_group/field_group.install create mode 100755 drupal/sites/all/modules/field_group/field_group.js create mode 100755 drupal/sites/all/modules/field_group/field_group.module create mode 100755 drupal/sites/all/modules/field_group/field_group.test create mode 100755 drupal/sites/all/modules/field_group/horizontal-tabs/horizontal-tabs.css create mode 100755 drupal/sites/all/modules/field_group/horizontal-tabs/horizontal-tabs.js create mode 100755 drupal/sites/all/modules/field_group/multipage/multipage.css create mode 100755 drupal/sites/all/modules/field_group/multipage/multipage.js diff --git a/drupal-starting-project.esproj/user.guillaumebartolini.espressostorage b/drupal-starting-project.esproj/user.guillaumebartolini.espressostorage index b6acb53..c8eb224 100644 --- a/drupal-starting-project.esproj/user.guillaumebartolini.espressostorage +++ b/drupal-starting-project.esproj/user.guillaumebartolini.espressostorage @@ -7,13 +7,13 @@ ESProjectWindowState ContentSize - {1106, 705} + {1680, 970} ProjectURL file://localhost/Users/guillaumebartolini/projects/drupal-starting-project/drupal-starting-project.esproj/ StateType ProjectWindow TopLeftPoint - {2847, 1018} + {2560, 1099} com.macrabbit.Espresso.FileManager.DisclosureCollapsed @@ -21,7 +21,7 @@ ExpandedURLs - file://localhost/Users/guillaumebartolini/projects/drupal-starting-project/drupal/sites/all/themes/rubik + file://localhost/Users/guillaumebartolini/projects/drupal-starting-project/drupal com.macrabbit.Espresso.Publisher.DisclosureCollapsed diff --git a/drupal/sites/all/.DS_Store b/drupal/sites/all/.DS_Store index 5008ddfcf53c02e82d7eee2e57c38e5672ef89f6..c11650436ae09872cea1f23a881b093e77f19b44 100644 GIT binary patch delta 287 zcmZoMXfc=|#>B`mF;Q%yo}wrt0|NsP3otO`Fr+dRCzTf$B;`y@Tt3-Agr%OHA(tVa zA%&q7Su#HfsAYXpK~83IiGjg2MkZz!RyKAHPEHPBn1{L;LX;^^Rv{PN(; zl+>ieqF6AyB(bEl*eS6HEEAAek^z(fvqSRpbAap^sOs>{l#+~i0SWKwY70wK9R(8$ zi&`CpYIAb~AlulYww9BFgHvD)hp3XCjYmjgO>JF$1JF%CzzFgV2=GEEIN7u@QI8Ge jr_J0P+#EpfZ%q8oJeglak(CLkMq#p{i120)kv+@+b7@Jb delta 70 zcmZoMXfc=|#>AjHu~2NHo+1YW5HK<@2yA}HsK&PW17jECW_AvK4xj>{$am(+{342+ UKzW7)kiy9(Jj$D6L{=~Z075el%K!iX diff --git a/drupal/sites/all/modules/field_group/CHANGELOG.txt b/drupal/sites/all/modules/field_group/CHANGELOG.txt new file mode 100755 index 0000000..b4a64bb --- /dev/null +++ b/drupal/sites/all/modules/field_group/CHANGELOG.txt @@ -0,0 +1,40 @@ +/* $Id*/ +CHANGELOG for field_group for Drupal 7 + +Field_group 7.x-1.x-dev + o Issue #1095316: Field Groups disappear when Content Type is renamed. + o Issue #1095316 by swentel: Support for Entity API. + o Issue #1095002 by animelion: Upgrading removes all existing field groups. + o Issue #1095130 by willvincent: Features export not working with rc2. + +Field_group 7.x-1.0-rc2 + o Ran through coder, minor. + o Issue #1033036 by Stalski, swentel: Create a field_group.api.php. + o Made the summary descriptions more human readable. + o Issue #1086450: Cannot see red star on some field groups even required fields are set to 1. + o #1072292 by shadow_jh, stalski: Using on user settings page but need to hid on registration page. + o #1092360 by dww: Move field_group_update_7000 functionality to hook_install(). + o #1061228 Rewrite the field_group_field_group_is_empty function. + o Added ID's to fieldgroups. + o Removed unused field_group.admin.inc + menu item. Required asterix moving to field_group setting. + o #1045526 by stalski: Make formatter options more user-friendly and logical. + o #1041880 by robertgarrigos: duplicated entries in field_group table. + o #1043834 by amsri: Field Group module just does not work with profiles 2. + +Field_group 7.x-1.0-rc1 + o #1006464 Change #groups to #fieldgroups because of name collapsing with form_process_fieldset + o #1024184 fix collapsible when mode is set to open + o #1020278 by mori: Update fails. + o #1020116 by mikegfx: Confusing verbage across group types. + o #1018012 by mikegfx: Adding required asterisk to group tabs that have required fields. + o #960916 fixed reference warnings. + o No label anymore with div>open. + o #969258 Added check for fields and extra_fields. + o #960916 Fixed notice on for reference on group in field_group_settings. + o #961106 Fixed notice on entity type and bundle check. + o #962072 by mori: Improve CSS for horizontal tabs & accordion. + o Changed Fieldgroup API: defaults and instance_settings are now merged. + o Changed save action so everything is gathered during form_state to + postpone saving until the save button is hit. + o Changed some important variable name, so it makes more sense and easier to read. + o Add basic crud functions. \ No newline at end of file diff --git a/drupal/sites/all/modules/field_group/LICENSE.txt b/drupal/sites/all/modules/field_group/LICENSE.txt new file mode 100644 index 0000000..d159169 --- /dev/null +++ b/drupal/sites/all/modules/field_group/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. + + + Copyright (C) + + 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. + + , 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/drupal/sites/all/modules/field_group/README.txt b/drupal/sites/all/modules/field_group/README.txt new file mode 100755 index 0000000..eb6efc2 --- /dev/null +++ b/drupal/sites/all/modules/field_group/README.txt @@ -0,0 +1,37 @@ + +History: + Field_group was written for Drupal 7. For drupal 6, the module is + located in the CCK module (http://drupal.org/project/cck). + As drupal core has a fields API drupal > 6, the field_group module + is considered a contribution. + +Description: + field_group is a module that will group a set of fields. In Drupal7, + with fields, one means all fields that come from fieldable entities. + You can add fieldgroups in several types with their own format settings. + field_group has API functions to add your own formatter and rendering for + it. + One of the biggest improvements to previous versions, is that fieldgroups + have unlimited nesting, better display control. + Note that field_group will only group fields, it can not be used to hide + certain fields since this a permission matter. + +Module project page: + http://drupal.org/project/field_group + +Documentation page: + http://drupal.org/node/1017838 + http://drupal.org/node/1017962 + +To submit bug reports and feature suggestions, or to track changes: + http://drupal.org/project/issues/field_group + +-- MAINTAINERS -- + +stalski - http://drupal.org/user/322618 +swentel - http://drupal.org/user/107403 +zuuperman - http://drupal.org/user/361625 + +-- INSPIRATORS -- + +yched - http://drupal.org/user/39567 diff --git a/drupal/sites/all/modules/field_group/field_group.api.php b/drupal/sites/all/modules/field_group/field_group.api.php new file mode 100755 index 0000000..2ace3ee --- /dev/null +++ b/drupal/sites/all/modules/field_group/field_group.api.php @@ -0,0 +1,435 @@ + array( + * 'fieldset' => array( + * // required, String with the name of the formatter type. + * 'label' => t('Fieldset'), + * // optional, String description of the formatter type. + * 'description' => t('This is field group that ...'), + * // required, Array of available formatter options. + * 'format_types' => array('open', 'collapsible', 'collapsed'), + * // required, String with default value of the style. + 'default_formatter' => 'collapsible', + * // optional, Array with key => default_value pairs. + * 'instance_settings' => array('key' => 'value'), + * ), + * ), + * 'display' => array( + * 'fieldset' => array( + * // required, String with the name of the formatter type. + * 'label' => t('Fieldset'), + * // optional, String description of the formatter type. + * 'description' => t('This is field group that ...'), + * // required, Array of available formatter options. + * 'format_types' => array('open', 'collapsible', 'collapsed'), + * // required, String with default value of the style. + 'default_formatter' => 'collapsible', + * // optional, Array with key => default_value pairs. + * 'instance_settings' => array('key' => 'value'), + * ), + * ), + * ), + * @endcode + * + * @return $formatters + * A collection of available formatting html controls for form + * and display overview type. + * + * @see field_group_field_group_formatter_info() + */ +function hook_field_group_formatter_info() { + return array( + 'form' => array( + 'fieldset' => array( + 'label' => t('Fieldset'), + 'description' => t('This fieldgroup renders the inner content in a fieldset with the titel as legend.'), + 'format_types' => array('open', 'collapsible', 'collapsed'), + 'instance_settings' => array('classes' => ''), + 'default_formatter' => 'collapsible', + ), + ), + 'display' => array( + 'div' => array( + 'label' => t('Div'), + 'description' => t('This fieldgroup renders the inner content in a simple div with the titel as legend.'), + 'format_types' => array('open', 'collapsible', 'collapsed'), + 'instance_settings' => array('effect' => 'none', 'speed' => 'fast', 'classes' => ''), + 'default_formatter' => 'collapsible', + ), + ), + ); +} + +/** + * Implements hook_field_group_format_settings(). + * + * Defines configuration widget for the settings on a field group + * formatter. Eache formatter can have different elements and storage. + * + * @params Object $group The group object. + * @return Array $form The form element for the format settings. + */ +function hook_field_group_format_settings($group) { + // Add a wrapper for extra settings to use by others. + $form = array( + 'instance_settings' => array( + '#tree' => TRUE, + '#weight' => 2, + ), + ); + + $field_group_types = field_group_formatter_info(); + $mode = $group->mode == 'form' ? 'form' : 'display'; + $formatter = $field_group_types[$mode][$group->format_type]; + + // Add the required formatter type selector. + if (isset($formatter['format_types'])) { + $form['formatter'] = array( + '#title' => t('Fieldgroup settings'), + '#type' => 'select', + '#options' => drupal_map_assoc($formatter['format_types']), + '#default_value' => isset($group->format_settings['formatter']) ? $group->format_settings['formatter'] : $formatter['default_formatter'], + '#weight' => 1, + ); + } + if ($mode == 'form') { + $form['instance_settings']['required_fields'] = array( + '#type' => 'checkbox', + '#title' => t('Mark group for required fields.'), + '#default_value' => isset($group->format_settings['instance_settings']['required_fields']) ? $group->format_settings['instance_settings']['required_fields'] : (isset($formatter['instance_settings']['required_fields']) ? $formatter['instance_settings']['required_fields'] : ''), + '#weight' => 2, + ); + } + $form['instance_settings']['classes'] = array( + '#title' => t('Extra CSS classes'), + '#type' => 'textfield', + '#default_value' => isset($group->format_settings['instance_settings']['classes']) ? $group->format_settings['instance_settings']['classes'] : (isset($formatter['instance_settings']['classes']) ? $formatter['instance_settings']['classes'] : ''), + '#weight' => 3, + '#element_validate' => array('field_group_validate_css_class'), + ); + $form['instance_settings']['description'] = array( + '#title' => t('Description'), + '#type' => 'textarea', + '#default_value' => isset($group->format_settings['instance_settings']['description']) ? $group->format_settings['instance_settings']['description'] : (isset($formatter['instance_settings']['description']) ? $formatter['instance_settings']['description'] : ''), + '#weight' => 0, + ); + + // Add optional instance_settings. + switch ($group->format_type) { + case 'div': + $form['instance_settings']['effect'] = array( + '#title' => t('Effect'), + '#type' => 'select', + '#options' => array('none' => t('None'), 'blind' => t('Blind')), + '#default_value' => isset($group->format_settings['instance_settings']['effect']) ? $group->format_settings['instance_settings']['effect'] : $formatter['instance_settings']['effect'], + '#weight' => 2, + ); + $form['instance_settings']['speed'] = array( + '#title' => t('Speed'), + '#type' => 'select', + '#options' => array('none' => t('None'), 'slow' => t('Slow'), 'fast' => t('Fast')), + '#default_value' => isset($group->format_settings['instance_settings']['speed']) ? $group->format_settings['instance_settings']['speed'] : $formatter['instance_settings']['speed'], + '#weight' => 3, + ); + break; + case 'fieldset': + $form['instance_settings']['classes'] = array( + '#title' => t('Extra CSS classes'), + '#type' => 'textfield', + '#default_value' => isset($group->format_settings['instance_settings']['classes']) ? $group->format_settings['instance_settings']['classes'] : $formatter['instance_settings']['classes'], + '#weight' => 3, + '#element_validate' => array('field_group_validate_css_class'), + ); + break; + case 'tabs': + case 'htabs': + case 'accordion': + unset($form['instance_settings']['description']); + if (isset($form['instance_settings']['required_fields'])) { + unset($form['instance_settings']['required_fields']); + } + break; + case 'tab': + case 'htab': + case 'accordion-item': + default: + } + + return $form; +} + +/** + * Implements hook_field_group_pre_render(). + * + * This function gives you the oppertunity to create the given + * wrapper element that can contain the fields. + * In the example beneath, some variables are prepared and used when building the + * actual wrapper element. All elements in drupal fapi can be used. + * + * Note that at this point, the field group has no notion of the fields in it. + * + * There is also an alternative way of handling this. The default implementation + * within field_group calls "field_group_pre_render_". + * @see field_group_pre_render_fieldset. + * + * @param Array $elements by address. + * @param Object $group The Field group info. + */ +function hook_field_group_pre_render(& $element, $group, & $form) { + + // You can prepare some variables to use in the logic. + $view_mode = isset($form['#view_mode']) ? $form['#view_mode'] : 'form'; + $id = $form['#entity_type'] . '_' . $form['#bundle'] . '_' . $view_mode . '_' . $group->group_name; + + // Each formatter type can have whole different set of element properties. + switch ($group->format_type) { + + // Normal or collapsible div. + case 'div': + $effect = isset($group->format_settings['instance_settings']['effect']) ? $group->format_settings['instance_settings']['effect'] : 'none'; + $speed = isset($group->format_settings['instance_settings']['speed']) ? $group->format_settings['instance_settings']['speed'] : 'none'; + $add = array( + '#type' => 'markup', + '#weight' => $group->weight, + '#id' => $id, + ); + $classes .= " speed-$speed effect-$effect"; + if ($group->format_settings['formatter'] != 'open') { + $add['#prefix'] = '
+ ' . check_plain(t($group->label)) . ' +
'; + } + else { + $add['#prefix'] = '
'; + $add['#suffix'] = '
'; + } + if (!empty($description)) { + $add['#prefix'] .= '
' . $description . '
'; + } + $element += $add; + + if ($effect == 'blind') { + drupal_add_library('system', 'effects.blind'); + } + + break; + break; + } +} + +/** + * Implements hook_field_group_pre_render(). + * + * Function that fungates as last resort to alter the pre_render build. + */ +function hook_field_group_pre_render_alter(&$element, $group, & $form) { + + if ($group->format_type == 'htab') { + $element['#theme_wrappers'] = array('my_horizontal_tab'); + } + +} + +/** + * Implements hook_field_group_build_pre_render_alter(). + * + * Function that fungates as last resort where you can alter things. It is + * expected that when you need this function, you have most likely a very custom + * case or it is a fix that can be put in field_group core. + * + * @param Array $elements by address. + */ +function hook_field_group_build_pre_render_alter(& $element) { + + // Prepare variables. + $display = isset($element['#view_mode']); + $groups = array_keys($element['#groups']); + + // Example from field_group itself to unset empty elements. + if ($display) { + foreach (element_children($element) as $name) { + if (in_array($name, $groups)) { + if (field_group_field_group_is_empty($element[$name], $groups)) { + unset($element[$name]); + } + } + } + } + + // You might include additional javascript files and stylesheets. + $element['#attached']['js'][] = drupal_get_path('module', 'field_group') . '/field_group.js'; + $element['#attached']['css'][] = drupal_get_path('module', 'field_group') . '/field_group.css'; + +} + +/** + * Implements hook_field_group_format_summary(). + * + * Place to override or change default summary behavior. In most + * cases the implementation of field group itself will be enough. + * + * TODO It might be better to change this hook with already created summaries, + * giving the ability to alter or add it later on. + */ +function hook_field_group_format_summary($group) { + $output = ''; + // Create additional summary or change the default setting. + return $output; +} + +/** + * Implement hook_ctools_plugin_api(). + * This hook is needed to let ctools know about exportables. + * If you create field groups by using hook_field_group_info, you + * will need to include the ctools api hook as well. + */ +function hook_ctools_plugin_api($module, $api) { + if ($module == 'field_group' && $api == 'field_group') { + return array('version' => 1); + } +} + +/** + * Implements hook_field_group_info(). + * Don't forget to include the ctools hook to notify that + * your modules has field group exports. + * @see hook_ctools_plugin_api. + */ +function hook_field_group_info() { + +} + +/** + * Implements hook_field_group_update_field_group(). + * + * This hook is invoked by ctools export API. + * Note that this is used by ctools and the group could occasional be + * the group ID. + * + * @param $object $group + * The FieldGroup object. + */ +function hook_field_group_update_field_group($group) { + // Delete extra data depending on the group. +} + +/** + * Implements hook_field_group_delete_field_group(). + * + * This hook is invoked by ctools export API. + * + * @param $object $group + * The FieldGroup object. + */ +function hook_field_group_delete_field_group($group) { + // Delete extra data depending on the group. +} + +/** + * Implements hook_field_group_create_field_group(). + * + * This hook is invoked by ctools export API. + * + * @param $object $group + * The FieldGroup object. + */ +function hook_field_group_create_field_group($group) { + // Create extra data depending on the group. +} + + + +/** + * @} End of "addtogroup hooks". + */ + + + +/** + * @addtogroup utility functions + * @{ + */ + +/** + * Get the groups for a given entity type, bundle and view mode. + * + * @param String $entity_type + * The Entity type where field groups are requested. + * @param String $bundle + * The entity bundle for the field groups. + * @param String $view_mode + * The view mode scope for the field groups. + * + * @see field_group_read_groups() + * @see ctools_export_crud_load() + * @see ctools_export_crud_load_all() + * @see ctools_export_crud_delete() + * @see ctools_export_crud_save() + */ +function field_group_info_groups($entity_type = NULL, $bundle = NULL, $view_mode = NULL, $reset = FALSE) { + // This function caches the result and delegates to field_group_read_groups. +} + +/** + * Get the groups for the given parameters, uncached. + * + * @param Array $params + * The Entity type where field groups are requested. + * + * @see field_group_info_groups() + * @see ctools_export_load_object() + */ +function field_group_read_groups($params = array()) { + // This function loads the requested groups through ctools export api. +} + +/** + * @} End of "addtogroup utility functions". + */ + diff --git a/drupal/sites/all/modules/field_group/field_group.css b/drupal/sites/all/modules/field_group/field_group.css new file mode 100755 index 0000000..5117873 --- /dev/null +++ b/drupal/sites/all/modules/field_group/field_group.css @@ -0,0 +1,32 @@ +/* $Id: field_group.css,v 1.1.2.12 2010/12/22 22:22:35 stalski Exp $ */ + +/** + * Fix for fieldsets in vertical tabs. + * Note that this can only be hardcoded to the Seven theme + * where people who override this, are in trouble. + */ +.vertical-tabs fieldset.default-fallback, +div.field-group-tabs-wrapper div.field-type-image fieldset, +div.field-group-tabs-wrapper div.field-type-file fieldset { + border: 1px solid #CCCCCC; + margin: 1em 0; + padding: 2.5em 0 0; + position: relative; +} + +div.field-group-tabs-wrapper div.field-type-image legend, +div.field-group-tabs-wrapper div.field-type-file legend, +.vertical-tabs .field-group-fieldset legend { + display: block; +} + +/** + * Override the accordion default style for view_modes. + */ +form .ui-accordion h3, form .ui-accordion h3.ui-state-active { + padding-left: 2em; +} + +.ui-accordion h3.ui-state-active { + background: url("/misc/ui/images/ui-bg_glass_75_e6e6e6_1x400.png") repeat-x scroll 50% 50% #E6E6E6; +} \ No newline at end of file diff --git a/drupal/sites/all/modules/field_group/field_group.features.inc b/drupal/sites/all/modules/field_group/field_group.features.inc new file mode 100755 index 0000000..cea7833 --- /dev/null +++ b/drupal/sites/all/modules/field_group/field_group.features.inc @@ -0,0 +1,48 @@ + $group) { + if ($group->entity_type == $entity_type && $group->bundle == $bundle + && in_array($field_name, $group->data['children'])) { + $export['features']['field_group'][$group_id] = $group_id; + } + } + } + } + + //Add any parent field groups that haven't been selected. + if (!empty($export['features']['field_group'])) { + foreach ($export['features']['field_group'] as $id) { + $group = isset($field_groups[$id]) ? $field_groups[$id] : FALSE; + + if ($group && !empty($group->parent_name)) { + $parent_id = $group->parent_name . '|' . $group->entity_type . '|' . $group->bundle . '|' . $group->mode; + $parent_group = isset($field_groups[$parent_id]) ? $field_groups[$parent_id] : FALSE; + + if ($parent_group && !isset($export['features']['field_group'][$parent_id])) { + $export['features']['field_group'][$parent_id] = $parent_id; + } + } + } + if(empty($export['dependencies']['field_group'])) { + $export['dependencies']['field_group'] = 'field_group'; + } + } +} diff --git a/drupal/sites/all/modules/field_group/field_group.field_ui.css b/drupal/sites/all/modules/field_group/field_group.field_ui.css new file mode 100755 index 0000000..7584e99 --- /dev/null +++ b/drupal/sites/all/modules/field_group/field_group.field_ui.css @@ -0,0 +1,14 @@ + +#field-overview tr.field-group .group-label, +#field-display-overview tr.field-group .group-label { + font-weight: bold; +} + +#field-overview tr.static-region, +#field-display-overview tr.static-region { + background-color: #ddd; +} + +#edit-refresh { + display:none; +} \ No newline at end of file diff --git a/drupal/sites/all/modules/field_group/field_group.field_ui.inc b/drupal/sites/all/modules/field_group/field_group.field_ui.inc new file mode 100755 index 0000000..47a1545 --- /dev/null +++ b/drupal/sites/all/modules/field_group/field_group.field_ui.inc @@ -0,0 +1,815 @@ +entity_type = $form['#entity_type']; + $params->bundle = $form['#bundle']; + $params->admin_path = _field_ui_bundle_admin_path($params->entity_type, $params->bundle); + $params->display_overview = $display_overview; + + $formatters = field_group_formatter_info(); + + if ($display_overview) { + $params->region_callback = 'field_group_display_overview_row_region'; + $params->mode = $form['#view_mode']; + } + else { + $params->region_callback = 'field_group_field_overview_row_region'; + $params->mode = 'form'; + } + + $params->groups = field_group_info_groups($params->entity_type, $params->bundle, $params->mode, TRUE); + + // Gather parenting data. + $params->parents = array(); + foreach ($params->groups as $name => $group) { + foreach ($group->children as $child) { + $params->parents[$child] = $name; + } + } + + return $params; +} + +/** + * Function to alter the fields overview and display overview screen. + */ +function field_group_field_ui_overview_form_alter(&$form, &$form_state, $display_overview = FALSE) { + + // Only start altering the form if we need to. + if (empty($form['#fields']) && empty($form['#extra'])) { + return; + } + + $params = field_group_field_ui_form_params($form, $display_overview); + + // Add some things to be able to preserve synced usage of field_ui. + if (!$display_overview) { + // This key is used to store the current updated field. + $form_state += array( + 'formatter_settings_edit' => NULL, + ); + // Add AJAX wrapper. + $form['fields']['#prefix'] = '
'; + $form['fields']['#suffix'] = '
'; + } + $form['#groups'] = array_keys($params->groups); + + $table = &$form['fields']; + + // Add a region for 'add_new' rows, but only when fields are + // available and thus regions. + if (isset($table['#regions'])) { + $table['#regions'] += array( + 'add_new' => array('title' => ' '), + ); + } + + // Extend available parenting options. + foreach ($params->groups as $name => $group) { + $table['#parent_options'][$name] = $group->label; + } + $table['#parent_options']['_add_new_group'] = t('Add new group'); + + // Update existing rows accordingly to the parents. + foreach (element_children($table) as $name) { + $table[$name]['parent_wrapper']['parent']['#options'] = $table['#parent_options']; + // Inherit the value of the parent when default value is empty. + if (empty($table[$name]['parent_wrapper']['parent']['#default_value'])) { + $table[$name]['parent_wrapper']['parent']['#default_value'] = isset($params->parents[$name]) ? $params->parents[$name] : ''; + } + } + + $formatter_options = field_group_field_formatter_options($display_overview ? 'display' : 'form'); + + $refresh_rows = isset($form_state['values']['refresh_rows']) ? $form_state['values']['refresh_rows'] : (isset($form_state['input']['refresh_rows']) ? $form_state['input']['refresh_rows'] : NULL); + + // Create the group rows and check actions. + foreach (array_keys($params->groups) as $name) { + + // Play around with form_state so we only need to hold things + // between requests, until the save button was hit. + if (isset($form_state['field_group'][$name])) { + $group = & $form_state['field_group'][$name]; + } + else { + $group = & $params->groups[$name]; + } + + // Check the currently selected formatter, and merge persisted values for + // formatter settings for the group. + // This needs to be done first, so all fields are updated before creating form elements. + if (isset($refresh_rows) && $refresh_rows == $name) { + $settings = isset($form_state['values']['fields'][$name]) ? $form_state['values']['fields'][$name] : (isset($form_state['input']['fields'][$name]) ? $form_state['input']['fields'][$name] : NULL); + if (array_key_exists('settings_edit', $settings)) { + //$group->format_type = $form_state['field_group'][$name]->format_type; + $group = $form_state['field_group'][$name]; + } + field_group_formatter_row_update($group, $settings); + } + + // Save the group when the configuration is submitted. + if (!empty($form_state['values'][$name . '_formatter_settings_update'])) { + field_group_formatter_settings_update($group, $form_state['values']['fields'][$name]); + } + // After all updates are finished, let the form_state know. + $form_state['field_group'][$name] = $group; + + $settings = field_group_format_settings_form($group); + + $id = strtr($name, '_', '-'); + $js_rows_data[$id] = array('type' => 'group', 'name' => $name); + // A group cannot be selected as its own parent. + $parent_options = $table['#parent_options']; + unset($parent_options[$name]); + $table[$name] = array( + '#attributes' => array('class' => array('draggable', 'field-group'), 'id' => $id), + '#row_type' => 'group', + '#region_callback' => $params->region_callback, + '#js_settings' => array('rowHandler' => 'group'), + 'human_name' => array( + '#markup' => check_plain(t($group->label)), + '#prefix' => '', + '#suffix' => '', + ), + 'weight' => array( + '#type' => 'textfield', + '#default_value' => $group->weight, + '#size' => 3, + '#attributes' => array('class' => array('field-weight')), + ), + 'parent_wrapper' => array( + 'parent' => array( + '#type' => 'select', + '#options' => $parent_options, + '#empty_value' => '', + '#default_value' => isset($params->parents[$name]) ? $params->parents[$name] : '', + '#attributes' => array('class' => array('field-parent')), + '#parents' => array('fields', $name, 'parent'), + ), + 'hidden_name' => array( + '#type' => 'hidden', + '#default_value' => $name, + '#attributes' => array('class' => array('field-name')), + ), + ), + ); + + $table[$name] += array( + 'group_name' => array( + '#markup' => check_plain($name), + ), + 'format' => array( + 'type' => array( + '#type' => 'select', + '#options' => $formatter_options, + '#default_value' => $group->format_type, + '#attributes' => array('class' => array('field-group-type')), + ), + ), + ); + + $base_button = array( + '#submit' => array('field_ui_display_overview_multistep_submit'), + '#ajax' => array( + 'callback' => 'field_ui_display_overview_multistep_js', + 'wrapper' => 'field-display-overview-wrapper', + 'effect' => 'fade', + ), + '#field_name' => $name, + ); + + if ($form_state['formatter_settings_edit'] == $name) { + $table[$name]['format']['#cell_attributes'] = array('colspan' => $display_overview ? 3 : 3); + $table[$name]['format']['format_settings'] = array( + '#type' => 'container', + '#attributes' => array('class' => array('field-formatter-settings-edit-form')), + '#parents' => array('fields', $name, 'format_settings'), + '#weight' => -5, + 'label' => array( + '#markup' => t('Field group format:') . ' ' . $group->format_type . '', + ), + // Create a settings form where hooks can pick in. + 'settings' => $settings, + 'actions' => array( + '#type' => 'actions', + 'save_settings' => $base_button + array( + '#type' => 'submit', + '#name' => $name . '_formatter_settings_update', + '#value' => t('Update'), + '#op' => 'update', + ), + 'cancel_settings' => $base_button + array( + '#type' => 'submit', + '#name' => $name . '_formatter_settings_cancel', + '#value' => t('Cancel'), + '#op' => 'cancel', + // Do not check errors for the 'Cancel' button. + '#limit_validation_errors' => array(), + ), + ), + ); + $table[$name]['#attributes']['class'][] = 'field-formatter-settings-editing'; + $table[$name]['format']['type']['#attributes']['class'] = array('element-invisible'); + } + else { + // After saving, the settings are updated here aswell. First we create + // the element for the table cell. + $table[$name]['settings_summary'] = array('#markup' => ''); + if (!empty($group->format_settings)) { + $table[$name]['settings_summary'] = field_group_format_settings_summary($name, $group); + } + // Add the configure button. + $table[$name]['settings_edit'] = $base_button + array( + '#type' => 'image_button', + '#name' => $name . '_group_settings_edit', + '#src' => 'misc/configure.png', + '#attributes' => array('class' => array('field-formatter-settings-edit'), 'alt' => t('Edit')), + '#op' => 'edit', + // Do not check errors for the 'Edit' button. + '#limit_validation_errors' => array(), + '#prefix' => '
', + '#suffix' => '
', + ); + if ($display_overview) { + $table[$name]['settings_edit']['#suffix'] .= l(t('delete'), $params->admin_path . '/groups/' . $name . '/delete/' . $params->mode); + } + } + + if (!$display_overview) { + $table[$name] += array( + 'delete' => array( + '#markup' => l(t('delete'), $params->admin_path . '/groups/' . $name . '/delete/form'), + ), + ); + } + } + + // Additional row: add new group. + $parent_options = $table['#parent_options']; + unset($parent_options['_add_new_group']); + $table['_add_new_group'] = field_group_add_row('_add_new_group', $parent_options, $params); + + $table['_add_new_group'] += array( + 'format' => array( + 'type' => array( + '#type' => 'select', + '#options' => $formatter_options, + '#default_value' => 'fieldset', + ), + ), + 'settings_summary' => array(), + 'settings_edit' => array(), + ); + + if (!$display_overview) { + // See field_ui.admin.inc for more details on refresh rows. + $form['refresh_rows'] = array('#type' => 'hidden'); + $form['refresh'] = array( + '#type' => 'submit', + '#value' => t('Refresh'), + '#op' => 'refresh_table', + '#submit' => array('field_ui_display_overview_multistep_submit'), + '#ajax' => array( + 'callback' => 'field_ui_display_overview_multistep_js', + 'wrapper' => 'field-display-overview-wrapper', + 'effect' => 'fade', + // The button stays hidden, so we hide the AJAX spinner too. Ad-hoc + // spinners will be added manually by the client-side script. + 'progress' => 'none', + ), + ); + } + + $form['#attached']['css'][] = drupal_get_path('module', 'field_group') . '/field_group.field_ui.css'; + $form['#attached']['js'][] = drupal_get_path('module', 'field_group') . '/field_group.field_ui.js'; + + $form['#validate'][] = 'field_group_field_overview_validate'; + $form['#submit'][] = 'field_group_field_overview_submit'; + + // Create the settings for fieldgroup as vertical tabs (merged with DS). + field_group_field_ui_create_vertical_tabs($form, $form_state, $params); + +} + +/** + * Return an array of field_group_formatter options. + */ +function field_group_field_formatter_options($type) { + $options = &drupal_static(__FUNCTION__); + + if (!isset($options)) { + $options = array(); + $field_group_types = field_group_formatter_info(); + foreach ($field_group_types[$type] as $name => $field_group_type) { + $options[$name] = $field_group_type['label']; + } + } + return $options; +} + +/** + * Helper function to add a row in the overview forms. + */ +function field_group_add_row($name, $parent_options, $params) { + return array( + '#attributes' => array('class' => array('draggable', 'field-group', 'add-new')), + '#row_type' => 'add_new_group', + '#js_settings' => array('rowHandler' => 'group'), + '#region_callback' => $params->region_callback, + 'label' => array( + '#type' => 'textfield', + '#size' => 15, + '#description' => t('Label'), + '#prefix' => '
' . t('Add new group') . '
', + '#suffix' => '
', + ), + 'weight' => array( + '#type' => 'textfield', + '#default_value' => field_info_max_weight($params->entity_type, $params->bundle, $params->mode) + 3, + '#size' => 3, + '#title_display' => 'invisible', + '#title' => t('Weight for new group'), + '#attributes' => array('class' => array('field-weight')), + '#prefix' => '
 
', + ), + 'parent_wrapper' => array( + 'parent' => array( + '#type' => 'select', + '#options' => $parent_options, + '#empty_value' => '', + '#attributes' => array('class' => array('field-parent')), + '#prefix' => '
 
', + '#parents' => array('fields', $name, 'parent'), + ), + 'hidden_name' => array( + '#type' => 'hidden', + '#default_value' => $name, + '#attributes' => array('class' => array('field-name')), + ), + ), + 'group_name' => array( + '#type' => 'textfield', + // This field should stay LTR even for RTL languages. + '#field_prefix' => 'group_', + '#field_suffix' => '‎', + '#attributes' => array('dir' => 'ltr'), + '#size' => 15, + '#description' => t('Group name (a-z, 0-9, _)'), + '#prefix' => '
 
', + '#cell_attributes' => array('colspan' => $params->display_overview ? 1 : 2), + ), + ); +} + +/** + * Creates a form for field_group formatters. + * @param Object $group The FieldGroup object. + */ +function field_group_format_settings_form(&$group) { + $form = array(); + $form['label'] = array( + '#type' => 'textfield', + '#title' => t('Field group label'), + '#default_value' => $group->label, + '#weight' => -5, + '#element_validate' => array('field_group_format_settings_label_validate'), + ); + $form += module_invoke_all('field_group_format_settings', $group); + $form['#validate'] = array('field_group_format_settings_form_validate'); + return $form; +} + +/** + * Validate the label. Label is required for fieldsets that are collapsible. + */ +function field_group_format_settings_label_validate($element, &$form_state) { + + $group = $form_state['values']['fields'][$element['#parents'][1]]; + $settings = $group['format_settings']['settings']; + $name = $form_state['formatter_settings_edit']; + $form_state['values']['fields'][$name]['settings_edit_form']['settings'] = $settings; + if ($group['format']['type'] == 'fieldset' && ($settings['formatter'] == 'collapsed' || $settings['formatter'] == 'collapsible') && empty($settings['label'])) { + form_error($element, t('The label is required when formatter is collapsible or collapsed')); + } + +} + +/** + * Update the row so that the group variables are updated. + * The rendering of the elements needs the updated defaults. + * @param Object $group + * @param array $settings + */ +function field_group_formatter_row_update(& $group, $settings) { + // if the row has changed formatter type, update the group object + if (!empty($settings['format']['type']) && $settings['format']['type'] != $group->format_type) { + $group->format_type = $settings['format']['type']; + field_group_formatter_settings_update($group, $settings); + } +} + +/** + * Update handler for field_group configuration settings. + * @param Object $group The group object + * @param Array $settings Configuration settings + */ +function field_group_formatter_settings_update(& $group, $settings) { + + // Fetch the field_group formatter defaults. + $field_group_types = field_group_formatter_info(); + $mode = $group->mode == 'form' ? 'form' : 'display'; + $formatter = $field_group_types[$mode][$group->format_type]; + + // for format changes we load the defaults. + if (empty($settings['format_settings']['settings'])) { + $group->format_settings = array( + 'formatter' => isset($formatter['default_formatter']) ? $formatter['default_formatter'] : '', + 'instance_settings' => $formatter['instance_settings'] + ); + } + else { + $group->format_type = $settings['format']['type']; + $group->label = $settings['format_settings']['settings']['label']; + $group->format_settings = $settings['format_settings']['settings']; + // This is avoided now, cause of the form_state['field_group'] + // ctools_include('export'); + // ctools_export_crud_save('field_group', $group); + // cache_clear_all('field_groups', 'cache_field'); + } +} + +/** + * Creates a summary for the field format configuration summary. + * @param String $group_name The name of the group + * @param Object $group The group object + * @return Array ready to be rendered. + */ +function field_group_format_settings_summary($group_name, $group) { + $summary = implode('
', module_invoke_all('field_group_format_summary', $group)); + return array( + '#markup' => '
' . $summary . '
', + '#cell_attributes' => array('class' => array('field-formatter-summary-cell')), + ); +} + +/** + * Returns the region to which a row in the 'Manage fields' screen belongs. + * @param Array $row A field or field_group row + * @return String the current region. + */ +function field_group_field_overview_row_region($row) { + switch ($row['#row_type']) { + case 'group': + return 'main'; + case 'add_new_group': + // If no input in 'label', assume the row has not been dragged out of the + // 'add new' section. + if (empty($row['label']['#value'])) { + return 'add_new'; + } + return 'main'; + } +} + +/** + * Returns the region to which a row in the 'Manage display' screen belongs. + * @param Array $row A field or field_group row + * @return String the current region. + */ +function field_group_display_overview_row_region($row) { + switch ($row['#row_type']) { + case 'group': + return ($row['format']['type']['#value'] == 'hidden' ? 'hidden' : 'visible'); + case 'add_new_group': + // If no input in 'label', assume the row has not been dragged out of the + // 'add new' section. + if (empty($row['label']['#value'])) { + return 'add_new'; + } + return ($row['format']['type']['#value'] == 'hidden' ? 'hidden' : 'visible'); + } +} + +/** + * Validate handler for the overview screens. + * @param Array $form The complete form. + * @param Array $form_state The state of the form. + */ +function field_group_field_overview_validate($form, &$form_state) { + $form_values = $form_state['values']['fields']; + $entity_type = $form['#entity_type']; + $bundle = $form['#bundle']; + $mode = (isset($form['#view_mode']) ? $form['#view_mode'] : 'form'); + + $group = $form_values['_add_new_group']; + + // Validate if any information was provided in the 'add new group' row. + if (array_filter(array($group['label'], $group['group_name']))) { + // Missing label. + if (!$group['label']) { + form_set_error('fields][_add_new_group][label', t('Add new group: you need to provide a label.')); + } + + // Missing group name. + if (!$group['group_name']) { + form_set_error('fields][_add_new_group][group_name', t('Add new group: you need to provide a group name.')); + } + // Group name validation. + else { + $group_name = $group['group_name']; + + // Add the 'group_' prefix. + if (drupal_substr($group_name, 0, 6) != 'group_') { + $group_name = 'group_' . $group_name; + form_set_value($form['fields']['_add_new_group']['group_name'], $group_name, $form_state); + } + + // Invalid group name. + if (!preg_match('!^group_[a-z0-9_]+$!', $group_name)) { + form_set_error('fields][_add_new_group][group_name', t('Add new group: the group name %group_name is invalid. The name must include only lowercase unaccentuated letters, numbers, and underscores.', array('%group_name' => $group_name))); + } + if (drupal_strlen($group_name) > 32) { + form_set_error('fields][_add_new_group][group_name', t("Add new group: the group name %group_name is too long. The name is limited to 32 characters, including the 'group_' prefix.", array('%group_name' => $group_name))); + } + + // Group name already exists. + if (field_group_exists($group_name, $entity_type, $bundle, $mode)) { + form_set_error('fields][_add_new_group][group_name', t('Add new group: the group name %group_name already exists.', array('%group_name' => $group_name))); + } + } + } +} + +/** + * Submit handler for the overview screens. + * @param Array $form The complete form. + * @param Array $form_state The state of the form. + */ +function field_group_field_overview_submit($form, &$form_state) { + + $form_values = $form_state['values']['fields']; + $entity_type = $form['#entity_type']; + $bundle = $form['#bundle']; + $mode = (isset($form['#view_mode']) ? $form['#view_mode'] : 'form'); + + // Collect children. + $children = array_fill_keys($form['#groups'], array()); + foreach ($form_values as $name => $value) { + if (!empty($value['parent'])) { + // Substitute newly added fields, in case they were dragged + // directly in a group. + if ($name == '_add_new_field' && isset($form_state['fields_added']['_add_new_field'])) { + $name = $form_state['fields_added']['_add_new_field']; + } + elseif ($name == '_add_existing_field' && isset($form_state['fields_added']['_add_existing_field'])) { + $name = $form_state['fields_added']['_add_existing_field']; + } + $children[$value['parent']][$name] = $name; + } + } + + // Prepare storage with ctools. + ctools_include('export'); + + // Create new group. + if (!empty($form_values['_add_new_group']['group_name'])) { + $values = $form_values['_add_new_group']; + + $field_group_types = field_group_formatter_info(); + $formatter = $field_group_types[($mode == 'form' ? 'form' : 'display')][$values['format']['type']]; + + $new_group = (object) array( + 'identifier' => $values['group_name'] . '|' . $entity_type . '|' . $bundle . '|' . $mode, + 'group_name' => $values['group_name'], + 'entity_type' => $entity_type, + 'bundle' => $bundle, + 'mode' => $mode, + 'children' => isset($children['_add_new_group']) ? array_keys($children['_add_new_group']) : array(), + 'parent_name' => $values['parent'], + 'weight' => $values['weight'], + 'label' => $values['label'], + 'format_type' => $values['format']['type'], + 'disabled' => FALSE, + ); + $new_group->format_settings = array('formatter' => isset($formatter['default_formatter']) ? $formatter['default_formatter'] : ''); + if (isset($formatter['instance_settings'])) { + $new_group->format_settings['instance_settings'] = $formatter['instance_settings']; + } + + // Save and enable it in ctools + ctools_export_crud_save('field_group', $new_group); + ctools_export_crud_enable('field_group', $new_group->identifier); + + // Store new group information for any additional submit handlers. + $form_state['groups_added']['_add_new_group'] = $new_group->group_name; + drupal_set_message(t('New group %label successfully created.', array('%label' => $new_group->label))); + + // Replace the newly created group in the $children array, in case it was + // dragged directly in an existing field. + foreach (array_keys($children) as $parent) { + if (isset($children[$parent]['_add_new_group'])) { + unset($children[$parent]['_add_new_group']); + $children[$parent][$new_group->group_name] = $new_group->group_name; + } + } + } + + // Update existing groups. + $groups = field_group_info_groups($entity_type, $bundle, $mode, TRUE); + foreach ($form['#groups'] as $group_name) { + $group = $groups[$group_name]; + $group->label = $form_state['field_group'][$group_name]->label; + $group->children = array_keys($children[$group_name]); + $group->parent_name = $form_values[$group_name]['parent']; + $group->weight = $form_values[$group_name]['weight']; + $group->format_type = isset($form_values[$group_name]['format']['type']) ? $form_values[$group_name]['format']['type'] : 'visible'; + if (isset($form_state['field_group'][$group_name]->format_settings)) { + $group->format_settings = $form_state['field_group'][$group_name]->format_settings; + } + ctools_export_crud_save('field_group', $group); + } + + cache_clear_all('field_groups', 'cache_field'); +} + +/** + * Validate the entered css class from the submitted format settings. + * @param Array $element The validated element + * @param Array $form_state The state of the form. + */ +function field_group_validate_css_class($element, &$form_state) { + if (!empty($form_state['values']['fields'][$form_state['formatter_settings_edit']]['format_settings']['settings']['instance_settings']['classes']) && !preg_match('!^[A-Za-z0-9-_ ]+$!', $form_state['values']['fields'][$form_state['formatter_settings_edit']]['format_settings']['settings']['instance_settings']['classes'])) { + form_error($element, t('The css class must include only letters, numbers, underscores and dashes.')); + } +} + +/** + * Implements hook_field_info_max_weight(). + */ +function field_group_field_info_max_weight($entity_type, $bundle, $context) { + $weights = array(); + foreach (field_group_info_groups($entity_type, $bundle, $context) as $group) { + $weights[] = $group->weight; + } + return $weights ? max($weights) : NULL; +} + +/** + * Menu callback; present a form for removing a group. + */ +function field_group_delete_form($form, &$form_state, $group, $view_mode = 'form') { + + $form['#group'] = $group; + $admin_path = _field_ui_bundle_admin_path($group->entity_type, $group->bundle); + if ($view_mode == 'form') { + $admin_path .= '/fields'; + } + else { + $admin_path .= '/display/' . $view_mode; + } + $form['#redirect'] = array($admin_path); + $output = confirm_form($form, + t('Are you sure you want to delete the group %group?', array('%group' => t($group->label))), + $admin_path, + t('This action cannot be undone.'), + t('Delete'), t('Cancel'), + 'confirm' + ); + return $output; +} + +/** + * Remove group from bundle. + * + * @todo we'll have to reset all view mode settings - that will be fun :) + */ +function field_group_delete_form_submit($form, &$form_state) { + + $group = $form['#group']; + $bundle = $group->bundle; + $entity_type = $group->entity_type; + $group->mode = $form_state['build_info']['args'][1]; + + $bundles = field_info_bundles(); + $bundle_label = $bundles[$entity_type][$bundle]['label']; + + ctools_include('export'); + field_group_group_export_delete($group, FALSE); + + drupal_set_message(t('The group %group has been deleted from the %type content type.', array('%group' => t($group->label), '%type' => $bundle_label))); + + // Redirect. + $form_state['redirect'] = $form['#redirect']; +} + +/** + * Create vertical tabs. + */ +function field_group_field_ui_create_vertical_tabs(&$form, &$form_state, $params) { + + $form_state['field_group_params'] = $params; + + $entity_info = entity_get_info($params->entity_type); + $view_modes = array(); + if ($params->mode != 'default') { + $view_modes['default'] = t('Default'); + } + if ($params->mode != 'form') { + $view_modes['0'] = t('Form'); + } + foreach ($entity_info['view modes'] as $view_mode => $data) { + if ($data['custom settings'] && $params->mode != $view_mode) { + $view_modes[$view_mode] = $data['label']; + } + } + + // Add additional settings vertical tab. + if (!isset($form['additional_settings'])) { + $form['additional_settings'] = array( + '#type' => 'vertical_tabs', + '#theme_wrappers' => array('vertical_tabs'), + '#prefix' => '
', + '#suffix' => '
', + '#tree' => TRUE, + ); + $form['#attached']['js'][] = 'misc/form.js'; + $form['#attached']['js'][] = 'misc/collapse.js'; + } + + // Add extra guidelines for webmaster. + $form['additional_settings']['field_group'] = array( + '#type' => 'fieldset', + '#title' => t('Fieldgroups'), + '#description' => t('

Fields can be dragged into groups with unlimited nesting. Each fieldgroup format comes with a configuration form, specific for that format type.
Note that some formats come in pair. These types have a html wrapper to nest its fieldgroup children. E.g. Place accordion items into the accordion, vertical tabs in vertical tab group and horizontal tabs in the horizontal tab group. There is one exception to this rule, you can use a vertical tab without a wrapper when the additional settings tabs are available. E.g. node forms.

'), + '#collapsible' => TRUE, + '#collapsed' => FALSE, + '#parents' => array('additional_settings'), + ); + $form['additional_settings']['field_group']['fieldgroup_clone'] = array( + '#title' => t('Select source view mode or form'), + '#description' => t('Clone fieldgroups from selected view mode to the current display'), + '#type' => 'select', + '#options' => $view_modes, + '#default_value' => 'none' + ); + $form['additional_settings']['field_group']['fieldgroup_submit'] = array( + '#type' => 'submit', + '#value' => t('Clone'), + '#submit' => array('field_group_field_ui_clone_field_groups') + ); + +} + +/** + * Submit handler to save existing fieldgroups from one view mode or form to another. + */ +function field_group_field_ui_clone_field_groups($form, &$form_state) { + + $source_mode = $form_state['values']['additional_settings']['fieldgroup_clone'] == 0 ? 'form' : $form_state['values']['additional_settings']['fieldgroup_clone']; + $groups_to_clone = field_group_read_groups(array('bundle' => $form_state['field_group_params']->bundle, 'entity_type' => $form_state['field_group_params']->entity_type)); + $source_groups = $groups_to_clone[$form_state['field_group_params']->entity_type][$form_state['field_group_params']->bundle][$source_mode]; + + $fields = array_keys($form_state['values']['fields']); + + if (!empty($source_groups)) { + + foreach ($source_groups as $source_group) { + + if (in_array($source_group->group_name, $fields)) { + drupal_set_message(t('Fieldgroup @group is not cloned since a group already exists with the same name.', array('@group' => $source_group->group_name)), 'warning'); + continue; + } + + // Recreate the identifier and reset the id. + $source_group->id = NULL; + $source_group->mode = $form_state['field_group_params']->mode; + $source_group->identifier = $source_group->group_name . '|' . $source_group->entity_type . '|' . $source_group->bundle . '|' . $form_state['field_group_params']->mode; + $source_group->disabled = FALSE; + unset($source_group->export_type, $source_group->type, $source_group->table); + + // Save and enable it in ctools. + ctools_include('export'); + ctools_export_crud_save('field_group', $source_group); + ctools_export_crud_enable('field_group', $source_group->identifier); + + drupal_set_message(t('Fieldgroup @group cloned successfully.', array('@group' => $source_group->group_name))); + + } + } + +} +/** + * eof(). + */ \ No newline at end of file diff --git a/drupal/sites/all/modules/field_group/field_group.field_ui.js b/drupal/sites/all/modules/field_group/field_group.field_ui.js new file mode 100755 index 0000000..8a2b24d --- /dev/null +++ b/drupal/sites/all/modules/field_group/field_group.field_ui.js @@ -0,0 +1,137 @@ + +(function($) { + +Drupal.behaviors.fieldUIFieldsOverview = { + attach: function (context, settings) { + $('table#field-overview', context).once('field-field-overview', function() { + Drupal.fieldUIOverview.attach(this, settings.fieldUIRowsData, Drupal.fieldUIFieldOverview); + }); + } +}; + +/** + * Row handlers for the 'Manage fields' screen. + */ +Drupal.fieldUIFieldOverview = Drupal.fieldUIFieldOverview || {}; + +Drupal.fieldUIFieldOverview.group = function(row, data) { + this.row = row; + this.name = data.name; + this.region = data.region; + this.tableDrag = data.tableDrag; + + // Attach change listener to the 'group format' select. + this.$formatSelect = $('select.field-group-type', row); + this.$formatSelect.change(Drupal.fieldUIOverview.onChange); + + return this; +}; + +Drupal.fieldUIFieldOverview.group.prototype = { + getRegion: function () { + return 'main'; + }, + + regionChange: function (region, recurse) { + return {}; + }, + + regionChangeFields: function (region, element, refreshRows) { + + // Create a new tabledrag rowObject, that will compute the group's child + // rows for us. + var tableDrag = element.tableDrag; + rowObject = new tableDrag.row(element.row, 'mouse', true); + // Skip the main row, we handled it above. + rowObject.group.shift(); + + // Let child rows handlers deal with the region change - without recursing + // on nested group rows, we are handling them all here. + $.each(rowObject.group, function() { + var childRow = this; + var childRowHandler = $(childRow).data('fieldUIRowHandler'); + $.extend(refreshRows, childRowHandler.regionChange(region, false)); + }); + } +}; + + +/** + * Row handlers for the 'Manage display' screen. + */ +Drupal.fieldUIDisplayOverview = Drupal.fieldUIDisplayOverview || {}; + +Drupal.fieldUIDisplayOverview.group = function(row, data) { + this.row = row; + this.name = data.name; + this.region = data.region; + this.tableDrag = data.tableDrag; + + // Attach change listener to the 'group format' select. + this.$formatSelect = $('select.field-group-type', row); + this.$formatSelect.change(Drupal.fieldUIOverview.onChange); + + return this; +}; + +Drupal.fieldUIDisplayOverview.group.prototype = { + getRegion: function () { + return (this.$formatSelect.val() == 'hidden') ? 'hidden' : 'visible'; + }, + + regionChange: function (region, recurse) { + + // Default recurse to true. + recurse = (recurse == undefined) || recurse; + + // When triggered by a row drag, the 'format' select needs to be adjusted to + // the new region. + var currentValue = this.$formatSelect.val(); + switch (region) { + case 'visible': + if (currentValue == 'hidden') { + // Restore the group format back to 'fieldset'. + var value = 'fieldset'; + } + break; + + default: + var value = 'hidden'; + break; + } + if (value != undefined) { + this.$formatSelect.val(value); + } + + var refreshRows = {}; + refreshRows[this.name] = this.$formatSelect.get(0); + + if (recurse) { + this.regionChangeFields(region, this, refreshRows); + } + + return refreshRows; + }, + + regionChangeFields: function (region, element, refreshRows) { + + // Create a new tabledrag rowObject, that will compute the group's child + // rows for us. + var tableDrag = element.tableDrag; + rowObject = new tableDrag.row(element.row, 'mouse', true); + // Skip the main row, we handled it above. + rowObject.group.shift(); + + // Let child rows handlers deal with the region change - without recursing + // on nested group rows, we are handling them all here. + $.each(rowObject.group, function() { + var childRow = this; + var childRowHandler = $(childRow).data('fieldUIRowHandler'); + $.extend(refreshRows, childRowHandler.regionChange(region, false)); + }); + + } + +}; + +})(jQuery); \ No newline at end of file diff --git a/drupal/sites/all/modules/field_group/field_group.info b/drupal/sites/all/modules/field_group/field_group.info new file mode 100644 index 0000000..efab892 --- /dev/null +++ b/drupal/sites/all/modules/field_group/field_group.info @@ -0,0 +1,18 @@ +name = Fieldgroup +description = Fieldgroup +package = Fields +dependencies[] = field +dependencies[] = ctools +core = 7.x +files[] = field_group.install +files[] = field_group.module +files[] = field_group.field_ui.inc +files[] = field_group.form.inc +files[] = field_group.features.inc +files[] = field_group.test +; Information added by drupal.org packaging script on 2011-10-19 +version = "7.x-1.1" +core = "7.x" +project = "field_group" +datestamp = "1319051133" + diff --git a/drupal/sites/all/modules/field_group/field_group.install b/drupal/sites/all/modules/field_group/field_group.install new file mode 100755 index 0000000..b84b435 --- /dev/null +++ b/drupal/sites/all/modules/field_group/field_group.install @@ -0,0 +1,258 @@ + t('Table that contains field group entries and settings.'), + + // CTools export definitions. + 'export' => array( + 'key' => 'identifier', + 'identifier' => 'field_group', + 'default hook' => 'field_group_info', + 'save callback' => 'field_group_group_save', + 'delete callback' => 'field_group_group_export_delete', + 'can disable' => TRUE, + 'api' => array( + 'owner' => 'field_group', + 'api' => 'field_group', + 'minimum_version' => 1, + 'current_version' => 1, + ), + ), + + 'fields' => array( + 'id' => array( + 'type' => 'serial', + 'not null' => TRUE, + 'description' => 'The primary identifier for a group', + 'no export' => TRUE, + ), + 'identifier' => array( + 'type' => 'varchar', + 'length' => 255, + 'not null' => TRUE, + 'default' => '', + 'description' => 'The unique string identifier for a group.', + ), + 'group_name' => array( + 'type' => 'varchar', + 'length' => 32, + 'not null' => TRUE, + 'default' => '', + 'description' => 'The name of this group.', + ), + 'entity_type' => array( + 'type' => 'varchar', + 'length' => 32, + 'not null' => TRUE, + 'default' => '', + ), + 'bundle' => array( + 'type' => 'varchar', + 'length' => 128, + 'not null' => TRUE, + 'default' => '' + ), + 'mode' => array( + 'type' => 'varchar', + 'length' => 128, + 'not null' => TRUE, + 'default' => '' + ), + // @todo 'parent_name' is redundant with the data in the 'children' + // entry, brings a risk of inconsistent data. This should be removed from + // the schema and pre-computed it if needed in field_group_get_groups(). + 'parent_name' => array( + 'type' => 'varchar', + 'length' => 32, + 'not null' => TRUE, + 'default' => '', + 'description' => 'The parent name for a group', + ), + 'data' => array( + 'type' => 'blob', + 'size' => 'big', + 'not null' => TRUE, + 'serialize' => TRUE, + 'description' => 'Serialized data containing the group properties that do not warrant a dedicated column.', + ), + ), + 'primary key' => array('id'), + 'indexes' => array( + 'group_name' => array('group_name'), + ), + 'unique keys' => array( + 'identifier' => array('identifier'), + ), + ); + return $schema; +} + +/** + * Utility function: fetch all the field_group definitions from the database. + */ +function _field_group_install_read_groups() { + $groups = array(); + if (db_table_exists('content_group')) { + $query = db_select('content_group', 'cg', array('fetch' => PDO::FETCH_ASSOC)) + ->fields('cg') + // We only want non-multigroups. + ->condition('group_type', 'standard'); + foreach ($query->execute() as $record) { + $record['settings'] = unserialize($record['settings']); + $groups[$record['group_name']] = $record; + } + foreach ($groups as $key => $group) { + $query2 = db_select('content_group_fields', 'cgf', array('fetch' => PDO::FETCH_ASSOC)) + ->fields('cgf') + ->condition('group_name', $group['group_name']); + foreach ($query2->execute() as $field) { + $groups[$field['group_name']]['children'][] = $field; + } + } + } + return $groups; +} + +/** + * Implements of hook_install(). + * + * Because this is a new module in D7, hook_update_N() doesn't help D6 + * users who upgrade to run the migration path. So, we try that here as + * the module is being installed. + */ +function field_group_install() { + + $groups = _field_group_install_read_groups(); + module_load_include('module', 'field_group'); + + if (!empty($groups)) { + + module_load_include('module', 'ctools'); + ctools_include('export'); + + foreach ($groups as $group) { + + $group = (object) $group; + + $new = new stdClass(); + $new->group_name = $group->group_name; + $new->entity_type = 'node'; + $new->bundle = $group->type_name; + $new->label = $group->label; + $new->parent_name = ''; + $new->children = array(); + foreach ($group->children as $child) { + $new->children[] = $child['field_name']; + } + + // The form. + $new->id = NULL; + $new->weight = $group->weight; + $new->mode = 'form'; + $new->format_type = 'fieldset'; + $new->format_settings = array( + 'formatter' => preg_match("/fieldset/", $group->settings['form']['style']) ? 'collapsible' : 'collapsed', + 'instance_settings' => array(), + ); + $new->identifier = $new->group_name . '|' . $new->entity_type . '|' . $new->bundle . '|' . $new->mode; + ctools_export_crud_save('field_group', $new); + + // The full node. + $new->id = NULL; + $new->weight = $group->weight; + $new->mode = 'default'; + $new->format_type = $group->settings['display']['full']['format']; + $new->format_settings = array( + 'formatter' => 'collapsible', + 'instance_settings' => array(), + ); + $new->identifier = $new->group_name . '|' . $new->entity_type . '|' . $new->bundle . '|' . $new->mode; + ctools_export_crud_save('field_group', $new); + + // The teaser node. + $new->id = NULL; + $new->weight = $group->weight; + $new->mode = 'teaser'; + $new->format_type = $group->settings['display']['teaser']['format']; + $new->format_settings = array( + 'formatter' => 'collapsible', + 'instance_settings' => array(), + ); + $new->identifier = $new->group_name . '|' . $new->entity_type . '|' . $new->bundle . '|' . $new->mode; + ctools_export_crud_save('field_group', $new); + + } + + } + + // Set weight to 1. + db_update('system') + ->fields(array('weight' => 1)) + ->condition('name', 'field_group') + ->execute(); + +} + +/** + * Update hook on the field_group table to add an unique identifier. + */ +function field_group_update_7001() { + + if (!db_field_exists('field_group', 'identifier')) { + // Add the new string identifier field for ctools. + db_add_field('field_group', 'identifier', array( + 'type' => 'varchar', + 'length' => 255, + 'not null' => TRUE, + 'default' => '', + 'description' => 'The unique string identifier for a group.', + )); + + module_load_include('module', 'field_group'); + _field_group_recreate_identifiers(); + + } + + db_update('system') + ->fields(array('weight' => 1)) + ->condition('name', 'field_group') + ->execute(); + +} + +/** + * Update hook to clear cache for new changes to take effect. + */ +function field_group_update_7002() { + + module_load_include('module', 'field_group'); + + // This hook is called to satify people with older version of field_group. + // This will recreate all identifiers for the field_groups known in database. + // At the moment, we only trigger field_groups that are stored in the database, where + // we should maybe get all field_groups as ctools has registered them. + // See http://drupal.org/node/1169146. + // See http://drupal.org/node/1018550. + _field_group_recreate_identifiers(); + +} + +/** + * Update hook to recreate identifiers. + * @see function field_group_update_7002. + */ +function field_group_update_7003() { + + module_load_include('module', 'field_group'); + _field_group_recreate_identifiers(); + +} \ No newline at end of file diff --git a/drupal/sites/all/modules/field_group/field_group.js b/drupal/sites/all/modules/field_group/field_group.js new file mode 100755 index 0000000..72f3444 --- /dev/null +++ b/drupal/sites/all/modules/field_group/field_group.js @@ -0,0 +1,195 @@ + +(function($) { + +/** + * Drupal FieldGroup object. + */ +Drupal.FieldGroup = Drupal.FieldGroup || {}; +Drupal.FieldGroup.Effects = Drupal.FieldGroup.Effects || {}; +Drupal.FieldGroup.groupWithfocus = null; + +Drupal.FieldGroup.setGroupWithfocus = function(element) { + element.css({display: 'block'}); + Drupal.FieldGroup.groupWithfocus = element; +} + +/** + * Implements Drupal.FieldGroup.processHook(). + */ +Drupal.FieldGroup.Effects.processFieldset = { + execute: function (context, settings, type) { + if (type == 'form') { + // Add required fields mark to any fieldsets containing required fields + $('fieldset.fieldset', context).once('fieldgroup-effects', function(i) { + if ($(this).is('.required-fields') && $(this).find('.form-required').length > 0) { + $('legend span.fieldset-legend', $(this)).eq(0).append(' ').append($('.form-required').eq(0).clone()); + } + if ($('.error', $(this)).length) { + $('legend span.fieldset-legend', $(this)).eq(0).addClass('error'); + Drupal.FieldGroup.setGroupWithfocus($(this)); + } + }); + } + } +} + +/** + * Implements Drupal.FieldGroup.processHook(). + */ +Drupal.FieldGroup.Effects.processAccordion = { + execute: function (context, settings, type) { + $('div.field-group-accordion-wrapper', context).once('fieldgroup-effects', function () { + var wrapper = $(this); + + wrapper.accordion({ + autoHeight: false, + active: '.field-group-accordion-active', + collapsible: true, + changestart: function(event, ui) { + if ($(this).hasClass('effect-none')) { + ui.options.animated = false; + } + else { + ui.options.animated = 'slide'; + } + } + }); + + if (type == 'form') { + // Add required fields mark to any element containing required fields + wrapper.find('div.accordion-item').each(function(i){ + if ($(this).is('.required-fields') && $(this).find('.form-required').length > 0) { + $('h3.ui-accordion-header').eq(i).append(' ').append($('.form-required').eq(0).clone()); + } + if ($('.error', $(this)).length) { + $('h3.ui-accordion-header').eq(i).addClass('error'); + var activeOne = $(this).parent().accordion("activate" , i); + $('.ui-accordion-content-active', activeOne).css({height: 'auto', width: 'auto', display: 'block'}); + } + }); + } + }); + } +} + +/** + * Implements Drupal.FieldGroup.processHook(). + */ +Drupal.FieldGroup.Effects.processHtabs = { + execute: function (context, settings, type) { + if (type == 'form') { + // Add required fields mark to any element containing required fields + $('fieldset.horizontal-tabs-pane', context).once('fieldgroup-effects', function(i) { + if ($(this).is('.required-fields') && $(this).find('.form-required').length > 0) { + $(this).data('horizontalTab').link.find('strong:first').after($('.form-required').eq(0).clone()).after(' '); + } + if ($('.error', $(this)).length) { + $(this).data('horizontalTab').link.parent().addClass('error'); + Drupal.FieldGroup.setGroupWithfocus($(this)); + $(this).data('horizontalTab').focus(); + } + }); + } + } +} + +/** + * Implements Drupal.FieldGroup.processHook(). + */ +Drupal.FieldGroup.Effects.processTabs = { + execute: function (context, settings, type) { + if (type == 'form') { + // Add required fields mark to any fieldsets containing required fields + $('fieldset.vertical-tabs-pane', context).once('fieldgroup-effects', function(i) { + if ($(this).is('.required-fields') && $(this).find('.form-required').length > 0) { + $(this).data('verticalTab').link.find('strong:first').after($('.form-required').eq(0).clone()).after(' '); + } + if ($('.error', $(this)).length) { + $(this).data('verticalTab').link.parent().addClass('error'); + Drupal.FieldGroup.setGroupWithfocus($(this)); + $(this).data('verticalTab').focus(); + } + }); + } + } +} + +/** + * Implements Drupal.FieldGroup.processHook(). + * + * TODO clean this up meaning check if this is really + * necessary. + */ +Drupal.FieldGroup.Effects.processDiv = { + execute: function (context, settings, type) { + + $('div.collapsible', context).once('fieldgroup-effects', function() { + var $wrapper = $(this); + + // Turn the legend into a clickable link, but retain span.field-group-format-toggler + // for CSS positioning. + + var $toggler = $('span.field-group-format-toggler:first', $wrapper); + var $link = $(''); + $link.prepend($toggler.contents()); + + // Add required field markers if needed + if ($(this).is('.required-fields') && $(this).find('.form-required').length > 0) { + $link.append(' ').append($('.form-required').eq(0).clone()); + } + + $link.appendTo($toggler); + + // .wrapInner() does not retain bound events. + $link.click(function () { + var wrapper = $wrapper.get(0); + // Don't animate multiple times. + if (!wrapper.animating) { + wrapper.animating = true; + var speed = $wrapper.hasClass('speed-fast') ? 300 : 1000; + if ($wrapper.hasClass('effect-none') && $wrapper.hasClass('speed-none')) { + $('> .field-group-format-wrapper', wrapper).toggle(); + } + else if ($wrapper.hasClass('effect-blind')) { + $('> .field-group-format-wrapper', wrapper).toggle('blind', {}, speed); + } + else { + $('> .field-group-format-wrapper', wrapper).toggle(speed); + } + wrapper.animating = false; + } + $wrapper.toggleClass('collapsed'); + return false; + }); + + }); + } +}; + +/** + * Behaviors. + */ +Drupal.behaviors.fieldGroup = { + attach: function (context, settings) { + if (settings.field_group == undefined) { + return; + } + + // Execute all of them. + $.each(Drupal.FieldGroup.Effects, function (func) { + // We check for a wrapper function in Drupal.field_group as + // alternative for dynamic string function calls. + var type = func.toLowerCase().replace("process", ""); + if (settings.field_group[type] != undefined && $.isFunction(this.execute)) { + this.execute(context, settings, settings.field_group[type]); + } + }); + + // Fixes css for fieldgroups under vertical tabs. + $('.fieldset-wrapper .fieldset > legend').css({display: 'block'}); + $('.vertical-tabs fieldset.fieldset').addClass('default-fallback'); + + } +}; + +})(jQuery); \ No newline at end of file diff --git a/drupal/sites/all/modules/field_group/field_group.module b/drupal/sites/all/modules/field_group/field_group.module new file mode 100755 index 0000000..3254e51 --- /dev/null +++ b/drupal/sites/all/modules/field_group/field_group.module @@ -0,0 +1,1778 @@ + $entity_info) { + if (isset($entity_info['fieldable']) && $entity_info['fieldable']) { + foreach ($entity_info['bundles'] as $bundle_name => $bundle_info) { + if (isset($bundle_info['admin'])) { + // Extract path information from the bundle. + $path = $bundle_info['admin']['path']; + // Different bundles can appear on the same path (e.g. %node_type and + // %comment_node_type). To allow field_group_menu_load() to extract the + // actual bundle object from the translated menu router path + // arguments, we need to identify the argument position of the bundle + // name string ('bundle argument') and pass that position to the menu + // loader. The position needs to be casted into a string; otherwise it + // would be replaced with the bundle name string. + if (isset($bundle_info['admin']['bundle argument'])) { + $bundle_arg = $bundle_info['admin']['bundle argument']; + $bundle_pos = (string) $bundle_arg; + } + else { + $bundle_arg = $bundle_name; + $bundle_pos = '0'; + } + + // This is the position of the %field_group_menu placeholder in the + // items below. + $group_position = count(explode('/', $path)) + 1; + + // Extract access information, providing defaults. + $access = array_intersect_key($bundle_info['admin'], drupal_map_assoc(array('access callback', 'access arguments'))); + $access += array( + 'access callback' => 'user_access', + 'access arguments' => array('administer site configuration'), + ); + + $items["$path/groups/%field_group_menu/delete"] = array( + 'load arguments' => array($entity_type, $bundle_arg, $bundle_pos, '%map'), + 'title' => 'Delete', + 'page callback' => 'drupal_get_form', + 'page arguments' => array('field_group_delete_form', $group_position), + 'type' => MENU_CALLBACK, + 'file' => 'field_group.field_ui.inc', + ) + $access; + } + } + } + } + + return $items; +} + +/** + * Implements hook_permission(). + */ +function field_group_permission() { + return array( + 'administer fieldgroups' => array( + 'title' => t('Administer fieldgroups'), + 'description' => t('Display the administration for fieldgroups.'), + ), + ); +} + +/** + * Menu Wildcard loader function to load group definitions. + * + * @param $group_name + * The name of the group, as contained in the path. + * @param $entity_type + * The name of the entity. + * @param $bundle_name + * The name of the bundle, as contained in the path. + * @param $bundle_pos + * The position of $bundle_name in $map. + * @param $map + * The translated menu router path argument map. + */ +function field_group_menu_load($group_name, $entity_type, $bundle_name, $bundle_pos, $map) { + + if ($bundle_pos > 0) { + $bundle = $map[$bundle_pos]; + $bundle_name = field_extract_bundle($entity_type, $bundle); + } + + $args = func_get_args(); + $args_pop = array_pop($args); + $mode = array_pop($args_pop); + + return field_group_load_field_group($group_name, $entity_type, $bundle_name, $mode); +} + +/** + * Loads a group definition. + * + * @param $group_name + * The name of the group. + * @param $entity_type + * The name of the entity. + * @param $bundle_name + * The name of the bundle. + * @param $mode + * The view mode to load. + */ +function field_group_load_field_group($group_name, $entity_type, $bundle_name, $mode) { + + ctools_include('export'); + $objects = ctools_export_load_object('field_group', 'conditions', array( + 'group_name' => $group_name, + 'entity_type' => $entity_type, + 'bundle' => $bundle_name, + 'mode' => $mode, + )); + $object = array_shift($objects); + + if ($object && isset($object->data)) { + return field_group_unpack($object); + } + + return $object; +} + +/** + * Implements hook_ctools_plugin_api(). + */ +function field_group_ctools_plugin_api($owner, $api) { + if ($owner == 'field_group' && $api == 'field_group') { + return array('version' => 1); + } +} + +/** + * Implements hook_theme(). + */ +function field_group_theme() { + return array( + 'horizontal_tabs' => array( + 'render element' => 'element', + ), + 'multipage' => array( + 'render element' => 'element', + ), + 'multipage_pane' => array( + 'render element' => 'element', + ), + ); +} + +/** + * Implements hook_field_attach_delete_bundle(). + * + * @param String $entity_type + * @param String $bundle + */ +function field_group_field_attach_delete_bundle($entity_type, $bundle) { + + ctools_include('export'); + $list = field_group_read_groups(array('bundle' => $bundle, 'entity_type' => $entity_type)); + + // Delete the entity's entry from field_group of all entities. + // We fetch the field groups first to assign the removal task to ctools. + if (isset($list[$entity_type], $list[$entity_type][$bundle])) { + foreach ($list[$entity_type][$bundle] as $group_mode => $groups) { + foreach ($groups as $group) { + ctools_export_crud_delete('field_group', $group); + } + } + } + +} + +/** + * Implements hook_field_attach_form(). + */ +function field_group_field_attach_form($entity_type, $entity, &$form, &$form_state, $langcode) { + $form['#attached']['css'][] = drupal_get_path('module', 'field_group') . '/field_group.field_ui.css'; + field_group_attach_groups($form, 'form', $form_state); +} + +/** + * Implements hook_form_FORM_ID_alter(). + * Using hook_form_field_ui_field_overview_form_alter. + */ +function field_group_form_field_ui_field_overview_form_alter(&$form, &$form_state) { + form_load_include($form_state, 'inc', 'field_group', 'field_group.field_ui'); + field_group_field_ui_overview_form_alter($form, $form_state); +} + +/** + * Implements hook_form_FORM_ID_alter(). + * Using hook_form_field_ui_display_overview_form_alter. + */ +function field_group_form_field_ui_display_overview_form_alter(&$form, &$form_state) { + form_load_include($form_state, 'inc', 'field_group', 'field_group.field_ui'); + field_group_field_ui_overview_form_alter($form, $form_state, TRUE); +} + +/** + * Implements hook_field_attach_view_alter(). + */ +function field_group_field_attach_view_alter(&$element, $context) { + // Check whether the view mode uses custom display settings or the 'default' mode. + $actual_mode = 'default'; + if (isset($element['#entity_type']) && isset($element['#bundle'])) { + $view_mode_settings = field_view_mode_settings($element['#entity_type'], $element['#bundle']); + $view_mode = $context['view_mode']; + $actual_mode = (!empty($view_mode_settings[$view_mode]['custom_settings']) ? $view_mode : 'default'); + field_group_attach_groups($element, $actual_mode); + } +} + +/** + * Implements hook_field_group_formatter_info(). + */ +function field_group_field_group_formatter_info() { + + return array( + 'form' => array( + 'div' => array( + 'label' => t('Div'), + 'description' => t('This fieldgroup renders the inner content in a simple div with the titel as legend.'), + 'format_types' => array('open', 'collapsible', 'collapsed'), + 'instance_settings' => array('description' => '', 'show_label' => 1, 'label_element' => 'h3', 'effect' => 'none', 'speed' => 'fast', 'classes' => '', 'required_fields' => 1), + 'default_formatter' => 'open', + ), + 'fieldset' => array( + 'label' => t('Fieldset'), + 'description' => t('This fieldgroup renders the inner content in a fieldset with the titel as legend.'), + 'format_types' => array('open', 'collapsible', 'collapsed'), + 'instance_settings' => array('description' => '', 'classes' => '', 'required_fields' => 1), + 'default_formatter' => 'collapsible', + ), + 'tabs' => array( + 'label' => t('Vertical tabs group'), + 'description' => t('This fieldgroup renders child groups in its own vertical tabs wrapper.'), + 'instance_settings' => array('classes' => ''), + ), + 'tab' => array( + 'label' => t('Vertical tab'), + 'description' => t('This fieldgroup renders the content in a fieldset, part of vertical tabs group.'), + 'format_types' => array('open', 'closed'), + 'instance_settings' => array('description' => '', 'classes' => '', 'required_fields' => 1), + 'default_formatter' => 'closed', + ), + 'htabs' => array( + 'label' => ('Horizontal tabs group'), + 'description' => t('This fieldgroup renders child groups in its own horizontal tabs wrapper.'), + 'instance_settings' => array('classes' => ''), + ), + 'htab' => array( + 'label' => t('Horizontal tab item'), + 'format_types' => array('open', 'closed'), + 'description' => t('This fieldgroup renders the content in a fieldset, part of horizontal tabs group.'), + 'default_formatter' => 'closed', + 'instance_settings' => array('description' => '', 'classes' => '', 'required_fields' => 1), + ), + 'multipage-group' => array( + 'label' => ('Multipage group'), + 'description' => t('This fieldgroup renders groups on separate pages.'), + 'instance_settings' => array('classes' => '', 'page_header' => 3, 'move_additional' => 1, 'page_counter' => 1, 'move_button' => 0), + ), + 'multipage' => array( + 'label' => t('Multipage'), + 'format_types' => array('start', 'no-start'), + 'description' => t('This fieldgroup renders the content in a page.'), + 'default_formatter' => 'no-start', + 'instance_settings' => array('description' => '', 'classes' => '', 'required_fields' => 1), + ), + 'accordion' => array( + 'label' => t('Accordion group'), + 'description' => t('This fieldgroup renders child groups as jQuery accordion.'), + 'instance_settings' => array('effect' => 'none', 'classes' => ''), + ), + 'accordion-item' => array( + 'label' => t('Accordion item'), + 'format_types' => array('open', 'closed'), + 'description' => t('This fieldgroup renders the content in a div, part of accordion group.'), + 'default_formatter' => 'closed', + 'instance_settings' => array('description' => '', 'classes' => '', 'required_fields' => 1), + ), + ), + 'display' => array( + 'div' => array( + 'label' => t('Div'), + 'description' => t('This fieldgroup renders the inner content in a simple div with the titel as legend.'), + 'format_types' => array('open', 'collapsible', 'collapsed'), + 'instance_settings' => array('description' => '', 'show_label' => 1, 'label_element' => 'h3', 'effect' => 'none', 'speed' => 'fast', 'classes' => ''), + 'default_formatter' => 'collapsible', + ), + 'fieldset' => array( + 'label' => t('Fieldset'), + 'description' => t('This fieldgroup renders the inner content in a fieldset with the titel as legend.'), + 'format_types' => array('open', 'collapsible', 'collapsed'), + 'instance_settings' => array('description' => '', 'classes' => ''), + 'default_formatter' => 'collapsible', + ), + 'tabs' => array( + 'label' => t('Vertical tabs group'), + 'description' => t('This fieldgroup renders child groups in its own vertical tabs wrapper.'), + 'instance_settings' => array('classes' => ''), + ), + 'tab' => array( + 'label' => t('Vertical tab'), + 'description' => t('This fieldgroup renders the content in a fieldset, part of vertical tabs group.'), + 'format_types' => array('open', 'closed'), + 'instance_settings' => array('description' => '', 'classes' => ''), + 'default_formatter' => 'closed', + ), + 'htabs' => array( + 'label' => ('Horizontal tabs group'), + 'description' => t('This fieldgroup renders child groups in its own horizontal tabs wrapper.'), + 'instance_settings' => array('classes' => ''), + ), + 'htab' => array( + 'label' => t('Horizontal tab item'), + 'format_types' => array('open', 'closed'), + 'description' => t('This fieldgroup renders the content in a fieldset, part of horizontal tabs group.'), + 'instance_settings' => array('description' => '', 'classes' => ''), + 'default_formatter' => 'closed', + ), + 'accordion' => array( + 'label' => t('Accordion group'), + 'description' => t('This fieldgroup renders child groups as jQuery accordion.'), + 'instance_settings' => array('description' => '', 'classes' => ''), + ), + 'accordion-item' => array( + 'label' => t('Accordion item'), + 'format_types' => array('open', 'closed'), + 'description' => t('This fieldgroup renders the content in a div, part of accordion group.'), + 'instance_settings' => array('classes' => ''), + 'default_formatter' => 'closed', + ), + ), + ); +} + +/** + * Implements hook_field_group_format_settings(). + * If the group has no format settings, default ones will be added. + * @params Object $group The group object. + * @return Array $form The form element for the format settings. + */ +function field_group_field_group_format_settings($group) { + // Add a wrapper for extra settings to use by others. + $form = array( + 'instance_settings' => array( + '#tree' => TRUE, + '#weight' => 2, + ), + ); + + $field_group_types = field_group_formatter_info(); + $mode = $group->mode == 'form' ? 'form' : 'display'; + $formatter = $field_group_types[$mode][$group->format_type]; + + // Add the required formatter type selector. + if (isset($formatter['format_types'])) { + $form['formatter'] = array( + '#title' => t('Fieldgroup settings'), + '#type' => 'select', + '#options' => drupal_map_assoc($formatter['format_types']), + '#default_value' => isset($group->format_settings['formatter']) ? $group->format_settings['formatter'] : $formatter['default_formatter'], + '#weight' => 1, + ); + } + + if (isset($formatter['instance_settings']['required_fields']) && $mode == 'form') { + $form['instance_settings']['required_fields'] = array( + '#type' => 'checkbox', + '#title' => t('Mark group for required fields.'), + '#default_value' => isset($group->format_settings['instance_settings']['required_fields']) ? $group->format_settings['instance_settings']['required_fields'] : (isset($formatter['instance_settings']['required_fields']) ? $formatter['instance_settings']['required_fields'] : ''), + '#weight' => 2, + ); + } + + if (isset($formatter['instance_settings']['classes'])) { + $form['instance_settings']['classes'] = array( + '#title' => t('Extra CSS classes'), + '#type' => 'textfield', + '#default_value' => isset($group->format_settings['instance_settings']['classes']) ? $group->format_settings['instance_settings']['classes'] : (isset($formatter['instance_settings']['classes']) ? $formatter['instance_settings']['classes'] : ''), + '#weight' => 3, + '#element_validate' => array('field_group_validate_css_class'), + ); + } + if (isset($formatter['instance_settings']['description'])) { + $form['instance_settings']['description'] = array( + '#title' => t('Description'), + '#type' => 'textarea', + '#default_value' => isset($group->format_settings['instance_settings']['description']) ? $group->format_settings['instance_settings']['description'] : (isset($formatter['instance_settings']['description']) ? $formatter['instance_settings']['description'] : ''), + '#weight' => 0, + ); + } + + // Add optional instance_settings. + switch ($group->format_type) { + case 'div': + $form['instance_settings']['show_label'] = array( + '#title' => t('Show label'), + '#type' => 'select', + '#options' => array(0 => t('No'), 1 => t('Yes')), + '#default_value' => isset($group->format_settings['instance_settings']['show_label']) ? $group->format_settings['instance_settings']['show_label'] : $formatter['instance_settings']['show_label'], + '#weight' => 2, + ); + $form['instance_settings']['label_element'] = array( + '#title' => t('Label element'), + '#type' => 'select', + '#options' => array('h2' => t('Header 2'), 'h3' => t('Header 3')), + '#default_value' => isset($group->format_settings['instance_settings']['label_element']) ? $group->format_settings['instance_settings']['label_element'] : $formatter['instance_settings']['label_element'], + '#weight' => 2, + ); + $form['instance_settings']['effect'] = array( + '#title' => t('Effect'), + '#type' => 'select', + '#options' => array('none' => t('None'), 'blind' => t('Blind')), + '#default_value' => isset($group->format_settings['instance_settings']['effect']) ? $group->format_settings['instance_settings']['effect'] : $formatter['instance_settings']['effect'], + '#weight' => 2, + ); + $form['instance_settings']['speed'] = array( + '#title' => t('Speed'), + '#type' => 'select', + '#options' => array('none' => t('None'), 'slow' => t('Slow'), 'fast' => t('Fast')), + '#default_value' => isset($group->format_settings['instance_settings']['speed']) ? $group->format_settings['instance_settings']['speed'] : $formatter['instance_settings']['speed'], + '#weight' => 3, + ); + break; + case 'fieldset': + break; + case 'multipage-group': + $form['instance_settings']['page_header'] = array( + '#title' => t('Format page title'), + '#type' => 'select', + '#options' => array(0 => t('None'), 1 => t('Label only'), 2 => t('Step 1 of 10'), 3 => t('Step 1 of 10 [Label]'),), + '#default_value' => isset($group->format_settings['instance_settings']['page_header']) ? $group->format_settings['instance_settings']['page_header'] : $formatter['instance_settings']['page_header'], + '#weight' => 1, + ); + $form['instance_settings']['page_counter'] = array( + '#title' => t('Add a page counter at the bottom'), + '#type' => 'select', + '#options' => array(0 => t('No'), 1 => t('Format 1 / 10'), 2 => t('The count number only')), + '#default_value' => isset($group->format_settings['instance_settings']['page_counter']) ? $group->format_settings['instance_settings']['page_counter'] : $formatter['instance_settings']['page_counter'], + '#weight' => 2, + ); + $form['instance_settings']['move_button'] = array( + '#title' => t('Move submit button to last multipage'), + '#type' => 'select', + '#options' => array(0 => t('No'), 1 => t('Yes')), + '#default_value' => isset($group->format_settings['instance_settings']['move_button']) ? $group->format_settings['instance_settings']['move_button'] : $formatter['instance_settings']['move_button'], + '#weight' => 3, + ); + $form['instance_settings']['move_additional'] = array( + '#title' => t('Move additional settings to last multipage (if available)'), + '#type' => 'select', + '#options' => array(0 => t('No'), 1 => t('Yes')), + '#default_value' => isset($group->format_settings['instance_settings']['move_additional']) ? $group->format_settings['instance_settings']['move_additional'] : $formatter['instance_settings']['move_additional'], + '#weight' => 4, + ); + case 'tabs': + case 'htabs': + break; + case 'accordion': + $form['instance_settings']['effect'] = array( + '#title' => t('Effect'), + '#type' => 'select', + '#options' => array('none' => t('None'), 'bounceslide' => t('Bounce slide')), + '#default_value' => isset($group->format_settings['instance_settings']['effect']) ? $group->format_settings['instance_settings']['effect'] : $formatter['instance_settings']['effect'], + '#weight' => 2, + ); + break; + case 'multipage': + break; + case 'tab': + case 'htab': + case 'accordion-item': + default: + } + + return $form; +} + +/** + * Helper function to prepare basic variables needed for most formatters. + * + * Called in field_group_field_group_pre_render(), but can also be called in + * other implementations of hook_field_group_pre_render(). + */ +function field_group_pre_render_prepare(&$group) { + + // Prepare extra classes. + $group->classes = array('field-group-' . $group->format_type, str_replace('_', '-', $group->group_name)); + if (isset($group->format_settings['formatter'])) { + $group->collapsible = in_array($group->format_settings['formatter'], array('collapsible', 'collapsed')); + // Open or closed horizontal or vertical tabs will be collapsible by default. + if ($group->format_type == 'tab' || $group->format_type == 'htab') { + $group->collapsible = TRUE; + } + $group->collapsed = in_array($group->format_settings['formatter'], array('collapsed', 'closed')); + if ($group->collapsible) { + $group->classes[] = 'collapsible'; + if ($group->collapsed) { + $group->classes[] = 'collapsed'; + } + } + } + + // Add a required-fields class to trigger the js. + if (isset($group->format_settings['instance_settings']) && !empty($group->format_settings['instance_settings']['required_fields'])) { + $group->classes[] = 'required-fields'; + } + + $group->classes = implode(' ', $group->classes); + if (isset($group->format_settings['instance_settings'], $group->format_settings['instance_settings']['classes'])) { + $group->classes .= ' ' . check_plain($group->format_settings['instance_settings']['classes']); + } + + $group->description = isset($group->format_settings['instance_settings']['description']) ? filter_xss_admin($group->format_settings['instance_settings']['description']) : ''; + +} + +/** + * Implements hook_field_group_pre_render(). + * + * @param Array $elements by address. + * @param Object $group The Field group info. + */ +function field_group_field_group_pre_render(& $element, &$group, & $form) { + + field_group_pre_render_prepare($group); + + $view_mode = isset($form['#view_mode']) ? $form['#view_mode'] : 'form'; + + // Add all field_group format types to the js settings. + $form['#attached']['js'][] = array( + 'data' => array('field_group' => array($group->format_type => $view_mode)), + 'type' => 'setting', + ); + $form['#attached']['js'][] = 'misc/form.js'; + $form['#attached']['js'][] = 'misc/collapse.js'; + + $element['#id'] = $form['#entity_type'] . '_' . $form['#bundle'] . '_' . $view_mode . '_' . $group->group_name; + $element['#weight'] = $group->weight; + + // Call the pre render function for the format type. + $function = "field_group_pre_render_" . str_replace("-", "_", $group->format_type); + if (function_exists($function)) { + $function($element, $group, $form); + } + +} + +/** + * Implements field_group_pre_render_. + * Format type: Fieldset. + * + * @param $element The field group form element. + * @param $group The Field group object prepared for pre_render. + * @param $form The root element or form. + */ +function field_group_pre_render_fieldset(&$element, $group, &$form) { + + $element += array( + '#type' => 'fieldset', + '#title' => check_plain(t($group->label)), + '#collapsible' => $group->collapsible, + '#collapsed' => $group->collapsed, + '#pre_render' => array(), + '#attributes' => array('class' => explode(' ', $group->classes)), + '#description' => $group->description, + ); + $element['#attached']['js'][] = 'misc/form.js'; + $element['#attached']['js'][] = 'misc/collapse.js'; + +} + +/** + * Implements field_group_pre_render_. + * Format type: Div. + * + * @param $element The field group form element. + * @param $group The Field group object prepared for pre_render. + * @param $form The root element or form. + */ +function field_group_pre_render_div(&$element, $group, &$form) { + + $show_label = isset($group->format_settings['instance_settings']['show_label']) ? $group->format_settings['instance_settings']['show_label'] : 0; + $label_element = isset($group->format_settings['instance_settings']['label_element']) ? $group->format_settings['instance_settings']['label_element'] : 'h2'; + $effect = isset($group->format_settings['instance_settings']['effect']) ? $group->format_settings['instance_settings']['effect'] : 'none'; + $speed = isset($group->format_settings['instance_settings']['speed']) ? $group->format_settings['instance_settings']['speed'] : 'none'; + + $element['#type'] = 'markup'; + + $group->classes .= " speed-$speed effect-$effect"; + if ($group->format_settings['formatter'] != 'open') { + $element['#prefix'] = '
+ <' . $label_element . '>' . check_plain(t($group->label)) . ' +
'; + $element['#suffix'] = '
'; + } + else { + $element['#prefix'] = '
'; + if ($show_label) { + $element['#prefix'] .= '<' . $label_element . '>' . check_plain(t($group->label)) . ''; + } + $element['#suffix'] = '
'; + } + if (!empty($group->description)) { + $element['#prefix'] .= '
' . $group->description . '
'; + } + + if ($effect == 'blind') { + drupal_add_library('system', 'effects.blind'); + } + +} + +/** + * Implements field_group_pre_render_. + * Format type: Accordion. + * + * @param $element The field group form element. + * @param $group The Field group object prepared for pre_render. + * @param $form The root element or form. + */ +function field_group_pre_render_accordion(&$element, $group, &$form) { + $effect = isset($group->format_settings['instance_settings']['effect']) ? $group->format_settings['instance_settings']['effect'] : 'none'; + + $group->classes .= " effect-$effect"; + + $element += array( + '#type' => 'markup', + '#prefix' => '
', + '#suffix' => '
', + ); +} + +/** + * Implements field_group_pre_render_. + * Format type: Accordion item. + * + * @param $element The field group form element. + * @param $group The Field group object prepared for pre_render. + * @param $form The root element or form. + */ +function field_group_pre_render_accordion_item(&$element, $group, &$form) { + + $element += array( + '#type' => 'markup', + '#prefix' => '

' . check_plain(t($group->label)) . '

+
', + '#suffix' => '
', + //'#attributes' => array('class' => array($group->format_type)), + ); + if (!empty($group->description)) { + $element['#prefix'] .= '
' . $group->description . '
'; + } + drupal_add_library('system', 'ui.accordion'); + +} + +/** + * Implements field_group_pre_render_. + * Format type: Horizontal tabs group. + * + * @param $element The field group form element. + * @param $group The Field group object prepared for pre_render. + * @param $form The root element or form. + */ +function field_group_pre_render_htabs(&$element, $group, &$form) { + + $element += array( + '#type' => 'horizontal_tabs', + '#title' => check_plain(t($group->label)), + '#theme_wrappers' => array('horizontal_tabs'), + '#prefix' => '
', + '#suffix' => '
', + ); + +} + +/** + * Implements field_group_pre_render_. + * Format type: Horizontal tab. + * + * @param $element The field group form element. + * @param $group The Field group object prepared for pre_render. + * @param $form The root element or form. + */ +function field_group_pre_render_htab(&$element, $group, &$form) { + + $element += array( + '#type' => 'fieldset', + '#title' => check_plain(t($group->label)), + '#collapsible' => $group->collapsible, + '#collapsed' => $group->collapsed, + '#attributes' => array('class' => explode(" ", $group->classes)), + '#group' => $group->parent_name, + // very important. Cannot be added on the form! + '#parents' => array($group->parent_name), + '#description' => $group->description, + ); + +} + +/** + * Implements field_group_pre_render_. + * Format type: Multipage group. + * + * @param $element The field group form element. + * @param $group The Field group object prepared for pre_render. + * @param $form The root element or form. + */ +function field_group_pre_render_multipage_group(&$element, &$group, &$form) { + + $multipage_element = array( + '#type' => 'multipage', + '#theme_wrappers' => array('multipage'), + '#prefix' => '
', + '#suffix' => '
', + ); + + $element += $multipage_element; + + $move_additional = isset($group->format_settings['instance_settings']['move_additional']) ? ($group->format_settings['instance_settings']['move_additional'] && isset($form['additional_settings'])) : isset($form['additional_settings']); + $move_button = isset($group->format_settings['instance_settings']['move_button']) ? $group->format_settings['instance_settings']['move_button'] : 0; + + drupal_add_js(array( + 'field_group' => array( + 'multipage_move_submit' => (bool) $move_button, + 'multipage_move_additional' => (bool) $move_additional + ) + ), 'setting'); + +} + +/** + * Implements field_group_pre_render_. + * Format type: Multipage. + * + * @param $element The field group form element. + * @param $group The Field group object prepared for pre_render. + * @param $form The root element or form. + */ +function field_group_pre_render_multipage(&$element, $group, &$form) { + + $group->classes .= $group->format_settings['formatter'] == 'start' ? ' multipage-open' : ' multipage-closed'; + $element += array( + '#type' => 'multipage_pane', + '#title' => check_plain(t($group->label)), + '#collapsible' => $group->collapsible, + '#collapsed' => $group->collapsed, + '#attributes' => array('class' => explode(" ", $group->classes)), + '#group' => $group->parent_name, + '#group_object' => $group, + '#parent_group_object' => $form['#groups'][$group->parent_name], + // very important. Cannot be added on the form! + '#parents' => array($group->parent_name), + '#description' => $group->description, + ); + +} + +/** + * Implements field_group_pre_render_. + * Format type: Vertical tabs wrapper. + * + * @param $element The field group form element. + * @param $group The Field group object prepared for pre_render. + * @param $form The root element or form. + */ +function field_group_pre_render_tabs(&$element, $group, &$form) { + + $element += array( + '#type' => 'vertical_tabs', + '#theme_wrappers' => array('vertical_tabs'), + '#prefix' => '
', + '#suffix' => '
', + ); + $element[$group->group_name . '__active_tab'] = array( + '#type' => 'hidden', + '#default_value' => '', + '#attributes' => array('class' => array('vertical-tabs-active-tab')), + ); + $form['#attached']['library'][] = array('system', 'drupal.form'); + $form['#attached']['library'][] = array('system', 'drupal.collapse'); + +} + +/** + * Implements field_group_pre_render_. + * Format type: Vertical tab. + * + * @param $element The field group form element. + * @param $group The Field group object prepared for pre_render. + * @param $form The root element or form. + */ +function field_group_pre_render_tab(&$element, $group, &$form) { + + $view_mode = isset($form['#view_mode']) ? $form['#view_mode'] : 'form'; + + // Could be it never runs through htab. + $form['#attached']['js'][] = array( + 'data' => array('field_group' => array('tabs' => $view_mode)), + 'type' => 'setting', + ); + + $add = array( + '#type' => 'fieldset', + '#id' => 'edit-' . $group->group_name, + '#title' => check_plain(t($group->label)), + '#collapsible' => $group->collapsible, + '#collapsed' => $group->collapsed, + '#attributes' => array('class' => explode(" ", $group->classes)), + '#description' => $group->description, + ); + + // Front-end and back-end on configuration will lead + // to vertical tabs nested in a separate vertical group. + if ($view_mode != 'form') { + $add['#group'] = empty($group->parent_name) ? 'additional_settings' : $group->parent_name; + $add['#parents'] = array($add['#group']); + $element += $add; + } + // Form fieldgroups which are nested into a vertical tab group + // are handled a little different. + elseif (!empty($group->parent_name)) { + $add['#group'] = $group->parent_name; + $element += $add; + } + // Forms "can" have additional settins. We'll try to locate it first, if not + // exists, field_group will create a parallel additional settings entry. + else { + // Create the fieldgroup element. + $add['#parents'] = array('additional_settings'); + $add['#group'] = 'additional_settings'; + $add['#weight'] = -30 + $group->weight; // hardcoded to bring our extra additional vtabs on top. + + // Check if the additional_settings exist for this type of form. + if (isset($form['additional_settings']['group']['#groups']['additional_settings'])) { + + // Merge fieldgroups with the core additional settings. + $form['additional_settings']['group']['#groups']['additional_settings'][$group->group_name] = $add; + $form['additional_settings']['group']['#groups'][$group->group_name] = array('#group_exists' => TRUE); + // Nest the fields inside the appropriate structure. + foreach (element_children($element) as $fieldname) { + $form['additional_settings']['group']['#groups']['additional_settings'][$group->group_name][$fieldname] = &$element[$fieldname]; + unset($element[$fieldname]); + } + } + // Assumption the wrapper is in the root. This could be done by field_group itself + // in previous loop of tabs in same wrapper or even some other contrib / custom module. + else { + if (!isset($form['additional_settings']['#type'])) { + $form['additional_settings'] = array( + '#type' => 'vertical_tabs', + '#weight' => $group->weight, + '#theme_wrappers' => array('vertical_tabs'), + '#prefix' => '
', + '#suffix' => '
', + ); + $form['#attached']['js'][] = 'misc/form.js'; + $form['#attached']['js'][] = 'misc/collapse.js'; + } + $form['additional_settings'][$group->group_name] = $add; + // Nest the fields inside the appropriate structure. + foreach (element_children($element) as $fieldname) { + $form['additional_settings'][$group->group_name][$fieldname] = &$element[$fieldname]; + unset($element[$fieldname]); + } + } + } + +} + +/** + * Implements hook_field_group_build_pre_render_alter(). + * @param Array $elements by address. + */ +function field_group_field_group_build_pre_render_alter(& $element) { + + // Someone is doing a node view, in a node view. Reset content. + // TODO Check if this breaks something else. + if (isset($element['#node']->content) && count($element['#node']->content) > 0) { + $element['#node']->content = array(); + } + + $display = isset($element['#view_mode']); + $groups = array_keys($element['#groups']); + + // Dish the fieldgroups with no fields for non-forms. + if ($display) { + field_group_remove_empty_display_groups($element, $groups); + } + else { + // Fix the problem on forms with additional settings. + field_group_remove_empty_form_groups('form', $element, $groups, $element['#groups'], $element['#entity_type']); + } + + // Add the default field_group javascript and stylesheet. + $element['#attached']['js'][] = drupal_get_path('module', 'field_group') . '/field_group.js'; + $element['#attached']['css'][] = drupal_get_path('module', 'field_group') . '/field_group.css'; + + // Move additional settings to the last multipage pane if configured that way. + // Note that multipages MUST be in the root of the form. + foreach (element_children($element) as $name) { + if (isset($element[$name]['#type']) && $element[$name]['#type'] == 'multipage' && isset($element['additional_settings'])) { + $parent_group = $element['#groups'][$name]; + $move_additional = isset($parent_group->format_settings['instance_settings']['move_additional']) ? $parent_group->format_settings['instance_settings']['move_additional'] : 1; + $last_pane = NULL; + foreach (element_children($element[$name], TRUE) as $pane) { + $last_pane = $pane; + } + $element[$name][$last_pane]['additional_settings'] = $element['additional_settings']; + unset($element['additional_settings']); + } + } + +} + +/** + * Remove empty groups on forms. + * + * @param String $parent_name + * The name of the element. + * @param array $element + * The element to check the empty state. + * @param array $groups + * Array of group objects. + */ +function field_group_remove_empty_form_groups($name, & $element, $groups, &$form_groups, $entity) { + + $exceptions = array('user__account', 'comment__author'); + + $children = element_children($element); + + $hasChildren = FALSE; + if (count($children)) { + foreach ($children as $childname) { + if (in_array($childname, $groups)) { + field_group_remove_empty_form_groups($childname, $element[$childname], $groups, $form_groups, $entity); + } + $exception = $entity . '__' . $childname; + $hasChildren = $hasChildren ? TRUE : (isset($element[$childname]['#type']) || in_array($exception, $exceptions)); + } + } + + if (!$hasChildren) { + + // Remove empty elements from the #groups. + if (empty($element) && isset($form_groups[$name]) && !is_array($form_groups[$name])) { + foreach ($form_groups as $group_name => $group) { + if (isset($group->children)) { + $group_children = array_flip($group->children); + if (isset($group_children[$name])) { + unset($form_groups[$group_name]->children[$group_children[$name]]); + } + } + } + } + + $element['#access'] = FALSE; + + } + +} + +/** + * Remove empty groups on entity display. + * @param array $element + * The element to check the empty state. + * @param array $groups + * Array of group objects. + */ +function field_group_remove_empty_display_groups(& $element, $groups) { + + $empty_child = TRUE; + $empty_group = TRUE; + + // Loop through the children for current element. + foreach (element_children($element) as $name) { + + // Descend if the child is a group. + if (in_array($name, $groups)) { + $empty_child = field_group_remove_empty_display_groups($element[$name], $groups); + if (!$empty_child) { + $empty_group = FALSE; + } + } + // Child is a field, the element is not empty. + elseif (!empty($element[$name])) { + $empty_group = FALSE; + } + + } + + // Reset an empty group. + if ($empty_group) { + $element = NULL; + } + + return $empty_group; + +} + +/** + * Implements hook_field_group_format_summary(). + */ +function field_group_field_group_format_summary($group) { + + $group_form = module_invoke_all('field_group_format_settings', $group); + + $output = ''; + if (isset($group->format_settings['formatter'])) { + $output .= '' . $group->format_type . ' ' . $group->format_settings['formatter'] . ''; + } + if (isset($group->format_settings['instance_settings'])) { + $last = end($group->format_settings['instance_settings']); + $output .= '
'; + foreach ($group->format_settings['instance_settings'] as $key => $value) { + if (empty($value)) { + continue; + } + + $output .= '' . $key . ' '; + + if (isset($group_form['instance_settings'], $group_form['instance_settings'][$key]['#options'])) { + $value = $group_form['instance_settings'][$key]['#options'][$value]; + } + + // Shorten the string. + if (drupal_strlen($value) > 38) { + $value = truncate_utf8($value, 50, TRUE, TRUE); + } + // If still numeric, handle it as yes or no. + elseif (is_numeric($value)) { + $value = $value == '1' ? t('yes') : t('no'); + } + $output .= check_plain($value); + $output .= $last == $value ? ' ' : '
'; + } + } + return $output; +} + +/** + * Implements hook_element_info(). + */ +function field_group_element_info() { + $types['horizontal_tabs'] = array( + '#theme_wrappers' => array('horizontal_tabs'), + '#default_tab' => '', + '#process' => array('form_process_horizontal_tabs'), + ); + $types['multipage'] = array( + '#theme_wrappers' => array('multipage'), + '#default_tab' => '', + '#process' => array('form_process_multipage'), + ); + $types['multipage_pane'] = array( + '#value' => NULL, + '#process' => array('form_process_fieldset', 'ajax_process_form'), + '#pre_render' => array('form_pre_render_fieldset'), + '#theme_wrappers' => array('multipage_pane'), + ); + return $types; +} + +/** + * Implements hook_library(). + */ +function field_group_library() { + + $path = drupal_get_path('module', 'field_group'); + // Horizontal Tabs. + $libraries['horizontal-tabs'] = array( + 'title' => 'Horizontal Tabs', + 'website' => 'http://drupal.org/node/323112', + 'version' => '1.0', + 'js' => array( + $path . '/horizontal-tabs/horizontal-tabs.js' => array(), + ), + 'css' => array( + $path . '/horizontal-tabs/horizontal-tabs.css' => array(), + ), + ); + // Multipage Tabs. + $libraries['multipage'] = array( + 'title' => 'Multipage', + 'website' => 'http://drupal.org/node/323112', + 'version' => '1.0', + 'js' => array( + $path . '/multipage/multipage.js' => array(), + ), + 'css' => array( + $path . '/multipage/multipage.css' => array(), + ), + ); + + return $libraries; +} + +/** + * Implements hook_field_extra_fields(). + */ +function field_group_field_extra_fields() { + $extra = array(); + + $extra['user']['user'] = array('form' => array()); + + // User picture field to integrate with user module. + if (variable_get('user_pictures', 0)) { + $extra['user']['user']['form']['picture'] = array( + 'label' => t('Picture'), + 'description' => t('User picture'), + 'weight' => 5, + ); + } + + // Field to itegrate with overlay module. + if (module_exists('overlay')) { + $extra['user']['user']['form']['overlay_control'] = array( + 'label' => t('Administrative overlay'), + 'description' => t('Administrative overlay'), + 'weight' => 5, + ); + } + + // Field to itegrate with contact module. + if (module_exists('contact')) { + $extra['user']['user']['form']['contact'] = array( + 'label' => t('Contact'), + 'description' => t('Contact user element'), + 'weight' => 5, + ); + } + + // Field to integrate with the locale module. + if (module_exists('locale')) { + $extra['user']['user']['form']['locale'] = array( + 'label' => t('Language settings'), + 'description' => t('Language settings for the user account.'), + 'weight' => 5, + ); + } + + // Field to integrate with the wysiwyg module on user settings. + if (module_exists('wysiwyg')) { + $extra['user']['user']['form']['wysiwyg'] = array( + 'label' => t('Wysiwyg status'), + 'description' => t('Text formats enabled for rich-text editing'), + 'weight' => 5, + ); + } + + return $extra; +} + +/** + * Implements hook_field_attach_rename_bundle(). + */ +function field_group_field_attach_rename_bundle($entity_type, $bundle_old, $bundle_new) { + db_query('UPDATE {field_group} SET bundle = :bundle WHERE bundle = :old_bundle AND entity_type = :entity_type', array( + ':bundle' => $bundle_new, + ':old_bundle' => $bundle_old, + ':entity_type' => $entity_type, + )); +} + +/** + * Creates a group formatted as horizontal tabs. + * This function will never be callable from within field_group rendering. Other + * modules using #type horizontal_tabs will have the benefit of this processor. + * + * @param $element + * An associative array containing the properties and children of the + * fieldset. + * @param $form_state + * The $form_state array for the form this horizontal tab widget belongs to. + * @return + * The processed element. + */ +function form_process_horizontal_tabs($element, &$form_state) { + // Inject a new fieldset as child, so that form_process_fieldset() processes + // this fieldset like any other fieldset. + $element['group'] = array( + '#type' => 'fieldset', + '#theme_wrappers' => array(), + '#parents' => $element['#parents'], + ); + + // The JavaScript stores the currently selected tab in this hidden + // field so that the active tab can be restored the next time the + // form is rendered, e.g. on preview pages or when form validation + // fails. + $name = implode('__', $element['#parents']); + if (isset($form_state['values'][$name . '__active_tab'])) { + $element['#default_tab'] = $form_state['values'][$name . '__active_tab']; + } + $element[$name . '__active_tab'] = array( + '#type' => 'hidden', + '#default_value' => $element['#default_tab'], + '#attributes' => array('class' => array('horizontal-tabs-active-tab')), + ); + + return $element; +} + +/** + * Returns HTML for an element's children fieldsets as horizontal tabs. + * + * @param $variables + * An associative array containing: + * - element: An associative array containing the properties and children of the + * fieldset. Properties used: #children. + * + * @ingroup themeable + */ +function theme_horizontal_tabs($variables) { + $element = $variables['element']; + // Add required JavaScript and Stylesheet. + drupal_add_library('field_group', 'horizontal-tabs'); + + $output = '

' . (!empty($element['#title']) ? $element['#title'] : t('Horizontal Tabs')) . '

'; + $output .= '
' . $element['#children'] . '
'; + + return $output; +} + +/** + * Creates a group formatted as multipage. + * This function will never be callable from within field_group rendering. Other + * modules using #type multipage will have the benefit of this processor. + * + * @param $element + * An associative array containing the properties and children of the + * fieldset. + * @param $form_state + * The $form_state array for the form this horizontal tab widget belongs to. + * @return + * The processed element. + */ +function form_process_multipage($element, &$form_state) { + // Inject a new fieldset as child, so that form_process_fieldset() processes + // this fieldset like any other fieldset. + $element['group'] = array( + '#type' => 'fieldset', + '#theme_wrappers' => array(), + '#parents' => $element['#parents'], + ); + + // The JavaScript stores the currently selected tab in this hidden + // field so that the active control can be restored the next time the + // form is rendered, e.g. on preview pages or when form validation + // fails. + $name = implode('__', $element['#parents']); + if (isset($form_state['values'][$name . '__active_control'])) { + $element['#default_tab'] = $form_state['values'][$name . '__active_control']; + } + $element[$name . '__active_control'] = array( + '#type' => 'hidden', + '#default_value' => $element['#default_control'], + '#attributes' => array('class' => array('multipage-active-control')), + ); + + return $element; +} + +/** + * Returns HTML for an element's children fieldsets as multipage. + * + * @param $variables + * An associative array containing: + * - element: An associative array containing the properties and children of the + * fieldset. Properties used: #children. + * + * @ingroup themeable + */ +function theme_multipage($variables) { + $element = $variables['element']; + // Add required JavaScript and Stylesheet. + drupal_add_library('field_group', 'multipage'); + + $output = '

' . (!empty($element['#title']) ? $element['#title'] : t('Multipage')) . '

'; + + $output .= '
'; + $output .= $element['#children']; + $output .= '
'; + + return $output; +} + +/** + * Returns HTML for multipage pane. + * + * @param $variables + * An associative array containing: + * - element: An associative array containing the properties and children of the + * fieldset. Properties used: #children. + * + * @ingroup themeable + */ +function theme_multipage_pane($variables) { + + $element = $variables['element']; + $group = $variables['element']['#group_object']; + $parent_group = $variables['element']['#parent_group_object']; + + static $multipages; + if (!isset($multipages[$group->parent_name])) { + $multipages = array($group->parent_name => 0); + } + $multipages[$parent_group->group_name]++; + + // Create a page title from the label. + $page_header = isset($parent_group->format_settings['instance_settings']['page_header']) ? $parent_group->format_settings['instance_settings']['page_header'] : 3; + switch ($page_header) { + case 1: + $title = $element['#title']; + break; + case 2: + $title = t('Step %count of %total', array('%count' => $multipages[$parent_group->group_name], '%total' => count($parent_group->children))); + break; + case 3: + $title = t('Step %count of %total !label', array('%count' => $multipages[$parent_group->group_name], '%total' => count($parent_group->children), '!label' => $element['#title'])); + break; + case 0: + default: + $title = ''; + break; + } + + element_set_attributes($element, array('id')); + _form_set_class($element, array('form-wrapper')); + + $output = ''; + if (!empty($element['#title'])) { + // Always wrap fieldset legends in a SPAN for CSS positioning. + $output .= '

' . $title . '

'; + } + $output .= '
'; + if (!empty($element['#description'])) { + $output .= '
' . $element['#description'] . '
'; + } + $output .= $element['#children']; + if (isset($element['#value'])) { + $output .= $element['#value']; + } + + // Add a page counter if needed. + // counter array(0 => t('No'), 1 => t('Format 1 / 10'), 2 => t('The count number only')); + $page_counter_format = isset($parent_group->format_settings['instance_settings']['page_counter']) ? $parent_group->format_settings['instance_settings']['page_counter'] : 1; + $multipage_element['#page_counter_rendered'] = ''; + if ($page_counter_format == 1) { + $output .= t('%count / %total', array('%count' => $multipages[$parent_group->group_name], '%total' => count($parent_group->children))); + } + elseif ($page_counter_format == 2) { + $output .= t('%count', array('%count' => $multipages[$parent_group->group_name])); + } + + $output .= '
'; + $output .= "\n"; + + return $output; + +} + +/** + * Get all groups. + * + * @param $entity_type + * The name of the entity. + * @param $bundle + * The name of the bundle. + * @param $view_mode + * The view mode. + * @param $reset. + * Whether to reset the cache or not. + */ +function field_group_info_groups($entity_type = NULL, $bundle = NULL, $view_mode = NULL, $reset = FALSE) { + static $groups = FALSE; + + if (!$groups || $reset) { + if (!$reset && $cached = cache_get('field_groups', 'cache_field')) { + $groups = $cached->data; + } + else { + $groups = field_group_read_groups(); + cache_set('field_groups', $groups, 'cache_field'); + } + } + + if (!isset($entity_type)) { + return $groups; + } + else { + if (isset($groups[$entity_type][$bundle][$view_mode])) { + return $groups[$entity_type][$bundle][$view_mode]; + } + else { + return array(); + } + } +} + +/** + * Read all groups. + * + * @param $params + * Parameters for the query + * $name The name of the entity. + * $bundle The name of the bundle. + * $view_mode The view mode. + */ +function field_group_read_groups($params = array()) { + + $groups = array(); + ctools_include('export'); + + if (empty($params)) { + $records = ctools_export_load_object('field_group'); + } + else { + $records = ctools_export_load_object('field_group', 'conditions', $params); + } + + foreach ($records as $group) { + // Deleted groups. + // @TODO remove the code below and add something meaningfull for "disabled" state. + if (isset($group->disabled) && $group->disabled) { + continue; + } + $groups[$group->entity_type][$group->bundle][$group->mode][$group->group_name] = field_group_unpack($group); + } + return $groups; + +} + +/** + * Utility function to recreate identifiers. + */ +function _field_group_recreate_identifiers() { + + // Migrate the field groups so they have a unique identifier. + $result = db_select('field_group', 'fg') + ->fields('fg') + ->execute(); + $rows = array(); + foreach($result as $row) { + $row->identifier = $row->group_name . '|' . $row->entity_type . '|' . $row->bundle . '|' . $row->mode; + $row->data = unserialize($row->data); + $rows[] = $row; + } + foreach ($rows as $row) { + drupal_write_record('field_group', $row, array('id')); + } + +} + +/** + * Checks if a field_group exists in required context. + * + * @param String $group_name + * The name of the group. + * @param String $entity_type + * The name of the entity. + * @param String $bundle + * The bundle for the entity. + * @param String $mode + * The view mode context the group will be rendered. + */ +function field_group_exists($group_name, $entity_type, $bundle, $mode) { + $groups = field_group_read_groups(); + return !empty($groups[$entity_type][$bundle][$mode][$group_name]); +} + +/** + * Unpacks a database row in a FieldGroup object. + * @param $group + * Database result object with stored group data. + * @return $group + * Field group object. + */ +function field_group_unpack($group) { + + // Extract unserialized data. + if (isset($group->data)) { + $data = $group->data; + unset($group->data); + $group->label = $data['label']; + $group->weight = $data['weight']; + $group->children = $data['children']; + $group->format_type = !empty($data['format_type']) ? $data['format_type'] : 'fieldset'; + if (isset($data['format_settings'])) { + $group->format_settings = $data['format_settings']; + } + } + + return $group; + +} + +/** + * Packs a FieldGroup object into a database row. + * @param $group + * FieldGroup object. + * @return $record + * Database row object, ready to be inserted/update + */ +function field_group_pack($group) { + + $record = clone $group; + $record->data = array( + 'label' => $record->label, + 'weight' => $record->weight, + 'children' => $record->children, + 'format_type' => !empty($record->format_type) ? $record->format_type : 'fieldset', + ); + if (isset($record->format_settings)) { + $record->data['format_settings'] = $record->format_settings; + } + return $record; +} + +/** + * Delete a field group. + * This function is also called by ctools export when calls are + * made through ctools_export_crud_delete(). + * + * @param $group + * A group definition. + * @param $ctools_crud + * Is this function called by the ctools crud delete. + */ +function field_group_group_export_delete($group, $ctools_crud = TRUE) { + + $query = db_delete('field_group'); + + if (isset($group->identifier)) { + $query->condition('identifier', $group->identifier); + if (!$ctools_crud) { + ctools_export_crud_disable('field_group', $group->identifier); + } + } + elseif (isset($group->id)) { + $query->condition('id', $group->id); + } + + if (!empty($group->mode)) { + $query->condition('mode', $group->mode); + } + + $query->execute(); + + cache_clear_all('field_groups', 'cache_field'); + module_invoke_all('field_group_delete_field_group', $group); + +} + +/** + * field_group_group_save(). + * + * Saves a group definition. + * This function is called by ctools export when calls are made + * through ctools_export_crud_save(). + * + * @param $group + * A group definition. + */ +function field_group_group_save(& $group) { + + // Prepare the record. + $object = field_group_pack($group); + + if (isset($object->export_type) && $object->export_type & EXPORT_IN_DATABASE) { + // Existing record. + $update = array('id'); + module_invoke_all('field_group_update_field_group', $object); + } + else { + // New record. + $update = array(); + $object->export_type = EXPORT_IN_DATABASE; + module_invoke_all('field_group_create_field_group', $object); + } + return drupal_write_record('field_group', $object, $update); + +} + +/** + * Function to retrieve all format possibilities for the fieldgroups. + */ +function field_group_formatter_info($display_overview = FALSE) { + $cache = &drupal_static(__FUNCTION__, array()); + if (empty($cache)) { + if ($cached = cache_get('field_group_formatter_info', 'cache_field')) { + $formatters = $cached->data; + } + else { + $formatters = array(); + $formatters += module_invoke_all('field_group_formatter_info'); + $hidden_region = array( + 'label' => t(''), + 'description' => '', + 'format_types' => array(), + 'instance_settings' => array(), + 'default_formatter' => '', + ); + //$formatters['form']['hidden'] = $hidden_region; + $formatters['display']['hidden'] = $hidden_region; + cache_set('field_group_formatter_info', $formatters, 'cache_field'); + } + $cache = $formatters; + } + return $cache; +} + +/** + * Attach groups to the (form) build. + * + * @param Array $element + * The part of the form. + * @param String $view_mode + * The mode for the build. + * @param Array $form_state + * The optional form state when in view_mode = form context. + */ +function field_group_attach_groups(&$element, $view_mode, $form_state = array()) { + + $entity_type = $element['#entity_type']; + $bundle = $element['#bundle']; + + $element['#groups'] = field_group_info_groups($entity_type, $bundle, $view_mode); + $element['#fieldgroups'] = $element['#groups']; + + // Create a lookup array. + $group_children = array(); + foreach ($element['#groups'] as $group_name => $group) { + foreach ($group->children as $child) { + $group_children[$child] = $group_name; + } + } + $element['#group_children'] = $group_children; + + // Add a pre render callback. + // This is needed since process seems too early for the front view modes. + // This is main bottleneck in field_group. By using this, we can't process + // our added groups in a normal way, resulting in early creation of vertical + // tabs, horizontal tabs and multipages. + $element['#pre_render'][] = 'field_group_build_pre_render'; + +} + +/** + * Process/ Pre-render callback. + * + * Depending on whether it is a form build or content build. + * Form api go through more than a regular build. #process is + * needed here, where #pre_render is ideal for the regular array. + * @see field_group_attach_groups() + * @see field_group_fields_nest() + * @param $element Form element + * @return $element Array with re-arranged fields in forms. + */ +function field_group_build_pre_render($element) { + + // Skip the nesting and field_group functions if no fieldgroups. + // This could be because you don't see them in the UI or programmatically. + if (empty($element['#fieldgroups'])) { + return $element; + } + + // Merge our #fieldgroups with #groups to avoid conflicts on fieldset types. + $element['#groups'] = array_merge($element['#groups'], $element['#fieldgroups']); + + // Nest the fields in the corresponding field groups. + field_group_fields_nest($element); + + // Allow others to alter the pre_rendered build. + drupal_alter('field_group_build_pre_render', $element); + + return $element; + +} + +/** + * Recursive function to nest fields in the field groups. + * + * This function will take out all the elements in the form and + * place them in the correct container element, a fieldgroup. + * The current group element in the loop is passed recursively so we can + * stash fields and groups in it while we go deeper in the array. + * @param Array $element + * The current element to analyse for grouping. + */ +function field_group_fields_nest(&$element) { + + // Create all groups and keep a flat list of references to these groups. + $group_references = array(); + foreach ($element['#groups'] as $group_name => $group) { + $element[$group_name] = array(); + $group_references[$group_name] = &$element[$group_name]; + } + + // Move all children to their parents. Use the flat list of references for + // direct access as we don't know where in the root_element hierarchy the + // parent currently is situated. + foreach ($element['#group_children'] as $child_name => $parent_name) { + // Block denied fields (#access) before they are put in groups. + // Fields (not groups) that don't have children (like field_permissions) are removed + // in field_group_field_group_build_pre_render_alter. + if (isset($element[$child_name]) && (!isset($element[$child_name]['#access']) || $element[$child_name]['#access'])) { + // If this is a group, we have to use a reference to keep the reference + // list intact (but if it is a field we don't mind). + $group_references[$parent_name][$child_name] = &$element[$child_name]; + } + // The child has been copied to its parent: remove it from the root element. + unset($element[$child_name]); + } + + // Bring extra element wrappers to achieve a grouping of fields. + // This will mainly be prefix and suffix altering. + foreach ($element['#groups'] as $group_name => $group) { + field_group_pre_render($group_references[$group_name], $group, $element); + } + +} + +/** + * Function to pre render the field group element. + * + * @see field_group_fields_nest() + * + * @param $element Array of group element that needs to be created! + * @param $group Object with the group information. + * @param $form The form object itself. + */ +function field_group_pre_render(& $element, $group, & $form) { + + // Only run the pre_render function if the group has elements. + // $group->group_name + if ($element == array()) { + return; + } + + // Let modules define their wrapping element. + // Note that the group element has no properties, only elements. + foreach (module_implements('field_group_pre_render') as $module) { + $function = $module . '_field_group_pre_render'; + if (function_exists($function)) { + // The intention here is to have the opportunity to alter the + // elements, as defined in hook_field_group_formatter_info. + // Note, implement $element by reference! + $function($element, $group, $form); + } + } + + // Allow others to alter the pre_render. + drupal_alter('field_group_pre_render', $element, $group, $form); + +} diff --git a/drupal/sites/all/modules/field_group/field_group.test b/drupal/sites/all/modules/field_group/field_group.test new file mode 100755 index 0000000..5c07ffd --- /dev/null +++ b/drupal/sites/all/modules/field_group/field_group.test @@ -0,0 +1,116 @@ + 'Group UI tests', + 'description' => 'Test the group UI functionality.', + 'group' => 'Field group', + ); + } + + function setUp() { + parent::setUp('field_test', 'field_group'); + + // Create test user. + $admin_user = $this->drupalCreateUser(array('administer content types')); + $this->drupalLogin($admin_user); + + // Create random group name. + $this->group_label = $this->randomName(8); + $this->group_name_input = drupal_strtolower($this->randomName(8)); + $this->group_name = 'group_' . $this->group_name_input; + } + + /** + * Creates a group on the article content type. + */ + function createGroup() { + + // Setup new group. + $group = array( + 'fields[_add_new_group][label]' => $this->group_label, + 'fields[_add_new_group][group_name]' => $this->group_name_input, + ); + + // Add new group on the 'Manage fields' page. + $this->drupalPost('admin/structure/types/manage/article/fields', $group, t('Save')); + $this->assertRaw(t('New group %label successfully created.', array('%label' => $this->group_label)), t('Group message displayed on screen.')); + + // Test if group is in the $groups array. + $groups = field_group_info_groups('node', 'article', 'form', TRUE); + $this->assertTrue(array_key_exists($this->group_name, $groups), t('Group found in groups array')); + + // Add new group on the 'Manage display' page. + $this->drupalPost('admin/structure/types/manage/article/display', $group, t('Save')); + $this->assertRaw(t('New group %label successfully created.', array('%label' => $this->group_label)), t('Group message displayed on screen.')); + + // Test if group is in the $groups array. + $groups = field_group_info_groups('node', 'article', 'default', TRUE); + $this->assertTrue(array_key_exists($this->group_name, $groups), t('Group found in groups array')); + } + + /** + * Delete a group. + */ + function deleteGroup() { + $this->drupalPost('admin/structure/types/manage/article/groups/' . $this->group_name . '/delete/form', array(), t('Delete')); + $this->assertRaw(t('The group %label has been deleted from the %article content type.', array('%label' => $this->group_label, '%article' => 'Article')), t('Group removal message displayed on screen.')); + + // Test that group is not in the $groups array. + $groups = field_group_info_groups('node', 'article', 'form', TRUE); + $this->assertFalse(array_key_exists($this->group_name, $groups), t('Group not found in groups array while deleting')); + + $this->drupalPost('admin/structure/types/manage/article/groups/' . $this->group_name . '/delete/default', array(), t('Delete')); + $this->assertRaw(t('The group %label has been deleted from the %article content type.', array('%label' => $this->group_label, '%article' => 'Article')), t('Group removal message displayed on screen.')); + + // Test that group is not in the $groups array. + $groups = field_group_info_groups('node', 'article', 'default', TRUE); + $this->assertFalse(array_key_exists($this->group_name, $groups), t('Group not found in groups array while deleting')); + } + + /** + * General CRUD. + */ + function testCRUDGroup() { + $this->createGroup(); + $this->deleteGroup(); + } + + /** + * Nest a field underneath a group. + */ + function testNestField() { + $this->createGroup(); + $edit = array( + 'fields[field_image][parent]' => $this->group_name, + ); + $this->drupalPost('admin/structure/types/manage/article/fields', $edit, t('Save')); + $this->assertRaw(t('Your settings have been saved.'), t('Settings saved')); + $groups = field_group_info_groups('node', 'article', 'form', TRUE); + $this->assertTrue(in_array('field_image', $groups[$this->group_name]->children), t('Image is a child of %group', array('%group' => $this->group_label))); + } +} diff --git a/drupal/sites/all/modules/field_group/horizontal-tabs/horizontal-tabs.css b/drupal/sites/all/modules/field_group/horizontal-tabs/horizontal-tabs.css new file mode 100755 index 0000000..a8d445f --- /dev/null +++ b/drupal/sites/all/modules/field_group/horizontal-tabs/horizontal-tabs.css @@ -0,0 +1,98 @@ +@CHARSET "UTF-8"; + +div.horizontal-tabs { + margin: 0 0 1em 0; /* LTR */ + padding: 0; + border: 1px solid #ccc; + position: relative; /* IE6/7 */ +} + +.horizontal-tabs ul.horizontal-tabs-list { + display: inline-block; + margin: 0; + border: 0; + padding: 0px; + position: relative; /* IE6 */ + list-style: none; + list-style-image: none; /* IE6 */ + background-color: #dedede; + border-right: 1px solid #dedede; + width: 100%; + height: auto; + clear: both; +} + +.horizontal-tabs fieldset.horizontal-tabs-pane { + padding: 0 1em; + border: 0; +} + +.horizontal-tabs-pane>legend { + display: none; +} + +/* Layout of each tab */ +.horizontal-tabs ul.horizontal-tabs-list li { + background: #eee; + border-right: 1px solid #ccc; + padding: 1px; + padding-top: 0; + margin: 0; + min-width: 5em; /* IE7 */ + float: left; +} +.horizontal-tabs ul.horizontal-tabs-list li.selected { + background-color: #fff; + padding: 0 0 1px 0; +} +.horizontal-tabs ul.horizontal-tabs-list li a { + display: block; + text-decoration: none; + padding: 0.5em 0.6em; +} +.horizontal-tabs ul.horizontal-tabs-list li a:hover { + outline: none; + background-color: #ededdd; +} +.horizontal-tabs ul.horizontal-tabs-list li:hover, +.horizontal-tabs ul.horizontal-tabs-list li:focus { + background-color: #ddd; +} +.horizontal-tabs ul.horizontal-tabs-list li a:focus strong, +.horizontal-tabs ul.horizontal-tabs-list li a:active strong, +.horizontal-tabs ul.horizontal-tabs-list li a:hover strong { + text-decoration: none; + outline: none; +} +.horizontal-tabs ul.horizontal-tabs-list li a, +.horizontal-tabs ul.horizontal-tabs-list li.selected a { + display: block; + text-decoration: none; + padding: 0.5em 0.6em 0.3em 0.6em; + position:relative; + top: 0px; +} +.horizontal-tabs ul.horizontal-tabs-list .selected strong { + color: #000; +} +.horizontal-tabs ul.horizontal-tabs-list .summary { + display: block; +} +.horizontal-tabs ul.horizontal-tabs ul.horizontal-tabs-list .summary { + line-height: normal; + margin-bottom: 0; +} + +/** + * tab content + */ +div.field-group-htabs-wrapper .field-group-format-wrapper { + clear: both; + padding: 0 0 0.6em; +} +/*hide*/ +.horizontal-tabs .horizontal-tab-hidden { + display: block; + position: absolute; + top: -100000px; +} \ No newline at end of file diff --git a/drupal/sites/all/modules/field_group/horizontal-tabs/horizontal-tabs.js b/drupal/sites/all/modules/field_group/horizontal-tabs/horizontal-tabs.js new file mode 100755 index 0000000..c2ab3ee --- /dev/null +++ b/drupal/sites/all/modules/field_group/horizontal-tabs/horizontal-tabs.js @@ -0,0 +1,205 @@ +(function ($) { + +/** + * This script transforms a set of fieldsets into a stack of horizontal + * tabs. Another tab pane can be selected by clicking on the respective + * tab. + * + * Each tab may have a summary which can be updated by another + * script. For that to work, each fieldset has an associated + * 'horizontalTabCallback' (with jQuery.data() attached to the fieldset), + * which is called every time the user performs an update to a form + * element inside the tab pane. + */ +Drupal.behaviors.horizontalTabs = { + attach: function (context) { + $('.horizontal-tabs-panes', context).once('horizontal-tabs', function () { + var focusID = $(':hidden.horizontal-tabs-active-tab', this).val(); + var tab_focus; + + // Check if there are some fieldsets that can be converted to horizontal-tabs + var $fieldsets = $('> fieldset', this); + if ($fieldsets.length == 0) { + return; + } + + // Create the tab column. + var tab_list = $('
    '); + $(this).wrap('
    ').before(tab_list); + + // Transform each fieldset into a tab. + $fieldsets.each(function (i) { + var horizontal_tab = new Drupal.horizontalTab({ + title: $('> legend', this).text(), + fieldset: $(this) + }); + horizontal_tab.item.addClass('horizontal-tab-button-' + i); + tab_list.append(horizontal_tab.item); + $(this) + .removeClass('collapsible collapsed') + .addClass('horizontal-tabs-pane') + .data('horizontalTab', horizontal_tab); + if (this.id == focusID) { + tab_focus = $(this); + } + }); + + $('> li:first', tab_list).addClass('first'); + $('> li:last', tab_list).addClass('last'); + + if (!tab_focus) { + // If the current URL has a fragment and one of the tabs contains an + // element that matches the URL fragment, activate that tab. + if (window.location.hash && $(window.location.hash, this).length) { + tab_focus = $(window.location.hash, this).closest('.horizontal-tabs-pane'); + } + else { + tab_focus = $('> .horizontal-tabs-pane:first', this); + } + } + if (tab_focus.length) { + tab_focus.data('horizontalTab').focus(); + } + }); + } +}; + +/** + * The horizontal tab object represents a single tab within a tab group. + * + * @param settings + * An object with the following keys: + * - title: The name of the tab. + * - fieldset: The jQuery object of the fieldset that is the tab pane. + */ +Drupal.horizontalTab = function (settings) { + var self = this; + $.extend(this, settings, Drupal.theme('horizontalTab', settings)); + + this.link.click(function () { + self.focus(); + return false; + }); + + // Keyboard events added: + // Pressing the Enter key will open the tab pane. + this.link.keydown(function(event) { + if (event.keyCode == 13) { + self.focus(); + // Set focus on the first input field of the visible fieldset/tab pane. + $("fieldset.horizontal-tabs-pane :input:visible:enabled:first").focus(); + return false; + } + }); + + // Pressing the Enter key lets you leave the tab again. + this.fieldset.keydown(function(event) { + // Enter key should not trigger inside