You are here

function feeds_tamper_save_instance in Feeds Tamper 7

Same name and namespace in other branches
  1. 6 feeds_tamper.inc \feeds_tamper_save_instance()

Save a plugin instance.

Parameters

stdClass $instance: A plugin instance object.

Return value

mixed If the plugin save failed, returns FALSE. If it succeeded, returns SAVED_NEW or SAVED_UPDATED, depending on the operation performed.

Related topics

7 calls to feeds_tamper_save_instance()
FeedsTamperWebTestHelper::addTamperPlugin in tests/feeds_tamper.test
FeedsTamperWebTestHelper::disableTamperPlugin in tests/feeds_tamper.test
feeds_tamper_rectify_instances in ./feeds_tamper.inc
Removes plugin instances whos source was removed.
feeds_tamper_ui_add_plugin_form_submit in feeds_tamper_ui/feeds_tamper_ui.admin.inc
Add plugin form submit handler.
feeds_tamper_ui_edit_plugin_form_submit in feeds_tamper_ui/feeds_tamper_ui.admin.inc
Edit plugin form submit handler.

... See full list

File

./feeds_tamper.inc, line 75
Version agnostic parts of feeds_tamper.module.

Code

function feeds_tamper_save_instance($instance) {
  $instance->id = drupal_substr($instance->id, 0, 127);
  ctools_include('export');

  // It's a new instance, give it the heaviest weight.
  if (!isset($instance->weight)) {
    $conditions = array(
      'importer' => $instance->importer,
      'source' => $instance->source,
    );
    $all = ctools_export_load_object('feeds_tamper', 'conditions', $conditions);
    $weight = 0;
    foreach ($all as $i) {
      if ($i->weight >= $weight) {
        $weight = $i->weight + 1;
      }
    }
    $instance->weight = $weight;
  }
  $disabled = variable_get('default_feeds_tamper', array());
  $disabled[$instance->id] = !empty($instance->disabled) ? TRUE : FALSE;
  variable_set('default_feeds_tamper', $disabled);
  return ctools_export_crud_save('feeds_tamper', $instance);
}