You are here

function _feeds_form_helper in Feeds 7.2

Same name and namespace in other branches
  1. 8.2 feeds.module \_feeds_form_helper()

Helper for Feeds validate and submit callbacks.

@todo This is all terrible. Remove.

Parameters

array $form: The form.

array $form_state: The current state of the form.

string $action: The action to perform on the form, for example:

  • Validate;
  • Submit.
2 calls to _feeds_form_helper()
feeds_form_submit in includes/FeedsConfigurable.inc
Submit handler for feeds_form().
feeds_form_validate in includes/FeedsConfigurable.inc
Form validation handler for feeds_form().

File

includes/FeedsConfigurable.inc, line 406
FeedsConfigurable and helper functions.

Code

function _feeds_form_helper(array $form, array &$form_state, $action) {
  $method = $form['#feeds_form_method'] . $action;
  $class = get_class($form['#configurable']);
  $id = $form['#configurable']->id;

  // Re-initialize the configurable object. Using feeds_importer() and
  // feeds_plugin() will ensure that we're using the same instance. We can't
  // reuse the previous form instance because feeds_importer() is used to save.
  // This will re-initialize all of the plugins anyway, causing some tricky
  // saving issues in certain cases.
  // See http://drupal.org/node/1672880.
  if ($class == variable_get('feeds_importer_class', 'FeedsImporter')) {
    $form['#configurable'] = feeds_importer($id);
  }
  else {
    $importer = feeds_importer($id);
    $plugin_key = $importer->config[$form['#configurable']
      ->pluginType()]['plugin_key'];
    $form['#configurable'] = feeds_plugin($plugin_key, $id);
  }
  if (method_exists($form['#configurable'], $method)) {
    $form['#configurable']
      ->{$method}($form_state['values']);
  }
}