You are here

function _fc_field_groups_group_has_completeness in Field Complete 7

Recursively processes groups to see if they contain completeness fields and if they do whether it is complete or not.

Parameters

string $group_name:

array $group:

array $all_groups:

Return value

boolean or NULL NULL means we've processed it, or it has no completeness at all.

1 call to _fc_field_groups_group_has_completeness()
fc_field_groups_fc_form_pre_render_alter in fc_field_groups/fc_field_groups.module
Implements hook_fc_form_pre_render_alter().

File

fc_field_groups/fc_field_groups.module, line 77
Field Complete Field Groups - Provides field complete support for field groups.

Code

function _fc_field_groups_group_has_completeness($group_name, $all_groups, $completeness, $depth = 0) {
  static $processed_groups = array();

  // Have we already processed this group?
  if (!empty($processed_groups[$group_name])) {
    return NULL;
  }

  // Mark this group as processed
  $processed_groups[$group_name] = TRUE;
  if (in_array($all_groups[$group_name]->format_type, array(
    'htabs',
    'vtabs',
  ))) {

    // This group is a wrapper and has no part in the display
    return NULL;
  }
  $complete = NULL;
  foreach ($all_groups[$group_name]->children as $child_name) {
    if (!empty($all_groups[$child_name])) {

      // This is a group name. so check the
      // child group to see if it's complete
      $child_complete = _fc_field_groups_group_has_completeness($child_name, $all_groups, $completeness, $depth + 1);
      if ($child_complete !== NULL) {

        // If the result was NULL it has no effect on the result
        $complete = $child_complete;
      }
    }
    else {

      // It's a field, if it's not in the completeness list
      // we just ignore it, otherwise we set the $complete
      // variable and continue processing.
      if (array_key_exists($child_name, $completeness)) {
        $complete = $completeness[$child_name];
      }
    }

    // Speed check, if complete has become false it can never be true
    // so we can exit the loop
    if ($complete === FALSE) {
      break;
    }
  }
  return $complete;
}