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

Debug some of the configuration building, rename advanced to plugins.

parent dcaa933e
No related branches found
No related tags found
No related merge requests found
...@@ -11,7 +11,7 @@ function feeds_schema() { ...@@ -11,7 +11,7 @@ function feeds_schema() {
$schema['feeds_configuration'] = array( $schema['feeds_configuration'] = array(
'description' => 'Configuration of feeds objects.', 'description' => 'Configuration of feeds objects.',
'export' => array( 'export' => array(
'key' => 'name', 'key' => 'id',
'identifier' => 'feed_object', 'identifier' => 'feed_object',
'default hook' => 'feeds', // Function hook name. 'default hook' => 'feeds', // Function hook name.
'api' => array( 'api' => array(
......
...@@ -20,6 +20,19 @@ function feeds_perm() { ...@@ -20,6 +20,19 @@ function feeds_perm() {
return array('use feeds', 'administer feeds'); return array('use feeds', 'administer feeds');
} }
/**
* Implementation of hook_ctools_plugin_api().
*
* @todo: switch hook_feeds_plugin() over to hook_ctools_plugin_api().
*/
function feeds_ctools_plugin_api($owner, $api) {
if ($owner == 'feeds' && $api == 'plugins') {
return array(
'version' => 1,
'');
}
}
/** /**
* Implementation of hook_feeds_plugin(). * Implementation of hook_feeds_plugin().
*/ */
......
...@@ -4,6 +4,24 @@ ...@@ -4,6 +4,24 @@
* @file * @file
*/ */
/**
* List available feed configurations.
*/
function feeds_ui_content_overview() {
$rows = array();
if ($feeds = feeds_load_all()) {
foreach ($feeds as $feed) {
$rows[] = array(
$feed->getId(),
);
}
}
$header = array(
t('Configurations'),
);
return theme('table', $header, $rows);
}
/** /**
* Build overview of available configurations. * Build overview of available configurations.
*/ */
...@@ -38,7 +56,7 @@ function feeds_ui_build_create_form(&$form_state) { ...@@ -38,7 +56,7 @@ function feeds_ui_build_create_form(&$form_state) {
$form['id'] = array( $form['id'] = array(
'#type' => 'textfield', '#type' => 'textfield',
'#title' => t('Id'), '#title' => t('Id'),
'#description' => t('A unique identifier for this preset.'), '#description' => t('A unique identifier for this configuration.'),
); );
$form['submit'] = array( $form['submit'] = array(
'#type' => 'submit', '#type' => 'submit',
...@@ -79,7 +97,7 @@ function feeds_ui_build_create_form_submit($form, &$form_state) { ...@@ -79,7 +97,7 @@ function feeds_ui_build_create_form_submit($form, &$form_state) {
* Edit an existing configuration. * Edit an existing configuration.
*/ */
function feeds_ui_build_edit_form(&$form_state, $feed) { function feeds_ui_build_edit_form(&$form_state, $feed) {
$form = _feeds_ui_config_form ($feed); $form = _feeds_ui_config_form($feed);
$form['submit'] = array( $form['submit'] = array(
'#type' => 'submit', '#type' => 'submit',
'#value' => t('Save'), '#value' => t('Save'),
...@@ -88,21 +106,19 @@ function feeds_ui_build_edit_form(&$form_state, $feed) { ...@@ -88,21 +106,19 @@ function feeds_ui_build_edit_form(&$form_state, $feed) {
} }
/** /**
* Edit an existing configuration. * Submit handler for feeds_ui_build_edit_form().
*/ */
function feeds_ui_build_mapping_form(&$form_state, $feed) { function feeds_ui_build_edit_form_submit($form, &$form_state) {
$form = array(); $feed = $form['#feed'];
$form['submit'] = array( $form['#feed']->addConfig($form_state['values']);
'#type' => 'submit', $form['#feed']->save();
'#value' => t('Save'), drupal_set_message(t('Saved configuration'));
);
return $form;
} }
/** /**
* Edit an existing configuration. * Edit an existing configuration.
*/ */
function feeds_ui_build_advanced_form(&$form_state, $feed) { function feeds_ui_build_mapping_form(&$form_state, $feed) {
$form = array(); $form = array();
$form['submit'] = array( $form['submit'] = array(
'#type' => 'submit', '#type' => 'submit',
...@@ -112,9 +128,9 @@ function feeds_ui_build_advanced_form(&$form_state, $feed) { ...@@ -112,9 +128,9 @@ function feeds_ui_build_advanced_form(&$form_state, $feed) {
} }
/** /**
* Helper, build edit UI for a feed. Used for editing and creating. * Edit plugin configuration.
*/ */
function _feeds_ui_config_form($feed = NULL) { function feeds_ui_build_plugin_form(&$form_state, $feed) {
$form = array(); $form = array();
$plugins = feeds_get_plugins(); $plugins = feeds_get_plugins();
$form['plugins'] = array( $form['plugins'] = array(
...@@ -125,14 +141,14 @@ function _feeds_ui_config_form($feed = NULL) { ...@@ -125,14 +141,14 @@ function _feeds_ui_config_form($feed = NULL) {
'#type' => 'radios', '#type' => 'radios',
'#title' => t('Fetcher'), '#title' => t('Fetcher'),
'#options' => $plugins['fetcher'], '#options' => $plugins['fetcher'],
'#description' => t('Select a fetcher for this preset'), '#description' => t('Select a fetcher for this configuration.'),
'#default_value' => empty($feed) ? key($plugins['fetcher']) : get_class($feed->fetcher), '#default_value' => empty($feed) ? key($plugins['fetcher']) : get_class($feed->fetcher),
); );
$form['plugins']['parser'] = array( $form['plugins']['parser'] = array(
'#type' => 'radios', '#type' => 'radios',
'#title' => t('Parser'), '#title' => t('Parser'),
'#options' => $plugins['parser'], '#options' => $plugins['parser'],
'#description' => t('Select a parser for this preset'), '#description' => t('Select a parser for this configuration.'),
'#default_value' => empty($feed) ? key($plugins['parser']) : get_class($feed->parser), '#default_value' => empty($feed) ? key($plugins['parser']) : get_class($feed->parser),
); );
if (empty($feed)) { if (empty($feed)) {
...@@ -147,34 +163,57 @@ function _feeds_ui_config_form($feed = NULL) { ...@@ -147,34 +163,57 @@ function _feeds_ui_config_form($feed = NULL) {
'#type' => 'checkboxes', '#type' => 'checkboxes',
'#title' => t('Processors'), '#title' => t('Processors'),
'#options' => $plugins['processor'], '#options' => $plugins['processor'],
'#description' => t('Select processors for this preset'), '#description' => t('Select processors for this configuration.'),
'#default_value' => $default, '#default_value' => $default,
); );
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Save'),
);
return $form;
}
/**
* Helper, build edit UI for a feed. Used for editing and creating.
* @todo: pull form from feed object.
*/
function _feeds_ui_config_form($feed = NULL) {
$form = array();
if ($feed) {
$config = $feed->getConfig();
$form['#feed'] = $feed;
}
$form['settings'] = array( $form['settings'] = array(
'#type' => 'fieldset', '#type' => 'fieldset',
'#title' => t('Basic settings'), '#title' => t('Basic configuration'),
); );
$form['settings']['content_type'] = array( $form['settings']['content_type'] = array(
'#type' => 'select', '#type' => 'select',
'#title' => t('Attach to content type'), '#title' => t('Attach to content type'),
'#description' => t('When you attach a feeds configuration to a node, you can use nodes for creating feeds on your site.'), '#description' => t('When you attach a configuration to a node, you can use nodes for creating feeds on your site.'),
'#options' => array('' => t('None')) + node_get_types('names'), '#options' => array('' => t('None')) + node_get_types('names'),
'#default_value' => '', '#default_value' => $config['content_type'],
); );
$form['settings']['source'] = array(
'#type' => 'textfield',
'#title' => t('URL'),
'#description' => t('Enter the URL for this feed @todo: delegate this form to plugin, hide if content type is picked.'),
'#default_value' => $config['source']['id'],
);
$form['settings']['update'] = array( $form['settings']['update'] = array(
'#type' => 'radios', '#type' => 'radios',
'#title' => t('Update existing'), '#title' => t('Update existing'),
'#options' => array(1 => t('Yes'), 0 => t('No')), '#options' => array(1 => t('Yes'), 0 => t('No')),
'#default_value' => 0, // @todo '#default_value' => $config['update'],
); );
$period = drupal_map_assoc(array(1, 900, 1800, 3600, 10800, 21600, 32400, 43200, 86400, 172800, 259200, 604800, 1209600, 2419200, 3628800, 4838400, 7257600, 15724800, 31536000), 'format_interval'); $period = drupal_map_assoc(array(1, 900, 1800, 3600, 10800, 21600, 32400, 43200, 86400, 172800, 259200, 604800, 1209600, 2419200, 3628800, 4838400, 7257600, 15724800, 31536000), 'format_interval');
$period[FEEDAPI_CRON_NEVER_REFRESH] = t('Never refresh'); $period[FEEDAPI_CRON_NEVER_REFRESH] = t('Do not refresh periodically');
$period[1] = t('As often as possible'); $period[1] = t('As often as possible');
$form['settings']['refresh_period'] = array( $form['settings']['refresh_period'] = array(
'#type' => 'select', '#type' => 'select',
'#title' => t('Minimum refresh period'), '#title' => t('Minimum refresh period'),
'#options' => $period, '#options' => $period,
'#default_value' => 0, // @todo '#default_value' => $config['refresh_period'],
); );
return $form; return $form;
} }
\ No newline at end of file
...@@ -4,6 +4,20 @@ ...@@ -4,6 +4,20 @@
* @file * @file
*/ */
/**
* Implementation of hook_help().
*/
function feeds_ui_help($path, $arg) {
switch ($path) {
case 'admin/build/feeds':
$output = '<p>'. t('Configure one or more feeds to import content into Drupal. You can use these feed configurations directly here or - if you attach them to a content type - simply by creating a node from that content type.') .'</p>';
return $output;
case 'admin/content/feeds':
$output = '<p>'. t('Import content into Drupal.') .'</p>';
return $output;
}
}
/** /**
* Implementation of hook_menu(). * Implementation of hook_menu().
*/ */
...@@ -45,25 +59,26 @@ function feeds_ui_menu() { ...@@ -45,25 +59,26 @@ function feeds_ui_menu() {
'type' => MENU_CALLBACK, 'type' => MENU_CALLBACK,
); );
$items['admin/build/feeds/edit/%feeds/edit'] = array( $items['admin/build/feeds/edit/%feeds/edit'] = array(
'title' => t('Configuration'), 'title' => t('Basic'),
'type' => MENU_DEFAULT_LOCAL_TASK, 'type' => MENU_DEFAULT_LOCAL_TASK,
); );
$items['admin/build/feeds/edit/%feeds/map'] = array( $items['admin/build/feeds/edit/%feeds/plugins'] = array(
'title' => t('Mapping'), 'title' => t('Plugins'),
'page callback' => 'drupal_get_form', 'page callback' => 'drupal_get_form',
'page arguments' => array('feeds_ui_build_mapping_form', 4), 'page arguments' => array('feeds_ui_build_plugin_form', 4),
'access arguments' => array('administer feeds'), 'access arguments' => array('administer feeds'),
'file' => 'feeds_ui.admin.inc', 'file' => 'feeds_ui.admin.inc',
'type' => MENU_LOCAL_TASK, 'type' => MENU_LOCAL_TASK,
'weight' => 1,
); );
$items['admin/build/feeds/edit/%feeds/advanced'] = array( $items['admin/build/feeds/edit/%feeds/map'] = array(
'title' => t('Advanced'), 'title' => t('Mapping'),
'page callback' => 'drupal_get_form', 'page callback' => 'drupal_get_form',
'page arguments' => array('feeds_ui_build_advanced_form', 4), 'page arguments' => array('feeds_ui_build_mapping_form', 4),
'access arguments' => array('administer feeds'), 'access arguments' => array('administer feeds'),
'file' => 'feeds_ui.admin.inc', 'file' => 'feeds_ui.admin.inc',
'type' => MENU_LOCAL_TASK, 'type' => MENU_LOCAL_TASK,
'weight' => 10, 'weight' => 2,
); );
return $items; return $items;
} }
......
...@@ -32,6 +32,21 @@ class Feed extends FeedsConfigurable { ...@@ -32,6 +32,21 @@ class Feed extends FeedsConfigurable {
} }
} }
/**
* Return defaults for feed configuration.
*/
public function getDefaultConfig() {
return array(
'fetcher' => 'FeedsHttpFetcher',
'parser' => 'FeedsSyndicationParser',
'processors' => array('FeedsNodeProcessor'),
'content_type' => '',
'source' => array(),
'update' => 0,
'refresh_period' => FEEDAPI_CRON_NEVER_REFRESH,
);
}
/** /**
* Import feed by using configured fetchers, parsers, processors. * Import feed by using configured fetchers, parsers, processors.
*/ */
...@@ -146,7 +161,14 @@ class FeedsConfigurable { ...@@ -146,7 +161,14 @@ class FeedsConfigurable {
} }
public function setConfig($config) { public function setConfig($config) {
$this->config = $config; $default_keys = $this->getDefaultConfig();
$this->config = array_intersect_key($config, $default_keys);
}
public function addConfig($config) {
$this->config = array_merge($this->config, $config);
$default_keys = $this->getDefaultConfig();
$this->config = array_intersect_key($this->config, $default_keys);
} }
public function getDefaultConfig() { public function getDefaultConfig() {
......
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