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

#849834 rbayliss, alex_b: Generalize feeds_config_form() to feeds_form().

parent dffca3e2
No related branches found
No related tags found
No related merge requests found
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
Feeds 6.x 1.0 XXXXXXXXXXXXXXXXXX Feeds 6.x 1.0 XXXXXXXXXXXXXXXXXX
-------------------------------- --------------------------------
- #849834 rbayliss, alex_b: Generalize feeds_config_form() to feeds_form().
- #907064 alex_b: Track imported terms. - #907064 alex_b: Track imported terms.
- #906720 alex_b: Introduce a hook_feeds_after_clear(). - #906720 alex_b: Introduce a hook_feeds_after_clear().
- #905820 tristan.oneil: Adjust delete message in FeedsDataProcessor to avoid - #905820 tristan.oneil: Adjust delete message in FeedsDataProcessor to avoid
......
...@@ -65,10 +65,10 @@ function feeds_perm() { ...@@ -65,10 +65,10 @@ function feeds_perm() {
*/ */
function feeds_forms() { function feeds_forms() {
$forms = array(); $forms = array();
$forms['FeedsImporter_feeds_config_form']['callback'] = 'feeds_config_form'; $forms['FeedsImporter_feeds_form']['callback'] = 'feeds_form';
$plugins = feeds_get_plugins(); $plugins = feeds_get_plugins();
foreach ($plugins as $plugin) { foreach ($plugins as $plugin) {
$forms[$plugin['handler']['class'] .'_feeds_config_form']['callback'] = 'feeds_config_form'; $forms[$plugin['handler']['class'] .'_feeds_form']['callback'] = 'feeds_form';
} }
return $forms; return $forms;
} }
......
...@@ -308,13 +308,13 @@ function feeds_ui_edit_page($importer, $active = 'help', $plugin_key = '') { ...@@ -308,13 +308,13 @@ function feeds_ui_edit_page($importer, $active = 'help', $plugin_key = '') {
ctools_include('dependent'); ctools_include('dependent');
if (empty($plugin_key)) { if (empty($plugin_key)) {
$active_container['title'] = t('Basic settings'); $active_container['title'] = t('Basic settings');
$active_container['body'] = feeds_get_config_form($importer); $active_container['body'] = feeds_get_form($importer, 'configForm');
} }
// feeds_plugin_instance() returns a correct result because feed has been // feeds_plugin_instance() returns a correct result because feed has been
// instantiated previously. // instantiated previously.
elseif (in_array($plugin_key, array_keys($plugins)) && $plugin = feeds_plugin_instance($plugin_key, $importer->id)) { elseif (in_array($plugin_key, array_keys($plugins)) && $plugin = feeds_plugin_instance($plugin_key, $importer->id)) {
$active_container['title'] = t('Settings for !plugin', array('!plugin' => $plugins[$plugin_key]['name'])); $active_container['title'] = t('Settings for !plugin', array('!plugin' => $plugins[$plugin_key]['name']));
$active_container['body'] = feeds_get_config_form($plugin); $active_container['body'] = feeds_get_form($plugin, 'configForm');
} }
break; break;
case 'mapping': case 'mapping':
...@@ -354,7 +354,7 @@ function feeds_ui_edit_page($importer, $active = 'help', $plugin_key = '') { ...@@ -354,7 +354,7 @@ function feeds_ui_edit_page($importer, $active = 'help', $plugin_key = '') {
// Fetcher. // Fetcher.
$fetcher = $plugins[$config['fetcher']['plugin_key']]; $fetcher = $plugins[$config['fetcher']['plugin_key']];
$actions = array(); $actions = array();
if (feeds_get_config_form($importer->fetcher)) { if (feeds_get_form($importer->fetcher, 'configForm')) {
$actions = array(l(t('Settings'), $path .'/settings/'. $config['fetcher']['plugin_key'])); $actions = array(l(t('Settings'), $path .'/settings/'. $config['fetcher']['plugin_key']));
} }
$info['title'] = t('Fetcher'); $info['title'] = t('Fetcher');
...@@ -371,7 +371,7 @@ function feeds_ui_edit_page($importer, $active = 'help', $plugin_key = '') { ...@@ -371,7 +371,7 @@ function feeds_ui_edit_page($importer, $active = 'help', $plugin_key = '') {
// Parser. // Parser.
$parser = $plugins[$config['parser']['plugin_key']]; $parser = $plugins[$config['parser']['plugin_key']];
$actions = array(); $actions = array();
if (feeds_get_config_form($importer->parser)) { if (feeds_get_form($importer->parser, 'configForm')) {
$actions = array(l(t('Settings'), $path .'/settings/'. $config['parser']['plugin_key'])); $actions = array(l(t('Settings'), $path .'/settings/'. $config['parser']['plugin_key']));
} }
$info['title'] = t('Parser'); $info['title'] = t('Parser');
...@@ -388,7 +388,7 @@ function feeds_ui_edit_page($importer, $active = 'help', $plugin_key = '') { ...@@ -388,7 +388,7 @@ function feeds_ui_edit_page($importer, $active = 'help', $plugin_key = '') {
// Processor. // Processor.
$processor = $plugins[$config['processor']['plugin_key']]; $processor = $plugins[$config['processor']['plugin_key']];
$actions = array(); $actions = array();
if (feeds_get_config_form($importer->processor)) { if (feeds_get_form($importer->processor, 'configForm')) {
$actions[] = l(t('Settings'), $path .'/settings/'. $config['processor']['plugin_key']); $actions[] = l(t('Settings'), $path .'/settings/'. $config['processor']['plugin_key']);
} }
$actions[] = l(t('Mapping'), $path .'/mapping'); $actions[] = l(t('Mapping'), $path .'/mapping');
......
...@@ -178,31 +178,43 @@ abstract class FeedsConfigurable { ...@@ -178,31 +178,43 @@ abstract class FeedsConfigurable {
*/ */
public function configFormValidate(&$values) { public function configFormValidate(&$values) {
} }
/**
* Submission handler for configForm().
*
* @param $values
*/
public function configFormSubmit(&$values) {
$this->addConfig($values);
$this->save();
drupal_set_message(t('Your changes have been saved.'));
feeds_cache_clear(FALSE);
}
} }
/** /**
* Config form wrapper. Use to render the configuration form of * Config form wrapper. Use to render the configuration form of
* a FeedsConfigurable object. * a FeedsConfigurable object.
* *
* @param * @param $configurable
* FeedsConfigurable object. * FeedsConfigurable object.
* @param * @param $form_method
* The parent object to perform the save on. * The form method that should be rendered.
* *
* @return * @return
* Rendered config form, if available. Empty string otherwise. * Rendered config form, if available. Empty string otherwise.
*/ */
function feeds_get_config_form($configurable) { function feeds_get_form($configurable, $form_method) {
$form_state = array(); $form_state = array();
if ($configurable->configForm($form_state)) { if (method_exists($configurable, $form_method)) {
return drupal_get_form(get_class($configurable) .'_feeds_config_form', $configurable); return drupal_get_form(get_class($configurable) .'_feeds_form', $configurable, $form_method);
} }
return ''; return '';
} }
/** /**
* Config form callback. Don't call directly, but use * Config form callback. Don't call directly, but use
* feeds_get_config_form($configurable) instead. * feeds_get_form($configurable, 'method') instead.
* *
* @param * @param
* FormAPI $form_state. * FormAPI $form_state.
...@@ -210,12 +222,15 @@ function feeds_get_config_form($configurable) { ...@@ -210,12 +222,15 @@ function feeds_get_config_form($configurable) {
* FeedsConfigurable object. * FeedsConfigurable object.
* @param * @param
* The object to perform the save() operation on. * The object to perform the save() operation on.
* @param $form_method
* The $form_method that should be rendered.
*/ */
function feeds_config_form(&$form_state, $configurable) { function feeds_form(&$form_state, $configurable, $form_method) {
$form = $configurable->configForm($form_state); $form = $configurable->$form_method($form_state);
$form['#configurable'] = $configurable; $form['#configurable'] = $configurable;
$form['#validate'] = array('feeds_config_form_validate'); $form['#feeds_form_method'] = $form_method;
$form['#submit'] = array('feeds_config_form_submit'); $form['#validate'] = array('feeds_form_validate');
$form['#submit'] = array('feeds_form_submit');
$form['submit'] = array( $form['submit'] = array(
'#type' => 'submit', '#type' => 'submit',
'#value' => t('Save'), '#value' => t('Save'),
...@@ -225,18 +240,21 @@ function feeds_config_form(&$form_state, $configurable) { ...@@ -225,18 +240,21 @@ function feeds_config_form(&$form_state, $configurable) {
} }
/** /**
* Validation handler for feeds_config_form(). * Validation handler for feeds_form().
*/ */
function feeds_config_form_validate($form, &$form_state) { function feeds_form_validate($form, &$form_state) {
$form['#configurable']->configFormValidate($form_state['values']); $validate_method = $form['#feeds_form_method'] .'Validate';
if (method_exists($form['#configurable'], $validate_method)) {
$form['#configurable']->$validate_method($form_state['values']);
}
} }
/** /**
* Submit handler for feeds_config_form(). * Submit handler for feeds_config_form().
*/ */
function feeds_config_form_submit($form, &$form_state) { function feeds_form_submit($form, &$form_state) {
$form['#configurable']->addConfig($form_state['values']); $submit_method = $form['#feeds_form_method'] .'Submit';
$form['#configurable']->save(); if (method_exists($form['#configurable'], $submit_method)) {
drupal_set_message(t('Your changes have been saved.')); $form['#configurable']->$submit_method($form_state['values']);
feeds_cache_clear(FALSE); }
} }
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