You are here

function fc_default_field_cardinality in Field Complete 7

1 string reference to 'fc_default_field_cardinality'
_fc_ctools_plugin_type in ./fc.registry.inc
Implements hook_ctools_plugin_type() to inform CTools about the layout plugin.

File

./fc.module, line 148
Field Complete - Provides field-based completeness for any entity.

Code

function fc_default_field_cardinality($function, $field_items, $instance, $field) {

  // Fetch an array of completed items
  $completed = array();
  $function($field_items, $instance, $field, $completed);

  // Test each field item to determine if it's not empty = complete
  // we also need to take into account cardinality
  $cardinality = $field['cardinality'];
  if ($cardinality == FIELD_CARDINALITY_UNLIMITED) {

    // If we can have unlimited then we must have at least one,
    // but if we have a number of items make the cardinality
    // equal to the total. This means that someone can create a
    // while bunch of items but they must all be complete for the
    // field itself to counted as complete.
    $cardinality = empty($field_items) ? 1 : count($field_items);
  }

  // It's complete as long as we have /at least/ the cardinality
  return count(array_filter($completed)) >= $cardinality;
}