You are here

field_group_table.api.php in Field Group Table 8

Same filename and directory in other branches
  1. 7 field_group_table.api.php

Hooks provided by Field Group Table.

File

field_group_table.api.php
View source
<?php

/**
 * @file
 * Hooks provided by Field Group Table.
 */

/**
 * @defgroup hooks Field Group Table hooks.
 * @{
 * The hooks provided by Field Group Table.
 */

/**
 * Allows modules to alter rows, useful to remove empty rows.
 *
 * When removing rows, you must unset the corresponding key/value pairs in both
 * $element and $children.
 *
 * @param array &$element
 *   An array containing render API code for the field group.
 * @param array &$children
 *   An array with the keys of the render API children of $element as returned
 *   by element_children.
 *
 * @see element_children()
 */
function hook_field_group_table_rows_alter(array &$element, array &$children) {

  // Only operate on "view" mode.
  if ($element['#mode'] != 'view') {
    return;
  }
  $render_api_properties = [
    '#theme',
    '#markup',
    '#prefix',
    '#suffix',
  ];
  foreach ($children as $index => $child) {

    // A row with a multi-value field is empty when the first element contains
    // no render API code.
    if (isset($element[$child][0]) && !array_intersect($render_api_properties, array_keys($element[$child][0]))) {
      unset($children[$index]);
      unset($element[$child]);
    }
  }
}

/**
 * @} End of "defgroup hooks".
 */

Functions

Namesort descending Description
hook_field_group_table_rows_alter Allows modules to alter rows, useful to remove empty rows.