function field_group_remove_empty_display_groups in Field Group 8.3
Same name and namespace in other branches
- 8 field_group.module \field_group_remove_empty_display_groups()
- 7.2 field_group.module \field_group_remove_empty_display_groups()
- 7 field_group.module \field_group_remove_empty_display_groups()
Remove empty groups on entity display.
Parameters
array $element: The element to check the empty state.
array $groups: Array of group objects.
Return value
bool
1 call to field_group_remove_empty_display_groups()
File
- ./
field_group.module, line 1086 - Allows administrators to attach field groups.
Code
function field_group_remove_empty_display_groups(&$element, $groups) {
$empty_child = TRUE;
$empty_group = TRUE;
// Loop through the visible children for current element.
foreach (Element::getVisibleChildren($element) as $name) {
// Descend if the child is a group.
if (in_array($name, $groups)) {
if (isset($element[$name]['#show_empty_fields']) && $element[$name]['#show_empty_fields']) {
$empty_group = FALSE;
}
else {
$empty_child = field_group_remove_empty_display_groups($element[$name], $groups);
if (!$empty_child) {
$empty_group = FALSE;
}
}
}
elseif (!empty($element[$name])) {
$clone_element = $element[$name];
// Weight parameter can make empty element seen as not empty.
unset($clone_element['#weight']);
if (!Element::isEmpty($clone_element)) {
$empty_group = FALSE;
}
}
}
// Reset an empty group.
if ($empty_group) {
$element = [];
}
return $empty_group;
}