You are here

function feeds_system_info_alter in Feeds 7.2

Implements hook_system_info_alter().

Goes through a list of all modules that provide Feeds plugins and makes them required if there are any importers using those plugins.

Related topics

File

./feeds.module, line 871
Feeds - basic API functions and hook implementations.

Code

function feeds_system_info_alter(array &$info, $file, $type) {
  if ($type !== 'module' || !module_exists($file->name) || !module_hook($file->name, 'feeds_plugins')) {
    return;
  }

  // Don't make Feeds require itself, otherwise you can't disable Feeds until
  // all importers are deleted.
  if ($file->name === 'feeds' || !function_exists('ctools_include')) {
    return;
  }

  // Get the plugins that belong to the current module.
  ctools_include('plugins');
  $module_plugins = array();
  foreach (ctools_get_plugins('feeds', 'plugins') as $plugin_id => $plugin) {
    if ($file->name === $plugin['module']) {
      $module_plugins[$plugin_id] = TRUE;
    }
  }

  // Check if any importers are using any plugins from the current module.
  foreach (feeds_importer_load_all(TRUE) as $importer) {

    // Skip importers that are defined in code and are provided by the current
    // module. This ensures that modules that define both an importer and a
    // plugin can still be disabled.
    if ($importer->export_type == EXPORT_IN_CODE) {
      $configs = ctools_export_load_object('feeds_importer', 'names', array(
        $importer->id,
      ));
      if (isset($configs[$importer->id]) && $configs[$importer->id]->export_module === $file->name) {
        continue;
      }
    }
    $configuration = $importer
      ->getConfig();
    foreach (array(
      'fetcher',
      'parser',
      'processor',
    ) as $plugin_type) {
      $plugin_key = $configuration[$plugin_type]['plugin_key'];
      if (isset($module_plugins[$plugin_key])) {
        $info['required'] = TRUE;
        break 2;
      }
    }
  }
  if (empty($info['required'])) {
    return;
  }
  if (module_exists('feeds_ui') && user_access('administer feeds')) {
    $info['explanation'] = t('Feeds is currently using this module for one or more <a href="@link">importers</a>', array(
      '@link' => url('admin/structure/feeds'),
    ));
  }
  else {
    $info['explanation'] = t('Feeds is currently using this module for one or more importers');
  }
}