You are here

function globallink_get_pending_fields in GlobalLink Connect for Drupal 7.6

Same name and namespace in other branches
  1. 7.7 globallink.inc \globallink_get_pending_fields()
  2. 7.5 globallink.inc \globallink_get_pending_fields()

Gets pending fields by content type.

Parameters

string $content_type: The desired content type.

Return value

array Array of pending fields.

3 calls to globallink_get_pending_fields()
globallink_field in ./globallink_field_configuration.inc
Renders form for globallink_field.
globallink_insert_all_fields in ./globallink.module
Adds all fields of content type to field config.
globallink_insert_gl_field_config in ./globallink_field_configuration.inc
Inserts GlobalLink field configuration.

File

./globallink.inc, line 762
Miscellaneous GlobalLink functions for node translations (non-entity).

Code

function globallink_get_pending_fields($content_type, $entity_type = NULL) {
  $_type = $content_type;
  if ($entity_type == 'fieldable_panels_pane') {
    $_type = 'fpp:' . $content_type;
  }
  else {
    if ($entity_type == 'taxonomy_term') {
      $_type = 'tax:' . $content_type;
    }
    else {
      if ($entity_type == 'bean') {
        $_type = 'bean:' . $content_type;
      }
    }
  }
  $config_fields = globallink_get_config_fields($_type);
  if ($entity_type == NULL || $entity_type == 'node') {
    $field_info_arr = field_info_instances('node', $content_type);
    $field_info_arr[] = array(
      'field_name' => 'title',
      'label' => 'Title',
    );
    $fkeys = array_keys($field_info_arr);
    foreach ($fkeys as $key) {
      $field_info_all = field_info_field($key);
      if ($field_info_all['type'] == 'text_with_summary') {
        $field_info_arr[$key . '@summary'] = array(
          'field_name' => $key . '@summary',
          'label' => $key . ' Summary',
        );
      }
    }
  }
  else {
    $field_info_arr = field_info_instances($entity_type, $content_type);
  }
  if (module_exists('metatag') && $entity_type != 'fieldable_panels_pane') {
    $field_info_arr[] = array(
      'field_name' => 'metatags',
      'label' => 'Meta tags',
    );
  }
  $field_arr = array();
  foreach ($field_info_arr as $field_info) {
    $field_name = $field_info['field_name'];
    $sum_field = '';
    if (strpos($field_name, '@summary') !== false) {
      $sum_field = $field_name;
    }
    if ($field_name != 'metatag' && $field_name != 'title' && empty($sum_field)) {
      $field = field_info_field($field_name);
      if ($field['type'] == 'field_collection') {
        $query = db_select('field_config', 'tf')
          ->fields('tf')
          ->condition('field_name', $field_name, '=')
          ->condition('translatable', '1', '=')
          ->condition('type', 'field_collection', '=');
        $results = $query
          ->execute();
        if ($results
          ->rowCount() == 0) {
          continue;
        }
      }
      if ($field['type'] != 'list_boolean' && $field['type'] != 'file' && $field['type'] != 'taxonomy_term_reference' && $field['type'] != 'entityreference' && $field['type'] != 'list_integer') {
        if (!isset($config_fields[$field_name])) {
          $field_arr[$field_name] = $field_info['label'];
        }
      }
    }
    else {
      if (!isset($config_fields[$field_name])) {
        $field_arr[$field_name] = $field_info['label'];
      }
    }
  }
  asort($field_arr);
  if (!entity_translation_node_supported_type($content_type) && $entity_type == 'node') {
    return $field_arr;
  }
  else {

    /*Added these changes for synching up the content type field configurations, with globallink field config. */
    $ret_fields = array();
    foreach ($field_arr as $key => $value) {
      if ($key != 'metatags') {
        $ret_fields[] = $key;
      }
    }
    if (empty($ret_fields)) {
      return $field_arr;
    }
    else {
      $query = db_select('field_config', 'tf')
        ->fields('tf', array(
        'field_name',
      ))
        ->condition('field_name', $ret_fields, 'IN')
        ->condition(db_or()
        ->condition(db_and()
        ->condition('translatable', '1', '='))
        ->condition(db_and()
        ->condition('type', 'image', '=')));
      $results = $query
        ->execute();
      $result = array();
      foreach ($results as $row) {
        foreach ($field_arr as $key => $value) {
          if ($key == $row->field_name) {
            $result[$row->field_name] = $row->field_name;
          }
        }
      }
      foreach ($field_arr as $key => $value) {
        if ($key == 'metatags' || strpos($key, '@summary') !== false) {
          $result[$key] = $value;
        }
      }
      return $result;
    }
  }
}