Skip to content
Snippets Groups Projects
Commit 87c79ba1 authored by Alex Barth's avatar Alex Barth
Browse files

Switch node types depending on enabled feed importers. Clear caches properly...

Switch node types depending on enabled feed importers.  Clear caches properly after enabling/disabling an importer configuration.
parent 7d889939
No related branches found
No related tags found
No related merge requests found
...@@ -242,8 +242,9 @@ function feeds_feeds_plugins() { ...@@ -242,8 +242,9 @@ function feeds_feeds_plugins() {
* Implementation of hook_node_info(). * Implementation of hook_node_info().
*/ */
function feeds_node_info() { function feeds_node_info() {
$items = array( $items = array();
'feed' => array( if (feeds_importer_enabled('feed')) {
$items['feed'] = array(
'name' => t('Feed'), 'name' => t('Feed'),
'module' => 'features', 'module' => 'features',
'description' => t('Subscribe to RSS or Atom feeds. Creates nodes of the content type "Feed item" from feed content.'), 'description' => t('Subscribe to RSS or Atom feeds. Creates nodes of the content type "Feed item" from feed content.'),
...@@ -252,8 +253,8 @@ function feeds_node_info() { ...@@ -252,8 +253,8 @@ function feeds_node_info() {
'has_body' => '1', 'has_body' => '1',
'body_label' => t('Body'), 'body_label' => t('Body'),
'locked' => TRUE, 'locked' => TRUE,
), );
'feed_item' => array( $items['feed_item'] = array(
'name' => t('Feed item'), 'name' => t('Feed item'),
'module' => 'features', 'module' => 'features',
'description' => t('This content type is being used for automatically aggregated content from feeds.'), 'description' => t('This content type is being used for automatically aggregated content from feeds.'),
...@@ -262,9 +263,9 @@ function feeds_node_info() { ...@@ -262,9 +263,9 @@ function feeds_node_info() {
'has_body' => '1', 'has_body' => '1',
'body_label' => t('Body'), 'body_label' => t('Body'),
'locked' => TRUE, 'locked' => TRUE,
), );
); }
if (module_exists('data')) { if (feeds_importer_enabled('feed_light')) {
$items['feed_light'] = array( $items['feed_light'] = array(
'name' => t('Feed (light)'), 'name' => t('Feed (light)'),
'module' => 'features', 'module' => 'features',
...@@ -464,6 +465,35 @@ function feeds_importer_load_all() { ...@@ -464,6 +465,35 @@ function feeds_importer_load_all() {
return $feeds; return $feeds;
} }
/**
* Return whether a importer is enabled or not.
*
* Use only for importer configurations that ship with feeds. This function
* assumes that importers are initially off and then enabled manually on
* admin/build/feeds.
*
* @return
* TRUE if the importer is enabled, FALSE if not.
*/
function feeds_importer_enabled($id) {
// 'default_feeds_importer' variable is used internally by CTools to determine
// the enabled/disabled state of a configuration. This variable may not be
// completely populated.
$disabled = variable_get('default_feeds_importer', FALSE);
if ($disabled === FALSE) {
$disabled = array();
foreach (feeds_importer_load_all() as $importer) {
$disabled[$importer->id] = $disabled->disabled;
}
variable_set('default_feeds_importer', $disabled);
}
// If disabled is not present, assume that importer configuration is disabled.
if (!isset($disabled[$id])) {
return FALSE;
}
return !$disabled[$id];
}
/** /**
* Get a feed configuration by content type. * Get a feed configuration by content type.
* *
......
...@@ -139,6 +139,11 @@ function feeds_ui_overview_form_submit($form, &$form_state) { ...@@ -139,6 +139,11 @@ function feeds_ui_overview_form_submit($form, &$form_state) {
$disabled[$importer->id] = !$form_state['values'][$importer->id]; $disabled[$importer->id] = !$form_state['values'][$importer->id];
} }
variable_set('default_feeds_importer', $disabled); variable_set('default_feeds_importer', $disabled);
// Clear caches.
node_get_types('types', NULL, TRUE);
cache_clear_all();
menu_rebuild();
} }
/** /**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment