DrupalBin
Submit Code
About
Recent Posts
Fix for Latest item + title list
Support Ticketing System module: code excerpt from 6.x-1.x-dev support.module lines 2843 to 2941
Fix for Create product reference field
Create product reference field
Re:
Fix for Code
Code
Code
bellHead's fields error
Code
more
User login
Log in using OpenID:
What is OpenID?
Username:
*
Password:
*
Log in using OpenID
Cancel OpenID login
Create new account
Request new password
Tags
CCK
drupal
fapi
jquery
menu
module
php
simpletest
test
theme
user
views
more tags
Home
Fix for refactored field groups for D7 and added recursive functions
View
Fix
July 30, 2010 - 10:07am — Anonymous
/**
* Attach groups to the form.
*/
function
field_group_attach_groups
(
&
$form
,
$view_mode
)
{
$entity_type
=
$form
[
'#entity_type'
]
;
$bundle
=
$form
[
'#bundle'
]
;
$form
[
'#groups'
]
= field_group_get_groups
(
$entity_type
,
$bundle
,
$view_mode
)
;
// Create a lookup array.
$group_children
=
array
(
)
;
foreach
(
$form
[
'#groups'
]
as
$group_name
=
>
$group
)
{
foreach
(
$group
-
>
children
as
$child
)
{
$group_children
[
$child
]
=
$group_name
;
}
}
$form
[
'#group_children'
]
=
$group_children
;
// Nest the fields in the corresponding field groups.
field_group_nest_fields
(
$form
,
$form
)
;
}
/**
* Recursive function to nest fields in the field groups.
* @param $form
* @return void
*/
function
field_group_nest_fields
(
&
$element
,
&
$form
,
$parent
=
NULL
)
{
$groups
=
$form
[
'#groups'
]
;
$group_fields
=
$form
[
'#group_children'
]
;
foreach
(
$groups
as
$group_name
=
>
$group
)
{
// Add fieldgroups to the current element.
if
(
(
empty
(
$group
-
>
parent_name
)
&&
!
isset
(
$parent
)
)
||
$parent
==
$group
-
>
parent_name
)
{
$element
[
$group_name
]
=
array
(
'#type'
=
>
'fieldset'
,
'#title'
=
>
$group
-
>
label
,
'#weight'
=
>
$group
-
>
weight
,
'#collapsible'
=
>
TRUE
,
'#collapsed'
=
>
FALSE
,
)
;
foreach
(
$group_fields
as
$groupfield
=
>
$groupname
)
{
// Stash the field in the group.
if
(
$groupname
==
$group_name
&&
isset
(
$form
[
$groupfield
]
)
)
{
$element
[
$group_name
]
[
$groupname
]
[
$groupfield
]
=
$form
[
$groupfield
]
;
unset
(
$form
[
$groupfield
]
)
;
unset
(
$form
[
'#group_children'
]
[
$groupfield
]
)
;
}
}
unset
(
$form
[
'#groups'
]
[
$group_name
]
)
;
field_group_nest_fields
(
$element
[
$group_name
]
,
$form
,
$group_name
)
;
}
}
}
Submit Fix
Summary:
Tags:
Any tags you'd like to associate with your code, delimitered by commas (example: Views, CCK, Module, etc).
Show summary in full view
/** * Attach groups to the form. */ function field_group_attach_groups(&$form, $view_mode) { $entity_type = $form['#entity_type']; $bundle = $form['#bundle']; $form['#groups'] = field_group_get_groups($entity_type,$bundle, $view_mode); // Create a lookup array. $group_children = array(); foreach ($form['#groups'] as $group_name => $group) { foreach ($group->children as $child) { $group_children[$child] = $group_name; } } $form['#group_children'] = $group_children; // Nest the fields in the corresponding field groups. field_group_nest_fields($form, $form); } /** * Recursive function to nest fields in the field groups. * @param $form * @return void */ function field_group_nest_fields(& $element, & $form, $parent = NULL) { $groups = $form['#groups']; $group_fields = $form['#group_children']; foreach ($groups as $group_name => $group) { // Add fieldgroups to the current element. if ((empty($group->parent_name) && !isset($parent)) || $parent == $group->parent_name) { $element[$group_name] = array( '#type' => 'fieldset', '#title' => $group->label, '#weight' => $group->weight, '#collapsible' => TRUE, '#collapsed' => FALSE, ); foreach ($group_fields as $groupfield => $groupname) { // Stash the field in the group. if ($groupname == $group_name && isset($form[$groupfield])) { $element[$group_name][$groupname][$groupfield] = $form[$groupfield]; unset($form[$groupfield]); unset($form['#group_children'][$groupfield]); } } unset($form['#groups'][$group_name]); field_group_nest_fields($element[$group_name], $form, $group_name); } } }
Syntax highlighting mode:
ActionScript
ColdFusion
Diff
Drupal 5
Drupal 6
HTML
INI
Javascript
MySQL
PHP
Python
robots.txt
SQL
Text
Select the syntax highlighting mode to use.
See Also:
Order
Title:
URL:
-1
0
1
Title:
URL:
-1
0
1
Any links you'd like to have associated with the post (Drupal.org issue, Wikipedia article, etc).
File attachments
Changes made to the attachments are not permanent until you save this post. The first "listed" file will be included in RSS feeds.
Attach new file:
The maximum upload size is
1 MB
. Only files with the following extensions may be uploaded:
jpg jpeg gif png txt doc xls pdf ppt pps odt ods odp
.