function restws_field_collection_entity_property_info_alter in RESTful Web Services Field Collection 7
Implements hook_entity_property_info_alter().
File
- ./
restws_field_collection.module, line 22 - RESTful Web Services Field collection module.
Code
function restws_field_collection_entity_property_info_alter(&$info) {
// Get information about field collections.
$field_collections = restws_field_collection_info();
// Iterate through entity types.
foreach ($info as $entity_type => &$entity_info) {
// If the entity type doesn't have any bundles, skip it.
if (empty($entity_info['bundles'])) {
continue;
}
// Iterate through the entity type bundles.
foreach ($entity_info['bundles'] as $bundle => &$bundle_info) {
// Iterate through the field collections defined above.
foreach ($field_collections as $fc_name => $fc_info) {
// If the bundle doesn't contain the field collection, skip it.
if (!array_key_exists($fc_name, $bundle_info['properties'])) {
continue;
}
// If the field collection doesn't have an alias, label, or field info,
// skip it.
if (empty($fc_info['alias']) || empty($fc_info['label']) || empty($fc_info['fields'])) {
continue;
}
// If the field collection supports multiple values, make it a list.
$type = 'struct';
if (!empty($fc_info['multiple'])) {
$type = 'list<' . $type . '>';
}
// Add a new property for the field collection using its alias.
$bundle_info['properties'][$fc_info['alias']] = array(
'type' => $type,
'label' => $fc_info['label'],
'getter callback' => 'restws_field_collection_property_get',
'setter callback' => 'restws_field_collection_property_set',
'property info' => array(),
);
// Assemble property info based on the field info.
foreach ($fc_info['fields'] as $field_name => $field_info) {
// If the field supports multiple values, make it a list.
$type = $field_info['field_type'];
if (!empty($field_info['multiple'])) {
$type = 'list<' . $type . '>';
}
// Set the field property info.
$bundle_info['properties'][$fc_info['alias']]['property info'][$field_name] = array(
'type' => $type,
'label' => $field_info['field_label'],
);
}
}
}
}
}