Please see http://drupal.org/node/1180574#comment-6091462.

I'm not sure if the maintainers of field collection would include a services component in their module. Does including it in Services core make sense?

Comments

Wassim Ghannoum’s picture

I'm having the same problem

is there any other way to organize fields in Drupal 7 ?

marcingy’s picture

Status: Active » Closed (won't fix)

Services doesn't support things out side of drupal core.

hypertext200’s picture

Here is a simple fix to the field collections. I'm using Restful with XML data.

<!-- field collection starts here -->
<field_collection_item>
   <und is_array="TRUE">
      <item>
         <entity>
            <field_name>field_collection_item</field_name>
            <field_text>
               <und is_array="TRUE">
                  <item>
                     <value>Some text</value>
                  </item>
               </und>
            </field_text_unlimited>
            <field_text>
               <und is_array="TRUE">
                  <item>
                     <value>Some text</value>
                  </item>
               </und>
            </field_text_unlimited>
      </item>
   </und>
</field_collection_item>

Then in a custom module implement hook_services_request_preprocess_alter()

/**
 * Implements hook_services_request_preprocess_alter()
 * @note : Serivices module hook
 */
function YOURMODULE_services_request_preprocess_alter($controller, &$args) {
  foreach ($args as $key => $arg) {
    $entities = _service_fieldcollection_recursive_search($arg, 'entity');
    foreach ($entities as $delta => $entity) {
      $field_name = $entity['field_name'];
      $field_collection = new FieldCollectionItemEntity($args[$key][$field_name]['und'][$delta]['entity']);
      $args[$key][$field_name]['und'][$delta]['entity'] = $field_collection;
    }
  }
}

/**
 * Recureisve search on the array
 */
function _service_fieldcollection_recursive_search($array, $key) {
  $results = array();
  if (is_array($array)) {
    if (isset($array[$key])) {
      $results[] = $array[$key];
    }
    foreach ($array as $subarray) {
      $results = array_merge($results, _service_fieldcollection_recursive_search($subarray, $key));
    }
  }
  return $results;
}

This can be extended for all the other type of entities which has entity host as node. Hope this help.

hypertext200’s picture

zach.bimson’s picture

Would the creator not be interested in this being part of the module or maybe even a sub module?