You are here

function _filter_fields in GatherContent 7.3

Same name and namespace in other branches
  1. 8 forms/gc.mapping-edit.inc \_filter_fields()

Helper function.

Use for filtering only equivalent fields.

Parameters

object $gathercontent_field: Type of field in GatherContent.

string $content_type: Name of Drupal content type.

Return value

array Associative array with equivalent fields.

1 call to _filter_fields()
gathercontent_mapping_edit_form in forms/gathercontent.mapping-edit.inc
Edit mapping form.

File

forms/gathercontent.mapping-edit.inc, line 531
Multistep mapping form.

Code

function _filter_fields($gathercontent_field, $content_type) {
  $mapping_array = array(
    'files' => array(
      'file',
      'image',
    ),
    'section' => array(
      'text_long',
    ),
    'text' => array(
      'text',
      'text_long',
      'text_with_summary',
    ),
    'choice_radio' => array(
      'text',
    ),
    'choice_checkbox' => array(
      'list_text',
    ),
  );
  $instances = field_info_instances('node', $content_type);
  $fields = array();

  // Fields.
  foreach ($instances as $name => $instance) {
    $field = field_info_field($instance['field_name']);
    if (in_array($field['type'], $mapping_array[$gathercontent_field->type])) {

      // Constrains:
      // - do not map plain text (Drupal) to rich text (gathercontent).
      // - do not map radios (gathercontent) to text (Drupal),
      // if widget isn't provided by select_or_other module.
      // - do not map section (gathercontent) to plain text (Drupal).
      switch ($gathercontent_field->type) {
        case 'text':
          if (!$instance['settings']['text_processing'] && !$gathercontent_field->plain_text || $instance['widget']['module'] === 'select_or_other') {
            continue 2;
          }
          break;
        case 'choise_radio':
          if ($instance['widget']['module'] !== 'select_or_other') {
            continue 2;
          }
          break;
        case 'section':
          if (!$instance['settings']['text_processing']) {
            continue 2;
          }
          break;
      }
      $fields[$instance['field_name']] = $instance['label'];
    }
  }
  if ($gathercontent_field->type === 'text' && $gathercontent_field->plain_text && (!module_exists('title') || !title_field_replacement_enabled('node', $content_type, 'title'))) {
    $fields['title'] = 'Title';
  }
  return $fields;
}