You are here

function globallink_insert_fc in GlobalLink Connect for Drupal 7.7

Same name and namespace in other branches
  1. 7.5 globallink.module \globallink_insert_fc()
  2. 7.6 globallink.module \globallink_insert_fc()

Adds field-collection field to field config.

Parameters

string $entity_type: The field entity type.

string $fc_name: The field-collection name.

string $content_type: The node content type.

string $bundle: The field bundle name.

4 calls to globallink_insert_fc()
globallink_form_entity_translation_translatable_form_submit in ./globallink.module
Submit function to synch up the content type field config changes with the globallink field config changes.
globallink_form_field_ui_field_edit_form_submit in ./globallink.module
Update field config for modified bundle field.
globallink_form_field_ui_field_overview_form_submit in ./globallink.module
Submit handler for Manage Fields Page of Content Type and Field Collection. Adds a new field being added to the fields config table for translation.
globallink_insert_gl_field_config in ./globallink_field_configuration.inc
Inserts GlobalLink field configuration.

File

./globallink.module, line 531
GlobalLink translation module.

Code

function globallink_insert_fc($entity_type, $fc_name, $content_type, $bundle) {
  $fc_field_info = field_info_field($fc_name);
  $fc_field_instance = field_info_instance($entity_type, $fc_name, $bundle);
  $query = db_select('field_config', 'tf')
    ->fields('tf')
    ->condition('field_name', $fc_name, '=')
    ->condition('translatable', '1', '=')
    ->condition('type', 'field_collection', '=');
  $results = $query
    ->execute();
  if ($results
    ->rowCount() == 0) {
    return;
  }

  // Add FC field to the config
  db_insert('globallink_field_config')
    ->fields(array(
    'content_type' => $content_type,
    'entity_type' => $entity_type,
    'bundle' => $bundle,
    'field_name' => $fc_name,
    'field_type' => $fc_field_info['type'],
    'field_label' => $fc_field_instance['label'],
    'translatable' => 1,
  ))
    ->execute();
  $fc_field_infos = field_info_instances('field_collection_item');
  if (isset($fc_field_infos) && isset($fc_field_infos[$fc_name]) && is_array($fc_field_infos[$fc_name])) {
    $fc_items = array_keys($fc_field_infos[$fc_name]);
    foreach ($fc_items as $fc_item) {

      // Add all the FC field items recursively.
      globallink_insert_fc_items($content_type, $fc_name, $fc_item);
    }
  }
}