You are here

function farm_api_info in farmOS 7

Farm info API callback.

1 string reference to 'farm_api_info'
farm_api_menu in modules/farm/farm_api/farm_api.module
Implements hook_menu().

File

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

Code

function farm_api_info() {

  // Start with an empty info array.
  $info = array();

  // Check for an authenticated user with access to farmOS API info.
  $access = user_access('access farm api info');

  // Iterate through all the modules that implement hook_farm_info.
  $hook = 'farm_info';
  $modules = module_implements($hook);
  foreach ($modules as $module) {

    // Invoke the hook to get info.
    $module_info = module_invoke($module, $hook);

    // If the info is empty, skip it.
    if (!is_array($module_info)) {
      continue;
    }

    // Iterate through the info items.
    foreach ($module_info as $key => $item) {

      // If the item is an array with an 'info' key, that is what we will
      // include.
      if (is_array($item) && !empty($item['info'])) {

        // If the user is authenticated with permission OR if an OAuth2 scope is
        // authorized for this request, add the item to the info array.
        if ($access || !empty($item['scope']) && farm_api_check_scope($item['scope'])) {

          // Add the key to an array before merging.
          $item = array(
            $key => $item['info'],
          );

          // Include in info.
          $info = array_merge($info, $item);
        }
      }
      elseif ($access) {

        // Add the key to an array before merging.
        $item = array(
          $key => $item,
        );

        // Include in info.
        $info = array_merge($info, $item);
      }
    }
  }

  // Output as JSON.
  drupal_json_output($info);
}