You are here

function _rules_import_transform_element in Rules 6

Transforms a single element to be compatible with workflow-ng

1 string reference to '_rules_import_transform_element'
rules_import_workflow_ng_rule in rules/rules.install
Transform a workflow-ng rule into a rule

File

rules/rules.install, line 230
Rules - Installation file.

Code

function _rules_import_transform_element(&$element) {
  if (!isset($element['#name'])) {

    // Just keep it.
  }
  else {
    if (function_exists($function = $element['#name'] . '_upgrade')) {
      $function($element);
    }
    else {
      if (function_exists($function = _rules_import_replace_module_name($element['#name']))) {
        $element['#name'] = $function;
      }
      else {
        drupal_set_message(t('No upgrade information for the element %name found. Aborting.', array(
          '%name' => $element['#name'],
        )), 'error');
        return FALSE;
      }
    }
  }

  // Upgrade to element to the new format
  rules_init_element_info($element);
  if (isset($element['#argument map'])) {
    $element['#settings']['#argument map'] = $element['#argument map'];
    unset($element['#argument map']);
  }
  unset($element['#id']);
  if (isset($element['#settings'])) {

    // Adapt the settings so that token integration stays working
    foreach ($element['#settings'] as $name => $data) {
      if (is_array($data) && ($pos = strpos($name, '_args'))) {
        $setting_name = substr($name, 0, $pos);
        $element['#settings']['#eval input']['token_rules_input_evaluator'][$setting_name] = $data;
        unset($element['#settings'][$name]);
      }
    }
  }
}