You are here

function redhen_dedupe_filter_form in RedHen CRM 7

Dedupe filter form.

1 string reference to 'redhen_dedupe_filter_form'
redhen_dedupe_list_page in modules/redhen_dedupe/redhen_dedupe.module
Page callback for listing duplicate contacts.

File

modules/redhen_dedupe/redhen_dedupe.module, line 134

Code

function redhen_dedupe_filter_form($form, &$form_state, $properties, $fields, $active) {
  $info = entity_get_property_info('redhen_contact');
  $excluded_props = array(
    'contact_id',
    'revision_id',
    'redhen_state',
  );
  $prop_options = $field_options = array();
  foreach ($info['properties'] as $name => $property) {
    if (isset($property['schema field']) && !in_array($name, $excluded_props)) {
      $prop_options[$name] = $property['label'];
    }
  }
  foreach ($info['bundles'] as $type) {
    foreach ($type['properties'] as $name => $field) {
      $field_options[$name] = $field['label'];
      $type = isset($field['type']) ? entity_property_extract_innermost_type($field['type']) : 'text';
      $is_entity = $type == 'entity' || (bool) entity_get_info($type);

      // Leave entities out of this.
      if (!$is_entity) {
        if (isset($field['field']) && $field['field'] && !empty($field['property info'])) {
          unset($field_options[$name]);
          foreach ($field['property info'] as $sub_key => $sub_prop) {
            $field_options[$name . ':' . $sub_key] = $field['label'] . ' -- ' . $sub_prop['label'];
          }
        }
        else {
          $field_options[$name] = $field['label'];
        }
      }
    }
  }
  $form['properties'] = array(
    '#title' => t('Contact properties'),
    '#type' => 'checkboxes',
    '#options' => $prop_options,
    '#default_value' => $properties,
    '#required' => FALSE,
    '#description' => t('Selected properties will be used to query duplicates. E.g., selecting first and last name will look for contacts with the same first and last names.'),
  );
  $form['fields'] = array(
    '#title' => t('Contact fields'),
    '#type' => 'checkboxes',
    '#options' => $field_options,
    '#default_value' => $fields,
    '#required' => FALSE,
    '#description' => t('Selected fields will be used to query duplicates along with the select Properties.'),
  );
  $form['active'] = array(
    '#title' => t('Active'),
    '#type' => 'checkbox',
    '#description' => t('Limit query to active contacts.'),
    '#default_value' => $active,
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Submit'),
  );
  return $form;
}