You are here

function globallink_insert_fc_items in GlobalLink Connect for Drupal 7.6

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

Adds child field of field-collection to field config.

Parameters

string $content_type: The node content type.

string $parent_field_name: The parent field-collection name.

string $field_name: The field name.

2 calls to globallink_insert_fc_items()
globallink_form_field_ui_field_edit_form_submit in ./globallink.module
Update field config for modified bundle field.
globallink_insert_fc in ./globallink.module
Adds field-collection field to field config.

File

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

Code

function globallink_insert_fc_items($content_type, $parent_field_name, $field_name) {

  // Everything added here will have entity type as field_collection_item
  $fc_field_info = field_info_field($field_name);
  $fc_field_instance = field_info_instance('field_collection_item', $field_name, $parent_field_name);
  switch ($fc_field_info['type']) {
    case 'image':
    case 'file':
    case 'list_integer':
    case 'list_boolean':
    case 'entity_reference':
    case 'taxonomy_term_reference':
      break;
    case 'field_collection':

      // Field-collection in a field-collection, first add this field-collection to the config
      db_insert('globallink_field_config')
        ->fields(array(
        'content_type' => $content_type,
        'entity_type' => 'field_collection_item',
        'bundle' => $parent_field_name,
        'field_name' => $field_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[$field_name]) && is_array($fc_field_infos[$field_name])) {
        $fc_items = array_keys($fc_field_infos[$field_name]);
        foreach ($fc_items as $fc_item) {

          // Now add the child fields for this field-collection recursively
          globallink_insert_fc_items($content_type, $field_name, $fc_item);
        }
      }
      break;
    default:
      if ($fc_field_info['translatable'] == 0) {
        break;
      }
      db_insert('globallink_field_config')
        ->fields(array(
        'content_type' => $content_type,
        'entity_type' => 'field_collection_item',
        'bundle' => $parent_field_name,
        'field_name' => $field_name,
        'field_type' => $fc_field_info['type'],
        'field_label' => $fc_field_instance['label'],
        'translatable' => 1,
      ))
        ->execute();
      break;
  }
}