You are here

public function fcIncomplete::process in Field Complete 7

File

fc_incomplete/fc_incomplete.inc, line 32
Field Incomplete - Provides a block displaying of what's currently incomplete on an entity - support.

Class

fcIncomplete

Code

public function process() {
  $field_info = field_info_fields();
  list($id, $vid, $bundle) = entity_extract_ids($this->entity_type, $this->entity);
  $instances = field_info_instances($this->entity_type, $bundle);

  // Allow other modules to remove instances from the completeness check
  $options = array(
    'bundle' => $bundle,
    'context' => 'view',
  );
  drupal_alter('fc_instances', $instances, $this->entity_type, $this->entity, $options);
  uasort($instances, array(
    $this,
    'sortInstances',
  ));
  foreach ($instances as $field_name => $instance) {
    $settings = $instance['settings']['fc'];
    if (!empty($settings['disable'])) {
      continue;
    }

    // Choose the right plugin for the field type.
    $field = $field_info[$field_name];
    $plugin = fc_get_plugin($field['type']);
    $field_items = field_get_items($this->entity_type, $this->entity, $field_name);
    if (empty($field_items)) {
      $this[$field_name] = new fcIncomplete($field_name, $this);
      if (!empty($settings['fc_allow_empty'])) {

        // Complex fields can be set so if they
        // don't they must be counted as complete.
        $this[$field_name]->complete = TRUE;
      }
      continue;
    }
    if ($function = ctools_plugin_get_function($plugin, 'completeness check')) {
      $incomplete = ctools_plugin_get_function($plugin, 'incomplete process');
      $cardinality = ctools_plugin_get_function($plugin, 'cardinality check');
      $this[$field_name] = $incomplete($this, $function, $cardinality, $field_items, $instance, $field);
    }
  }
  $this->complete = TRUE;
  $iterator = $this
    ->getIterator();
  while ($this->complete && $iterator
    ->valid()) {
    $this->complete = $this->complete && $iterator
      ->current()->complete;
    $iterator
      ->next();
  }
}