You are here

function fusion_apply_implements in Fusion Accelerator 7

Same name and namespace in other branches
  1. 7.2 fusion_apply/fusion_apply.module \fusion_apply_implements()

Returns a list of extensions that implement this API version of Fusion Apply.

@todo Cache this.

Return value

An associative array whose keys are system names of extensions and whose values are again associative arrays containing:

  • type: Either 'module' or 'theme'.
  • name: The system name of the extension.
  • path: The path to the extension.
  • directory: (optional) The sub-directory holding Fusion plugin files.
  • ...: Any other properties defined by the module or theme.
5 calls to fusion_apply_implements()
FusionApplyApiTestCase::testFusionApplyImplements in fusion_apply/tests/fusion_apply.test
Tests fusion_apply_implements().
fusion_apply_get_config_info in fusion_apply/fusion_apply.module
Fetch Fusion Apply configuration data from functionality plugins.
fusion_apply_get_group_info in fusion_apply/fusion_apply.module
Retrieves all skin groups registered by modules and themes.
fusion_apply_get_skin_info in fusion_apply/fusion_apply.module
Retrieves all skins registered by modules and themes.
fusion_apply_load_includes in fusion_apply/fusion_apply.module
Includes $extension.fusion.inc files of extensions compatible with this version of Fusion Apply.

File

fusion_apply/fusion_apply.module, line 208
Handles core Fusion Apply functionality.

Code

function fusion_apply_implements() {
  $cache =& drupal_static(__FUNCTION__);
  if (!isset($cache)) {
    $cache = array();

    // Collect hook_fusion_apply_api_VERSION() module implementations. This will also
    // auto-load $module.fusion_apply.inc files, which may contain skin/group hook
    // implementations (when not using the plugin system).
    $module_info = system_get_info('module');
    foreach (module_implements('fusion_apply_api_' . fusion_apply_VERSION) as $module) {

      // Ensure that $module and the extension type is registered.
      $cache[$module] = array(
        'type' => 'module',
        'name' => $module,
        'version' => isset($module_info[$module]['version']) ? $module_info[$module]['version'] : NULL,
      );

      // Check whether the hook returns any information.
      $function = $module . '_fusion_apply_api_' . fusion_apply_VERSION;
      $info = $function();
      if (isset($info) && is_array($info)) {
        $cache[$module] += $info;
      }

      // If the module specified a custom path, check whether it contains a
      // $module.fusion.inc file and auto-load it. module_implements() only
      // auto-loads $module.fusion.inc in a module's root folder.
      if (isset($cache[$module]['path'])) {
        $file = DRUPAL_ROOT . '/' . $cache[$module]['path'] . '/' . $module . '.fusion.inc';
        if (file_exists($file)) {
          require_once $file;
        }
      }

      // Populate defaults.
      $cache[$module] += array(
        'path' => drupal_get_path('module', $module),
        'directory' => NULL,
      );
    }

    // Collect the equivalent of hook_fusion_apply_api_VERSION() implementations in
    // themes. The theme system only initializes one theme (and optionally its
    // base themes) for the current request, and the phptemplate engine only
    // loads template.php during theme initialization. Furthermore, template.php
    // is a custom concept of the phptemplate engine and does not exist for
    // other theme engines. Since we are interested in all existing
    // implementations of all enabled themes, the equivalent of the module hook
    // is a theme .info file property 'fusion' that has the sub-keys 'api' and
    // optionally 'directory' defined.
    // Account for all enabled themes and (any recursive) base themes of them,
    // regardless of whether base themes are enabled.
    $all_themes = list_themes();
    $themes = array();

    // Additionally record the base themes and sub themes of each theme, in
    // order to apply inheritance rules elsewhere. Do not assign these variables
    // as properties on the theme objects themselves, since all objects are
    // pointers (much like references) in PHP 5, so our properties would be
    // visible for everyone else who calls list_themes().
    $base_themes = array();
    $sub_themes = array();
    foreach ($all_themes as $name => $theme) {

      // If the theme is enabled, add it to the stack.
      if (!empty($theme->status)) {
        $themes[$name] = $theme;

        // Find and add all base themes of the enabled theme to the stack.
        // @see drupal_theme_initialize()
        $sub_theme_name = $name;
        while ($name && isset($all_themes[$name]->base_theme)) {

          // Record the sub theme for the base theme.
          $sub_themes[$all_themes[$name]->base_theme][$name] = $name;

          // Add the base theme to the stack.
          $name = $all_themes[$name]->base_theme;
          $themes[$name] = $all_themes[$name];

          // Record the base theme for the original sub theme.
          $base_themes[$sub_theme_name][$name] = $name;
        }
      }
    }
    foreach ($themes as $name => $theme) {
      if (isset($theme->info['fusion']['api']) && $theme->info['fusion']['api'] == fusion_apply_VERSION) {

        // Ensure that the theme name and the extension type is registered.
        $cache[$name] = array(
          'type' => 'theme',
          'name' => $name,
          'version' => isset($theme->info['version']) ? $theme->info['version'] : NULL,
          'base themes' => isset($base_themes[$name]) ? $base_themes[$name] : array(),
          'sub themes' => isset($sub_themes[$name]) ? $sub_themes[$name] : array(),
        );

        // Add any additional information that has been registered.
        $cache[$name] += $theme->info['fusion'];

        // Populate defaults.
        $cache[$name] += array(
          'path' => drupal_get_path('theme', $name),
          // Since themes cannot do anything else than registering skins and
          // groups, we default to the sub-directory 'skins'.
          'directory' => 'skins',
        );

        // Lastly, for API consistency with modules, check whether the theme
        // contains a $theme.fusion.inc file and auto-load it, if any.
        $file = DRUPAL_ROOT . '/' . $cache[$name]['path'] . '/' . $name . '.fusion.inc';
        if (file_exists($file)) {
          require_once $file;
        }
      }
    }
  }
  return $cache;
}