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

Support disabling configurations.

parent 8f376cc7
No related branches found
No related tags found
No related merge requests found
......@@ -7,4 +7,4 @@
* feeds_use_defaults to FALSE.
*
* @todo.
*/
\ No newline at end of file
*/
......@@ -238,6 +238,47 @@ function feeds_feeds_plugins() {
return _feeds_feeds_plugins();
}
/**
* Implementation of hook_node_info().
*/
function feeds_node_info() {
$items = array(
'feed' => array(
'name' => t('Feed'),
'module' => 'features',
'description' => t('Subscribe to RSS or Atom feeds. Creates nodes of the content type "Feed item" from feed content.'),
'has_title' => '1',
'title_label' => t('Title'),
'has_body' => '1',
'body_label' => t('Body'),
'locked' => TRUE,
),
'feed_item' => array(
'name' => t('Feed item'),
'module' => 'features',
'description' => t('This content type is being used for automatically aggregated content from feeds.'),
'has_title' => '1',
'title_label' => t('Title'),
'has_body' => '1',
'body_label' => t('Body'),
'locked' => TRUE,
),
);
if (module_exists('data')) {
$items['feed_light'] = array(
'name' => t('Feed (light)'),
'module' => 'features',
'description' => t('Subscribe to RSS or Atom feeds. Create light weight database records from feed content.'),
'has_title' => '1',
'title_label' => t('Title'),
'has_body' => '1',
'body_label' => t('Body'),
'locked' => TRUE,
);
}
return $items;
}
/**
* Implementation of hook_nodeapi().
*/
......
......@@ -49,16 +49,34 @@ function feeds_ui_mapping_help() {
/**
* Build overview of available configurations.
*/
function feeds_ui_overview_page() {
function feeds_ui_overview_form(&$form_status) {
$rows = array();
$form = $form['enabled'] = $form['disabled'] = array();
$form['#header'] = array(
t('Name'),
t('Description'),
t('Attached to'),
t('Status'),
t('Operations'),
t('Enabled'),
);
foreach (feeds_importer_load_all() as $importer) {
$importer_form = array();
$importer_form['name']['#value'] = $importer->config['name'];
$importer_form['description']['#value'] = $importer->config['description'];
if (empty($importer->config['content_type'])) {
$attached = '[none]';
$importer_form['attached']['#value'] = '[none]';
}
else {
$attached = l(node_get_types('name', $importer->config['content_type']), 'node/add/'. $importer->config['content_type']);
if (!$importer->disabled) {
$importer_form['attached']['#value'] = l(node_get_types('name', $importer->config['content_type']), 'node/add/'. $importer->config['content_type']);
}
else {
$importer_form['attached']['#value'] = node_get_types('name', $importer->config['content_type']);
}
}
if ($importer->export_type == EXPORT_IN_CODE) {
$status = t('Default');
$edit = t('Override');
......@@ -74,32 +92,53 @@ function feeds_ui_overview_page() {
$edit = t('Edit');
$delete = t('Revert');
}
$rows[] = array(
$importer->config['name'],
$importer->config['description'],
$attached,
$status,
l($edit, 'admin/build/feeds/edit/'. $importer->id) .' | '.
l(t('Export'), 'admin/build/feeds/export/'. $importer->id) .' | '.
l(t('Clone'), 'admin/build/feeds/clone/'. $importer->id) .
(empty($delete) ? '' : ' | '. l($delete, 'admin/build/feeds/delete/'. $importer->id)),
$importer_form['status'] = array(
'#value' => $status,
);
if (!$importer->disabled) {
$importer_form['operations'] = array(
'#value' =>
l($edit, 'admin/build/feeds/edit/'. $importer->id) .' | '.
l(t('Export'), 'admin/build/feeds/export/'. $importer->id) .' | '.
l(t('Clone'), 'admin/build/feeds/clone/'. $importer->id) .
(empty($delete) ? '' : ' | '. l($delete, 'admin/build/feeds/delete/'. $importer->id)),
);
}
else {
$importer_form['operations']['#value'] = ' ';
}
$importer_form[$importer->id] = array(
'#type' => 'checkbox',
'#default_value' => !$importer->disabled,
'#attributes' => array('class' => 'feeds-ui-trigger-submit'),
);
if ($importer->disabled) {
$form['disabled'][$importer->id] = $importer_form;
}
else {
$form['enabled'][$importer->id] = $importer_form;
}
}
$rows[] = array(
l(t('New configuration'), 'admin/build/feeds/create'),
' ',
' ',
' ',
' ',
);
$header = array(
t('Name'),
t('Description'),
t('Attached to'),
t('Status'),
t('Operations'),
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Save'),
'#attributes' => array('class' => 'feeds-ui-hidden-submit'),
);
return theme('table', $header, $rows);
return $form;
}
/**
* Submit handler for feeds_ui_overview_form().
*/
function feeds_ui_overview_form_submit($form, &$form_state) {
$disabled = array();
foreach (feeds_importer_load_all() as $importer) {
$disabled[$importer->id] = !$form_state['values'][$importer->id];
}
variable_set('default_feeds_importer', $disabled);
}
/**
......@@ -580,6 +619,37 @@ function _feeds_ui_format_options($options) {
return $result;
}
/**
* Theme feeds_ui_overview_form().
*/
function theme_feeds_ui_overview_form($form) {
drupal_add_js(drupal_get_path('module', 'feeds_ui') .'/feeds_ui.js');
drupal_add_css(drupal_get_path('module', 'feeds_ui') .'/feeds_ui.css');
// Iterate through all importers and build a table.
foreach (array('enabled', 'disabled') as $type) {
foreach (element_children($form[$type]) as $id) {
$row = array();
foreach (element_children($form[$type][$id]) as $col) {
$row[$col] = array(
'data' => drupal_render($form[$type][$id][$col]),
'class' => $type,
);
}
$rows[] = array(
'data' => $row,
'class' => $type,
);
}
}
if (count($rows)) {
$output = theme('table', $form['#header'], $rows, array('class' => 'feeds-admin-importers'));
}
$output .= drupal_render($form);
return $output;
}
/**
* Theme feeds_ui_edit_page().
*/
......
/* $Id$ */
/* Feeds admin overview form. */
table.feeds-admin-importers td.disabled {
color: #ccc;
}
table.feeds-admin-importers tr.disabled.odd,
table.feeds-admin-importers tr.disabled.even {
border-color: #eee;
}
table.feeds-admin-importers tr.disabled.odd {
background-color: #f5f5f5;
}
/* Feeds edit form layout. */
div.feeds-settings {
}
......
......@@ -26,7 +26,8 @@ function feeds_ui_menu() {
$items['admin/build/feeds'] = array(
'title' => 'Feeds',
'description' => 'Configure feeds to import or aggregate RSS and Atom feeds, import CSV files or more.',
'page callback' => 'feeds_ui_overview_page',
'page callback' => 'drupal_get_form',
'page arguments' => array('feeds_ui_overview_form'),
'access arguments' => array('administer feeds'),
'file' => 'feeds_ui.admin.inc',
);
......@@ -86,6 +87,9 @@ function feeds_ui_menu() {
*/
function feeds_ui_theme() {
return array(
'feeds_ui_overview_form' => array(
'file' => 'feeds_ui.admin.inc',
),
'feeds_ui_mapping_form' => array(
'file' => 'feeds_ui.admin.inc',
),
......
......@@ -20,6 +20,9 @@ abstract class FeedsConfigurable {
/*
CTools export type of this object.
@todo: should live in FeedsImporter. Not all child classes
of FeedsConfigurable are exportable. Same goes for $disabled.
Export type can be one of
FEEDS_EXPORT_NONE - the configurable only exists in memory
EXPORT_IN_DATABASE - the configurable is defined in the database.
......@@ -28,6 +31,11 @@ abstract class FeedsConfigurable {
overridden in the database.*/
protected $export_type;
/**
* CTools export enabled status of this object.
*/
protected $disabled;
/**
* Instantiate a FeedsConfigurable object.
*
......
......@@ -212,6 +212,7 @@ class FeedsImporter extends FeedsConfigurable {
if ($config = ctools_export_load_object('feeds_importer', 'conditions', array('id' => $this->id))) {
$config = array_shift($config);
$this->export_type = $config->export_type;
$this->disabled = $config->disabled;
$this->config = $config->config;
return TRUE;
}
......
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