first import
This commit is contained in:
40
sites/all/modules/field_group/CHANGELOG.txt
Normal file
40
sites/all/modules/field_group/CHANGELOG.txt
Normal file
@@ -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.
|
339
sites/all/modules/field_group/LICENSE.txt
Normal file
339
sites/all/modules/field_group/LICENSE.txt
Normal file
@@ -0,0 +1,339 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 2, June 1991
|
||||
|
||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
License is intended to guarantee your freedom to share and change free
|
||||
software--to make sure the software is free for all its users. This
|
||||
General Public License applies to most of the Free Software
|
||||
Foundation's software and to any other program whose authors commit to
|
||||
using it. (Some other Free Software Foundation software is covered by
|
||||
the GNU Lesser General Public License instead.) You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
this service if you wish), that you receive source code or can get it
|
||||
if you want it, that you can change the software or use pieces of it
|
||||
in new free programs; and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
anyone to deny you these rights or to ask you to surrender the rights.
|
||||
These restrictions translate to certain responsibilities for you if you
|
||||
distribute copies of the software, or if you modify it.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must give the recipients all the rights that
|
||||
you have. You must make sure that they, too, receive or can get the
|
||||
source code. And you must show them these terms so they know their
|
||||
rights.
|
||||
|
||||
We protect your rights with two steps: (1) copyright the software, and
|
||||
(2) offer you this license which gives you legal permission to copy,
|
||||
distribute and/or modify the software.
|
||||
|
||||
Also, for each author's protection and ours, we want to make certain
|
||||
that everyone understands that there is no warranty for this free
|
||||
software. If the software is modified by someone else and passed on, we
|
||||
want its recipients to know that what they have is not the original, so
|
||||
that any problems introduced by others will not reflect on the original
|
||||
authors' reputations.
|
||||
|
||||
Finally, any free program is threatened constantly by software
|
||||
patents. We wish to avoid the danger that redistributors of a free
|
||||
program will individually obtain patent licenses, in effect making the
|
||||
program proprietary. To prevent this, we have made it clear that any
|
||||
patent must be licensed for everyone's free use or not licensed at all.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License applies to any program or other work which contains
|
||||
a notice placed by the copyright holder saying it may be distributed
|
||||
under the terms of this General Public License. The "Program", below,
|
||||
refers to any such program or work, and a "work based on the Program"
|
||||
means either the Program or any derivative work under copyright law:
|
||||
that is to say, a work containing the Program or a portion of it,
|
||||
either verbatim or with modifications and/or translated into another
|
||||
language. (Hereinafter, translation is included without limitation in
|
||||
the term "modification".) Each licensee is addressed as "you".
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running the Program is not restricted, and the output from the Program
|
||||
is covered only if its contents constitute a work based on the
|
||||
Program (independent of having been made by running the Program).
|
||||
Whether that is true depends on what the Program does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Program's
|
||||
source code as you receive it, in any medium, provided that you
|
||||
conspicuously and appropriately publish on each copy an appropriate
|
||||
copyright notice and disclaimer of warranty; keep intact all the
|
||||
notices that refer to this License and to the absence of any warranty;
|
||||
and give any other recipients of the Program a copy of this License
|
||||
along with the Program.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy, and
|
||||
you may at your option offer warranty protection in exchange for a fee.
|
||||
|
||||
2. You may modify your copy or copies of the Program or any portion
|
||||
of it, thus forming a work based on the Program, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) You must cause the modified files to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
b) You must cause any work that you distribute or publish, that in
|
||||
whole or in part contains or is derived from the Program or any
|
||||
part thereof, to be licensed as a whole at no charge to all third
|
||||
parties under the terms of this License.
|
||||
|
||||
c) If the modified program normally reads commands interactively
|
||||
when run, you must cause it, when started running for such
|
||||
interactive use in the most ordinary way, to print or display an
|
||||
announcement including an appropriate copyright notice and a
|
||||
notice that there is no warranty (or else, saying that you provide
|
||||
a warranty) and that users may redistribute the program under
|
||||
these conditions, and telling the user how to view a copy of this
|
||||
License. (Exception: if the Program itself is interactive but
|
||||
does not normally print such an announcement, your work based on
|
||||
the Program is not required to print an announcement.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Program,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Program, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Program.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Program
|
||||
with the Program (or with a work based on the Program) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may copy and distribute the Program (or a work based on it,
|
||||
under Section 2) in object code or executable form under the terms of
|
||||
Sections 1 and 2 above provided that you also do one of the following:
|
||||
|
||||
a) Accompany it with the complete corresponding machine-readable
|
||||
source code, which must be distributed under the terms of Sections
|
||||
1 and 2 above on a medium customarily used for software interchange; or,
|
||||
|
||||
b) Accompany it with a written offer, valid for at least three
|
||||
years, to give any third party, for a charge no more than your
|
||||
cost of physically performing source distribution, a complete
|
||||
machine-readable copy of the corresponding source code, to be
|
||||
distributed under the terms of Sections 1 and 2 above on a medium
|
||||
customarily used for software interchange; or,
|
||||
|
||||
c) Accompany it with the information you received as to the offer
|
||||
to distribute corresponding source code. (This alternative is
|
||||
allowed only for noncommercial distribution and only if you
|
||||
received the program in object code or executable form with such
|
||||
an offer, in accord with Subsection b above.)
|
||||
|
||||
The source code for a work means the preferred form of the work for
|
||||
making modifications to it. For an executable work, complete source
|
||||
code means all the source code for all modules it contains, plus any
|
||||
associated interface definition files, plus the scripts used to
|
||||
control compilation and installation of the executable. However, as a
|
||||
special exception, the source code distributed need not include
|
||||
anything that is normally distributed (in either source or binary
|
||||
form) with the major components (compiler, kernel, and so on) of the
|
||||
operating system on which the executable runs, unless that component
|
||||
itself accompanies the executable.
|
||||
|
||||
If distribution of executable or object code is made by offering
|
||||
access to copy from a designated place, then offering equivalent
|
||||
access to copy the source code from the same place counts as
|
||||
distribution of the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
4. You may not copy, modify, sublicense, or distribute the Program
|
||||
except as expressly provided under this License. Any attempt
|
||||
otherwise to copy, modify, sublicense or distribute the Program is
|
||||
void, and will automatically terminate your rights under this License.
|
||||
However, parties who have received copies, or rights, from you under
|
||||
this License will not have their licenses terminated so long as such
|
||||
parties remain in full compliance.
|
||||
|
||||
5. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Program or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Program (or any work based on the
|
||||
Program), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Program or works based on it.
|
||||
|
||||
6. Each time you redistribute the Program (or any work based on the
|
||||
Program), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute or modify the Program subject to
|
||||
these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties to
|
||||
this License.
|
||||
|
||||
7. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Program at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Program by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Program.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under
|
||||
any particular circumstance, the balance of the section is intended to
|
||||
apply and the section as a whole is intended to apply in other
|
||||
circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system, which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
8. If the distribution and/or use of the Program is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Program under this License
|
||||
may add an explicit geographical distribution limitation excluding
|
||||
those countries, so that distribution is permitted only in or among
|
||||
countries not thus excluded. In such case, this License incorporates
|
||||
the limitation as if written in the body of this License.
|
||||
|
||||
9. The Free Software Foundation may publish revised and/or new versions
|
||||
of the General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Program
|
||||
specifies a version number of this License which applies to it and "any
|
||||
later version", you have the option of following the terms and conditions
|
||||
either of that version or of any later version published by the Free
|
||||
Software Foundation. If the Program does not specify a version number of
|
||||
this License, you may choose any version ever published by the Free Software
|
||||
Foundation.
|
||||
|
||||
10. If you wish to incorporate parts of the Program into other free
|
||||
programs whose distribution conditions are different, write to the author
|
||||
to ask for permission. For software which is copyrighted by the Free
|
||||
Software Foundation, write to the Free Software Foundation; we sometimes
|
||||
make exceptions for this. Our decision will be guided by the two goals
|
||||
of preserving the free status of all derivatives of our free software and
|
||||
of promoting the sharing and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
|
||||
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
|
||||
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
|
||||
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
|
||||
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
|
||||
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
|
||||
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
|
||||
REPAIR OR CORRECTION.
|
||||
|
||||
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
||||
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
|
||||
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
|
||||
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
|
||||
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
|
||||
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
convey the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program is interactive, make it output a short notice like this
|
||||
when it starts in an interactive mode:
|
||||
|
||||
Gnomovision version 69, Copyright (C) year name of author
|
||||
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, the commands you use may
|
||||
be called something other than `show w' and `show c'; they could even be
|
||||
mouse-clicks or menu items--whatever suits your program.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or your
|
||||
school, if any, to sign a "copyright disclaimer" for the program, if
|
||||
necessary. Here is a sample; alter the names:
|
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
|
||||
`Gnomovision' (which makes passes at compilers) written by James Hacker.
|
||||
|
||||
<signature of Ty Coon>, 1 April 1989
|
||||
Ty Coon, President of Vice
|
||||
|
||||
This General Public License does not permit incorporating your program into
|
||||
proprietary programs. If your program is a subroutine library, you may
|
||||
consider it more useful to permit linking proprietary applications with the
|
||||
library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License.
|
37
sites/all/modules/field_group/README.txt
Normal file
37
sites/all/modules/field_group/README.txt
Normal file
@@ -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
|
435
sites/all/modules/field_group/field_group.api.php
Normal file
435
sites/all/modules/field_group/field_group.api.php
Normal file
@@ -0,0 +1,435 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Hooks provided by the Field group module.
|
||||
*
|
||||
* Fieldgroup is a module that will wrap fields and other fieldgroups. Nothing more, nothing less.
|
||||
* For this there are formatters we can create on forms and view modes.
|
||||
*
|
||||
* Some of the elements defined in fieldgroup will be ported to the elements module.
|
||||
*
|
||||
* DEVELOPERS NOTES
|
||||
*
|
||||
* - Fieldgroup uses a ''#fieldgroups' property to know what fieldgroups are to be pre_rendered and
|
||||
* rendered by the field_group module. This means we need to be sure our groups are in #fieldgroups.
|
||||
* #fieldgroups is later merged with the normal #groups that can be used by any other module.
|
||||
* This is done to be sure fieldgroup is not taking fieldsets from profile2, commerce line items,
|
||||
* commerce user profiles, ... .
|
||||
* When trying to merge a programmatically created field wrapper (div, markup, fieldset, ...) into
|
||||
* groups, you might consider adding it in #field_groups as well if you want the element processed
|
||||
* by fieldgroup.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup hooks
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Javascript hooks
|
||||
*
|
||||
* Drupal.FieldGroup.Effects.processHook.execute()
|
||||
* See field_group.js for the examples for all implemented formatters.
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Implements hook_field_group_formatter_info().
|
||||
*
|
||||
* Define the information on formatters. The formatters are
|
||||
* separated by view mode type. We have "form" for all form elements
|
||||
* and "display" will be the real view modes (full, teaser, sticky, ...)
|
||||
*
|
||||
* structure:
|
||||
* @code
|
||||
* array(
|
||||
* 'form' => 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_<format_type>".
|
||||
* @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'] = '<div class="field-group-format ' . $classes . '">
|
||||
<span class="field-group-format-toggler">' . check_plain(t($group->label)) . '</span>
|
||||
<div class="field-group-format-wrapper" style="display: none;">';
|
||||
$add['#suffix'] = '</div></div>';
|
||||
}
|
||||
else {
|
||||
$add['#prefix'] = '<div class="field-group-format ' . $group->group_name . ' ' . $classes . '">';
|
||||
$add['#suffix'] = '</div>';
|
||||
}
|
||||
if (!empty($description)) {
|
||||
$add['#prefix'] .= '<div class="description">' . $description . '</div>';
|
||||
}
|
||||
$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".
|
||||
*/
|
||||
|
34
sites/all/modules/field_group/field_group.css
Normal file
34
sites/all/modules/field_group/field_group.css
Normal file
@@ -0,0 +1,34 @@
|
||||
/* $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,
|
||||
div.field-group-tabs-wrapper div.field-type-datetime 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,
|
||||
div.field-group-tabs-wrapper div.field-type-datetime 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;
|
||||
}
|
48
sites/all/modules/field_group/field_group.features.inc
Normal file
48
sites/all/modules/field_group/field_group.features.inc
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
|
||||
/**
|
||||
* Implements hook_features_export_alter().
|
||||
*
|
||||
* For a given feature, add field groups that contain any fields that
|
||||
* are a part of this feature. Also, add parent groups of any groups
|
||||
* that are a part of this feature.
|
||||
*/
|
||||
function field_group_features_export_alter(&$export, $module_name) {
|
||||
//Make sure we have fresh data by loading directly.
|
||||
ctools_include('export');
|
||||
$field_groups = ctools_export_load_object('field_group');
|
||||
|
||||
//Add fieldgroups based on the fields that are present.
|
||||
if (!empty($export['features']['field'])) {
|
||||
foreach ($export['features']['field'] as $field) {
|
||||
list($entity_type, $bundle, $field_name) = explode('-', $field);
|
||||
|
||||
foreach ($field_groups as $group_id => $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';
|
||||
}
|
||||
}
|
||||
}
|
14
sites/all/modules/field_group/field_group.field_ui.css
Normal file
14
sites/all/modules/field_group/field_group.field_ui.css
Normal file
@@ -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;
|
||||
}
|
826
sites/all/modules/field_group/field_group.field_ui.inc
Normal file
826
sites/all/modules/field_group/field_group.field_ui.inc
Normal file
@@ -0,0 +1,826 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Field_group.field_ui.inc is a file that contains most functions
|
||||
* needed on the Fields UI Manage forms (display and fields).
|
||||
*/
|
||||
|
||||
/**
|
||||
* Helper function to get the form parameters to use while
|
||||
* building the fields and display overview form.
|
||||
*/
|
||||
function field_group_field_ui_form_params($form, $display_overview) {
|
||||
|
||||
$params = new stdClass();
|
||||
$params->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'] = '<div id="field-display-overview-wrapper">';
|
||||
$form['fields']['#suffix'] = '</div>';
|
||||
}
|
||||
$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' => '<span class="group-label">',
|
||||
'#suffix' => '</span>',
|
||||
),
|
||||
'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:') . ' <span class="formatter-name">' . $group->format_type . '</span>',
|
||||
),
|
||||
// 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' => '<div class="field-formatter-settings-edit-wrapper">',
|
||||
'#suffix' => '</div>',
|
||||
);
|
||||
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' => '<div class="label-input"><div class="add-new-placeholder">' . t('Add new group') . '</div>',
|
||||
'#suffix' => '</div>',
|
||||
),
|
||||
'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' => '<div class="add-new-placeholder"> </div>',
|
||||
),
|
||||
'parent_wrapper' => array(
|
||||
'parent' => array(
|
||||
'#type' => 'select',
|
||||
'#options' => $parent_options,
|
||||
'#empty_value' => '',
|
||||
'#attributes' => array('class' => array('field-parent')),
|
||||
'#prefix' => '<div class="add-new-placeholder"> </div>',
|
||||
'#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' => '<span dir="ltr">group_',
|
||||
'#field_suffix' => '</span>‎',
|
||||
'#attributes' => array('dir' => 'ltr'),
|
||||
'#size' => 15,
|
||||
'#description' => t('Group name (a-z, 0-9, _)'),
|
||||
'#prefix' => '<div class="add-new-placeholder"> </div>',
|
||||
'#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('<br />', module_invoke_all('field_group_format_summary', $group));
|
||||
return array(
|
||||
'#markup' => '<div class="field-formatter-summary">' . $summary . '</div>',
|
||||
'#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.'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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_id($element, &$form_state) {
|
||||
if (!empty($form_state['values']['fields'][$form_state['formatter_settings_edit']]['format_settings']['settings']['instance_settings']['id']) && !preg_match('!^[A-Za-z0-9-_]+$!', $form_state['values']['fields'][$form_state['formatter_settings_edit']]['format_settings']['settings']['instance_settings']['id'])) {
|
||||
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' => '<div>',
|
||||
'#suffix' => '</div>',
|
||||
'#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('<p class="fieldgroup-help">Fields can be dragged into groups with unlimited nesting. Each fieldgroup format comes with a configuration form, specific for that format type.<br />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.</p>'),
|
||||
'#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().
|
||||
*/
|
137
sites/all/modules/field_group/field_group.field_ui.js
Normal file
137
sites/all/modules/field_group/field_group.field_ui.js
Normal file
@@ -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);
|
18
sites/all/modules/field_group/field_group.info
Normal file
18
sites/all/modules/field_group/field_group.info
Normal file
@@ -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 2012-04-07
|
||||
version = "7.x-2.x-dev"
|
||||
core = "7.x"
|
||||
project = "field_group"
|
||||
datestamp = "1333757874"
|
||||
|
258
sites/all/modules/field_group/field_group.install
Normal file
258
sites/all/modules/field_group/field_group.install
Normal file
@@ -0,0 +1,258 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Fieldgroup module install file.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_schema().
|
||||
*/
|
||||
function field_group_schema() {
|
||||
$schema['field_group'] = array(
|
||||
'description' => 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();
|
||||
|
||||
}
|
195
sites/all/modules/field_group/field_group.js
Normal file
195
sites/all/modules/field_group/field_group.js
Normal file
@@ -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 = $('<a class="field-group-format-title" href="#"></a>');
|
||||
$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);
|
1783
sites/all/modules/field_group/field_group.module
Normal file
1783
sites/all/modules/field_group/field_group.module
Normal file
File diff suppressed because it is too large
Load Diff
151
sites/all/modules/field_group/field_group.test
Normal file
151
sites/all/modules/field_group/field_group.test
Normal file
@@ -0,0 +1,151 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Unit test file for groups.
|
||||
*
|
||||
* @todo - fill along if we know more.
|
||||
*
|
||||
* - nest a group under another group and see if parent_name is first group
|
||||
* - nest a group under second group and see if parent_name is second group
|
||||
* - settings: open f and verify on front-end (classes)
|
||||
* - settings: collapsible f and verify on front-end (classes)
|
||||
* - settings: collapsed f and verify on front-end (classes)
|
||||
* - settings: vertical tabs and verify on front-end (classes)
|
||||
* - settings: horizontal item and verify on front-end (classes)
|
||||
* - settings: vertical item and verify on front-end (classes)
|
||||
* - settings: hidden (simple div) and verify on front-end (classes)
|
||||
* - settings: label and verify on front-end
|
||||
* - delete a fieldgroup - make sure we have a couple with the same name
|
||||
* and make sure the right one is deleted!
|
||||
*/
|
||||
|
||||
/**
|
||||
* Group UI tests.
|
||||
*/
|
||||
class GroupUITestCase extends DrupalWebTestCase {
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => 'Field group tests',
|
||||
'description' => 'Test the field group functionality.',
|
||||
'group' => 'Field group',
|
||||
);
|
||||
}
|
||||
|
||||
function setUp() {
|
||||
parent::setUp('field_test', 'field_group');
|
||||
|
||||
// Create test user.
|
||||
$admin_user = $this->drupalCreateUser(array('administer content types', 'administer nodes', 'access administration pages', 'bypass node access'));
|
||||
$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;
|
||||
|
||||
// Create a fieldgroup.
|
||||
$field_group = new stdClass;
|
||||
$field_group->disabled = FALSE; /* Edit this to true to make a default field_group disabled initially */
|
||||
$field_group->api_version = 1;
|
||||
$field_group->identifier = 'wrapper|node|article|form';
|
||||
$field_group->group_name = 'wrapper';
|
||||
$field_group->entity_type = 'node';
|
||||
$field_group->bundle = 'article';
|
||||
$field_group->mode = 'form';
|
||||
$field_group->parent_name = '';
|
||||
$field_group->data = array(
|
||||
'label' => 'Wrapper',
|
||||
'weight' => '1',
|
||||
'children' => array(
|
||||
0 => 'field_image',
|
||||
),
|
||||
'format_type' => 'div',
|
||||
'format_settings' => array(
|
||||
'label' => 'Link',
|
||||
'instance_settings' => array(
|
||||
'required_fields' => 0,
|
||||
'id' => 'wrapper-id',
|
||||
'classes' => '',
|
||||
'description' => '',
|
||||
'show_label' => '0',
|
||||
'label_element' => 'h3',
|
||||
'effect' => 'none',
|
||||
'speed' => 'fast',
|
||||
),
|
||||
'formatter' => 'open',
|
||||
),
|
||||
);
|
||||
drupal_write_record('field_group', $field_group);
|
||||
ctools_export_crud_enable('field_group', $field_group->identifier);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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() {
|
||||
|
||||
// Test on the wrapper field.
|
||||
$groups = field_group_info_groups('node', 'article', 'form', TRUE);
|
||||
$this->assertTrue(in_array('field_image', $groups['wrapper']->children), t('Image is a child of %group', array('%group' => 'Wrapper')));
|
||||
|
||||
$this->drupalGet('node/add/article');
|
||||
$this->assertRaw('id="wrapper-id"', t('Wrapper id set on wrapper div'));
|
||||
}
|
||||
}
|
125
sites/all/modules/field_group/multipage/multipage.css
Normal file
125
sites/all/modules/field_group/multipage/multipage.css
Normal file
@@ -0,0 +1,125 @@
|
||||
.multipage-controls-list #edit-actions {
|
||||
float: left;
|
||||
}
|
||||
|
||||
.multipage-button {
|
||||
margin-bottom: 1em;
|
||||
margin-top: 0;
|
||||
float: left;
|
||||
line-height: 36px;
|
||||
}
|
||||
|
||||
.multipage-button a {
|
||||
padding-top: 10px;
|
||||
}
|
||||
|
||||
.multipage-counter{
|
||||
float: right;
|
||||
margin-right: 5px;
|
||||
height: 0;
|
||||
position: relative;
|
||||
top: 1.8em;
|
||||
line-height: 30px;
|
||||
font: 12px arial,sans-serif;
|
||||
font-weight: bold;
|
||||
color:#666;
|
||||
}
|
||||
|
||||
a.multipage-link-previous{
|
||||
font: 12px arial,sans-serif;
|
||||
font-weight: bold;
|
||||
color:#666;
|
||||
-webkit-transition: color 218ms;
|
||||
-moz-transition: color 218ms;
|
||||
-o-transition: color 218ms;
|
||||
transition: color 218ms;
|
||||
}
|
||||
|
||||
a.multipage-link-previous:hover{
|
||||
text-decoration:none;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.multipage-controls-list input.form-submit{
|
||||
background:none;
|
||||
border: none;
|
||||
border-radius: 2px;
|
||||
-moz-border-radius: 2px;
|
||||
-webkit-border-radius: 2px;
|
||||
border: 1px solid rgba(0, 0, 0, 0.1);
|
||||
font: 12px arial,sans-serif;
|
||||
font-weight: bold;
|
||||
color: #666;
|
||||
text-shadow: 0 1px 0 white;
|
||||
padding: 7px 12px;
|
||||
background: -webkit-gradient(linear,0% 40%,0% 70%,from(whiteSmoke),to(#F1F1F1));
|
||||
-o-transition: border-top-color 0.218s,border-right-color 0.218s,border-bottom-color 0.218s,border-left-color .218s;
|
||||
-webkit-transition: border-color .218s;
|
||||
}
|
||||
|
||||
.multipage-controls-list input.form-submit:hover{
|
||||
color:#333;
|
||||
box-shadow: 0 1px 1px rgba(0,0,0,0.1);
|
||||
-webkit-box-shadow: 0 1px 1px rgba(0,0,0,0.1);
|
||||
border-color: #939393;
|
||||
}
|
||||
|
||||
.multipage-controls-list input.form-submit:active{
|
||||
background: -webkit-gradient(linear,0% 40%,0% 70%,from(#F1F1F1),to(whiteSmoke));
|
||||
}
|
||||
|
||||
.multipage-controls-list input#edit-submit{
|
||||
background-image: -moz-linear-gradient(top,#4d90fe,#4787ed);
|
||||
background-image: -o-linear-gradient(top,#4d90fe,#4787ed);
|
||||
background-image: -webkit-gradient(linear,left top,left bottom,from(#4d90fe),to(#4787ed));
|
||||
color: white;
|
||||
text-shadow: none;
|
||||
text-transform: uppercase;
|
||||
min-width: 79px;
|
||||
}
|
||||
|
||||
.multipage-controls-list input#edit-submit:hover{
|
||||
background-image: -moz-linear-gradient(top,#4d90fe,#357ae8);
|
||||
background-image: -o-linear-gradient(top,#4d90fe,#357ae8);
|
||||
background-image: -webkit-gradient(linear,left top,left bottom,from(#4d90fe),to(#357ae8));
|
||||
color: white;
|
||||
text-shadow: none;
|
||||
box-shadow: 0 1px 1px rgba(0,0,0,0.2);
|
||||
-webkit-box-shadow: 0 1px 1px rgba(0,0,0,0.2);
|
||||
}
|
||||
|
||||
.multipage-controls-list input#edit-submit:active{
|
||||
background: #4D90FE;
|
||||
border-color: #2F5BB7;
|
||||
}
|
||||
|
||||
.multipage-controls-list input#edit-delete{
|
||||
background-image: -moz-linear-gradient(top,#dd4b39,#d14836);
|
||||
background-image: -o-linear-gradient(top,#dd4b39,#d14836);
|
||||
background-image: -webkit-gradient(linear,left top,left bottom,from(#dd4b39),to(#d14836));
|
||||
text-shadow: 0 1px rgba(0, 0, 0, 0.1);
|
||||
border: 1px solid transparent;
|
||||
color: white;
|
||||
text-shadow: none;
|
||||
|
||||
}
|
||||
|
||||
.multipage-controls-list input#edit-delete:hover{
|
||||
background-image: -moz-linear-gradient(top,#dd4b39,#c53727);
|
||||
background-image: -o-linear-gradient(top,#dd4b39,#c53727);
|
||||
background-image: -webkit-gradient(linear,left top,left bottom,from(#dd4b39),to(#c53727));
|
||||
border: 1px solid #B0281A!important;
|
||||
border-bottom: 1px solid #AF301F!important;
|
||||
box-shadow: 0 1px 1px rgba(0,0,0,0.2);
|
||||
-webkit-box-shadow: 0 1px 1px rgba(0,0,0,0.2);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.multipage-controls-list input#edit-delete:active{
|
||||
background-image: -moz-linear-gradient(top,#dd4b39,#b0281a);
|
||||
background-image: -o-linear-gradient(top,#dd4b39,#b0281a);
|
||||
background-image: -webkit-gradient(linear,left top,left bottom,from(#dd4b39),to(#b0281a));
|
||||
border: 1px solid #992A1b!important;
|
||||
box-shadow: 0 1px 2px rgba(0,0,0,0.3);
|
||||
-webkit-box-shadow: 0 1px 2px rgba(0,0,0,0.3);
|
||||
}
|
241
sites/all/modules/field_group/multipage/multipage.js
Normal file
241
sites/all/modules/field_group/multipage/multipage.js
Normal file
@@ -0,0 +1,241 @@
|
||||
(function ($) {
|
||||
|
||||
/**
|
||||
* This script transforms a set of wrappers into a stack of multipage pages.
|
||||
* Another pane can be entered by clicking next/previous.
|
||||
*
|
||||
*/
|
||||
Drupal.behaviors.MultiPage = {
|
||||
attach: function (context) {
|
||||
$('.multipage-panes', context).once('multipage', function () {
|
||||
|
||||
var focusID = $(':hidden.multipage-active-control', this).val();
|
||||
var paneWithFocus;
|
||||
|
||||
// Check if there are some wrappers that can be converted to multipages.
|
||||
var $panes = $('> div.field-group-multipage', this);
|
||||
var $form = $panes.parents('form');
|
||||
if ($panes.length == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Create the next/previous controls.
|
||||
var $controls;
|
||||
|
||||
// Transform each div.multipage-pane into a multipage with controls.
|
||||
$panes.each(function () {
|
||||
|
||||
$controls = $('<div class="multipage-controls-list"></div>');
|
||||
$(this).append('<div class="multipage-controls clearfix"></div>').append($controls);
|
||||
|
||||
// Check if the submit button needs to move to the latest pane.
|
||||
if (Drupal.settings.field_group.multipage_move_submit && $('.form-actions').length) {
|
||||
$('.form-actions', $form).remove().appendTo($($controls, $panes.last()));
|
||||
}
|
||||
|
||||
var multipageControl = new Drupal.multipageControl({
|
||||
title: $('> .multipage-pane-title', this).text(),
|
||||
wrapper: $(this),
|
||||
has_next: $(this).next().length,
|
||||
has_previous: $(this).prev().length
|
||||
});
|
||||
|
||||
$controls.append(multipageControl.item);
|
||||
$(this)
|
||||
.addClass('multipage-pane')
|
||||
.data('multipageControl', multipageControl);
|
||||
|
||||
if (this.id == focusID) {
|
||||
paneWithFocus = $(this);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
if (!paneWithFocus) {
|
||||
// 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) {
|
||||
paneWithFocus = $(window.location.hash, this).closest('.multipage-pane');
|
||||
}
|
||||
else {
|
||||
paneWithFocus = $('multipage-open', this).length ? $('multipage-open', this) : $('> .multipage-pane:first', this);
|
||||
}
|
||||
}
|
||||
if (paneWithFocus.length) {
|
||||
paneWithFocus.data('multipageControl').focus();
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* The multipagePane object represents a single div as a page.
|
||||
*
|
||||
* @param settings
|
||||
* An object with the following keys:
|
||||
* - title: The name of the tab.
|
||||
* - wrapper: The jQuery object of the <div> that is the tab pane.
|
||||
*/
|
||||
Drupal.multipageControl = function (settings) {
|
||||
var self = this;
|
||||
$.extend(this, settings, Drupal.theme('multipage', settings));
|
||||
|
||||
this.nextLink.click(function () {
|
||||
self.nextPage();
|
||||
return false;
|
||||
});
|
||||
|
||||
this.previousLink.click(function () {
|
||||
self.previousPage();
|
||||
return false;
|
||||
});
|
||||
|
||||
/*
|
||||
// Keyboard events added:
|
||||
// Pressing the Enter key will open the tab pane.
|
||||
this.nextLink.keydown(function(event) {
|
||||
if (event.keyCode == 13) {
|
||||
self.focus();
|
||||
// Set focus on the first input field of the visible wrapper/tab pane.
|
||||
$("div.multipage-pane :input:visible:enabled:first").focus();
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
// Pressing the Enter key lets you leave the tab again.
|
||||
this.wrapper.keydown(function(event) {
|
||||
// Enter key should not trigger inside <textarea> to allow for multi-line entries.
|
||||
if (event.keyCode == 13 && event.target.nodeName != "TEXTAREA") {
|
||||
// Set focus on the selected tab button again.
|
||||
$(".multipage-tab-button.selected a").focus();
|
||||
return false;
|
||||
}
|
||||
});
|
||||
*/
|
||||
};
|
||||
|
||||
Drupal.multipageControl.prototype = {
|
||||
|
||||
/**
|
||||
* Displays the tab's content pane.
|
||||
*/
|
||||
focus: function () {
|
||||
this.wrapper
|
||||
.show()
|
||||
.siblings('div.multipage-pane')
|
||||
.each(function () {
|
||||
var tab = $(this).data('multipageControl');
|
||||
tab.wrapper.hide();
|
||||
})
|
||||
.end()
|
||||
.siblings(':hidden.multipage-active-control')
|
||||
.val(this.wrapper.attr('id'));
|
||||
// Mark the active control for screen readers.
|
||||
$('#active-multipage-control').remove();
|
||||
this.nextLink.append('<span id="active-multipage-control" class="element-invisible">' + Drupal.t('(active page)') + '</span>');
|
||||
},
|
||||
|
||||
/**
|
||||
* Continues to the next page or step in the form.
|
||||
*/
|
||||
nextPage: function () {
|
||||
this.wrapper.next().data('multipageControl').focus();
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns to the previous page or step in the form.
|
||||
*/
|
||||
previousPage: function () {
|
||||
this.wrapper.prev().data('multipageControl').focus();
|
||||
},
|
||||
|
||||
/**
|
||||
* Shows a horizontal tab pane.
|
||||
*/
|
||||
tabShow: function () {
|
||||
// Display the tab.
|
||||
this.item.show();
|
||||
// Update .first marker for items. We need recurse from parent to retain the
|
||||
// actual DOM element order as jQuery implements sortOrder, but not as public
|
||||
// method.
|
||||
this.item.parent().children('.multipage-control').removeClass('first')
|
||||
.filter(':visible:first').addClass('first');
|
||||
// Display the wrapper.
|
||||
this.wrapper.removeClass('multipage-control-hidden').show();
|
||||
// Focus this tab.
|
||||
this.focus();
|
||||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* Hides a horizontal tab pane.
|
||||
*/
|
||||
tabHide: function () {
|
||||
// Hide this tab.
|
||||
this.item.hide();
|
||||
// Update .first marker for items. We need recurse from parent to retain the
|
||||
// actual DOM element order as jQuery implements sortOrder, but not as public
|
||||
// method.
|
||||
this.item.parent().children('.multipage-control').removeClass('first')
|
||||
.filter(':visible:first').addClass('first');
|
||||
// Hide the wrapper.
|
||||
this.wrapper.addClass('horizontal-tab-hidden').hide();
|
||||
// Focus the first visible tab (if there is one).
|
||||
var $firstTab = this.wrapper.siblings('.multipage-pane:not(.multipage-control-hidden):first');
|
||||
if ($firstTab.length) {
|
||||
$firstTab.data('multipageControl').focus();
|
||||
}
|
||||
return this;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Theme function for a multipage control.
|
||||
*
|
||||
* @param settings
|
||||
* An object with the following keys:
|
||||
* - title: The name of the tab.
|
||||
* @return
|
||||
* This function has to return an object with at least these keys:
|
||||
* - item: The root tab jQuery element
|
||||
* - nextLink: The anchor tag that acts as the clickable area of the control
|
||||
* - nextTitle: The jQuery element that contains the group title
|
||||
* - previousLink: The anchor tag that acts as the clickable area of the control
|
||||
* - previousTitle: The jQuery element that contains the group title
|
||||
*/
|
||||
Drupal.theme.prototype.multipage = function (settings) {
|
||||
var controls = {};
|
||||
controls.item = $('<span class="multipage-button"></span>');
|
||||
controls.item.append(controls.nextLink = $('<input type="button" class="form-submit multipage-link-next" value="" />').val(controls.nextTitle = Drupal.t('Next page')));
|
||||
controls.item.append(controls.previousLink = $('<input type="button" class="form-submit multipage-link-previous" value="" />').val(controls.nextTitle = Drupal.t('Previous')));
|
||||
if (!settings.has_next) {
|
||||
controls.nextLink.hide();
|
||||
}
|
||||
if (!settings.has_previous) {
|
||||
controls.previousLink.hide();
|
||||
}
|
||||
return controls;
|
||||
};
|
||||
|
||||
|
||||
Drupal.FieldGroup = Drupal.FieldGroup || {};
|
||||
Drupal.FieldGroup.Effects = Drupal.FieldGroup.Effects || {};
|
||||
|
||||
/**
|
||||
* Implements Drupal.FieldGroup.processHook().
|
||||
*/
|
||||
Drupal.FieldGroup.Effects.processMultipage = {
|
||||
execute: function (context, settings, type) {
|
||||
if (type == 'form') {
|
||||
// Add required fields mark to any element containing required fields
|
||||
$('div.multipage-pane').each(function(i){
|
||||
if ($('.error', $(this)).length) {
|
||||
Drupal.FieldGroup.setGroupWithfocus($(this));
|
||||
$(this).data('multipageControl').focus();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
})(jQuery);
|
Reference in New Issue
Block a user