You are here

function farm_api_field_alias_map in farmOS 7

Build a field alias map for restws requests and responses.

Parameters

string $prefix: The field name prefix to remove from fields.

Return value

array Returns an array of field names with the alias as the key, and the actual field name as the value.

2 calls to farm_api_field_alias_map()
farm_api_restws_request_alter in modules/farm/farm_api/farm_api.module
Implements hook_restws_request_alter().
farm_api_restws_response_alter_item in modules/farm/farm_api/farm_api.module
Helper function for altering a restws response item.

File

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

Code

function farm_api_field_alias_map($prefix) {

  // Start an empty map array.
  $alias_map = array();

  // Load a list of all fields.
  $fields = field_info_field_map();

  // Iterate through the fields to build an alias map.
  foreach ($fields as $field_name => $field_info) {

    // If the field is a field_collection, skip it. Field collection alias are a
    // special case that are currently handled by the restws_field_collection
    // module in farmOS.
    if ($field_info['type'] == 'field_collection') {
      continue;
    }

    // If the field name starts with the prefix, add it to the map.
    if (strpos($field_name, $prefix) === 0) {
      $alias = str_replace($prefix, '', $field_name);
      $alias_map[$alias] = $field_name;
    }
  }

  // Return the alias map.
  return $alias_map;
}