You are here

function farm_api_restws_response_alter_item in farmOS 7

Helper function for altering a restws response item.

Parameters

$item: The restws response item, passed by reference.

1 call to farm_api_restws_response_alter_item()
farm_api_restws_response_alter in modules/farm/farm_api/farm_api.module
Implements hook_restws_response_alter().

File

modules/farm/farm_api/farm_api.module, line 541
Farm API module.

Code

function farm_api_restws_response_alter_item(&$item) {

  // Build a field alias map to remove the 'field_farm_' prefix.
  $prefix = 'field_farm_';
  $alias_map = farm_api_field_alias_map($prefix);

  // Flip the alias map so that it is keyed by actual field name.
  $field_aliases = array_flip($alias_map);

  // Iterate through the item properties.
  foreach (array_keys($item) as $key) {

    // If the field name exists in the alias map, replace it with the alias.
    if (array_key_exists($key, $field_aliases)) {
      $item[$field_aliases[$key]] = $item[$key];
      unset($item[$key]);
    }

    // Remove Feeds properties.
    $feeds_prefixes = array(
      'feed_',
      'feeds_',
    );
    foreach ($feeds_prefixes as $prefix) {
      if (strpos($key, $prefix) === 0) {
        unset($item[$key]);
      }
    }
  }
}