You are here

function globallink_insert_field_collections in GlobalLink Connect for Drupal 7.5

Same name and namespace in other branches
  1. 7.7 globallink.install \globallink_insert_field_collections()
  2. 7.6 globallink.install \globallink_insert_field_collections()

Inserts field collections.

Parameters

string $node_type: The content type.

2 calls to globallink_insert_field_collections()
globallink_install in ./globallink.install
Implements hook_install().
globallink_update_7201 in ./globallink.install
Implements hook_update_N().

File

./globallink.install, line 2344
Installation file for GlobalLink module.

Code

function globallink_insert_field_collections($node_type) {
  $field_arr = field_info_instances('node', $node_type);
  $keys = array_keys($field_arr);
  foreach ($keys as $field_name) {
    $field_info = field_info_field($field_name);
    if ($field_info['type'] != 'field_collection') {
      continue;
    }
    db_insert('globallink_field_config')
      ->fields(array(
      'content_type' => $node_type,
      'entity_type' => 'node',
      'bundle' => $node_type,
      'field_name' => $field_name,
      'field_type' => $field_info['type'],
      'field_label' => $field_arr[$field_name]['label'],
      'translatable' => 0,
    ))
      ->execute();
    $fc_field_infos = field_info_instances('field_collection_item');
    if (isset($fc_field_infos) && isset($fc_field_infos[$field_name]) && is_array($fc_field_infos[$field_name])) {
      $fc_items = array_keys($fc_field_infos[$field_name]);
      foreach ($fc_items as $fc_item) {
        globallink_insert_field_collection_items($node_type, $field_name, $fc_item);
      }
    }
  }
}