You are here

function apps_add_app_info in Apps 7

@TODO: Add function description

Parameters

$apps:

1 call to apps_add_app_info()
apps_manifest in ./apps.manifest.inc
Produce the Process Manifest.

File

./apps.manifest.inc, line 519
Handles pulling and processing of app data from the server

Code

function apps_add_app_info(&$apps) {
  $info_cache = cache_get("apps_installed_app_info");
  $info = array();
  if ($info_cache) {
    $info = $info_cache->data;
  }
  $set_cache = FALSE;
  foreach ($apps as $id => $app) {
    if (!isset($info[$app['machine_name']])) {
      $info[$app['machine_name']] = array();

      // Check if app is local.
      $module_cache = system_rebuild_module_data();
      if (isset($module_cache[$app['machine_name']])) {
        if (!module_exists($app['machine_name'])) {

          // Module is in the codebase but not installed.
          module_load_include('module', $app['machine_name']);
          module_load_include('app.inc', $app['machine_name']);
        }
        $info[$app['machine_name']] = ($i = module_invoke($app['machine_name'], 'apps_app_info')) ? $i : array();
      }
      $set_cache = TRUE;
    }
    $apps[$id] += $info[$app['machine_name']];

    // Add defaults
    $info_defaults = array(
      'configure form' => $app['machine_name'] . "_apps_app_configure_form",
      'demo content description' => "Enabling the demo content will add content to the site that can help to understand how the app functions.  When it is disabled all of the demo content will be removed.",
      'parent_apps' => array(),
    );
    $apps[$id] += $info_defaults;
    if (!empty($app['dependencies']) && ($parent_apps = array_intersect_key($app['dependencies'], $apps))) {
      $apps[$id]['parent_apps'] = array_merge($apps[$id]['parent_apps'], $parent_apps);
    }

    // Set demo content callbacks if demo content module is set
    if (isset($apps[$id]['demo content module'])) {
      $apps[$id] += array(
        'demo content enabled callback' => 'apps_demo_content_enabled',
        'demo content enable callback' => 'apps_demo_content_enable',
        'demo content disable callback' => 'apps_demo_content_disable',
      );
    }

    // Turn conflicts into array('server' => 'server', name => 'name') as needed.
    foreach ($app['conflicts'] as $conflict_key => $conflict) {
      if (is_string($conflict) && strpos($conflict, ' ')) {
        $conflict = explode(' ', $conflict);
        $apps[$id]['conflicts'][$conflict_key] = array(
          'server' => $conflict[0],
          'name' => $conflict[1],
        );
      }
      elseif (is_string($conflict)) {
        $apps[$id]['conflicts'][$conflict_key] = array(
          'name' => $conflict,
        );
      }

      // Set server to this app's server if empty
      if (empty($apps[$id]['conflicts'][$conflict_key]['server'])) {
        $apps[$id]['conflicts'][$conflict_key]['server'] = $app['server']['name'];
      }

      // Mark as incompatible if enabled conflict.
      // Not checking other servers due to risk of timing issues/endless loop.
      if ($apps[$id]['conflicts'][$conflict_key]['server'] == $app['server']['name'] && !empty($apps[$app['server']['name']]) && $apps[$app['server']['name']]['status'] == APPS_ENABLED) {
        $apps[$id]['status'] = APPS_INCOMPATIBLE;
      }
    }
  }
  if ($set_cache) {
    cache_set("apps_install_app_info", $info);
  }
}