function rules_upgrade_convert_element

Convert a single element.

Parameters

array $element: The element to convert.

RulesPlugin $target: The converted element to write to.

2 calls to rules_upgrade_convert_element()
rules_upgrade_convert_rule in includes/rules.upgrade.inc
Converts a single reaction rule.
rules_upgrade_convert_rule_set in includes/rules.upgrade.inc
Converts a single rule set, including all of its rules.

File

includes/rules.upgrade.inc, line 231

Code

function rules_upgrade_convert_element(array $element, RulesPlugin $target) {
    foreach (array(
        'active',
        'label',
        'weight',
    ) as $key) {
        if (isset($element['#' . $key])) {
            $target->{$key} = $element['#' . $key];
        }
    }
    // Go through the parameters and take over its configuration if possible.
    foreach ($target->pluginParameterInfo() as $name => $info) {
        rules_upgrade_element_parameter_settings($element, $target, $name);
    }
    // @todo Care about php input evaluator for non-text parameters.
    // Take care of variable names and labels.
    foreach ($target->pluginProvidesVariables() as $name => $info) {
        rules_upgrade_element_variable_settings($element, $target, $name);
    }
    if ($target instanceof RulesConditionInterface && !empty($element['#negate'])) {
        $target->negate(TRUE);
    }
    if ($target instanceof RulesReactionRule) {
        // Cut of the 'event_' prefix.
        $target->event(substr($element['#set'], 6));
    }
    if ($element['#type'] == 'rule') {
        if (!empty($element['#conditions'])) {
            foreach (element_children($element['#conditions']) as $key) {
                $child = rules_upgrade_plugin_factory($element['#conditions'][$key]);
                rules_upgrade_convert_element($element['#conditions'][$key], $child);
                $target->condition($child);
            }
        }
        if (!empty($element['#actions'])) {
            foreach (element_children($element['#actions']) as $key) {
                $child = rules_upgrade_plugin_factory($element['#actions'][$key]);
                rules_upgrade_convert_element($element['#actions'][$key], $child);
                $target->action($child);
            }
        }
    }
    // Invoke action/condition specific hooks and a general one.
    if ($element['#type'] == 'action' || $element['#type'] == 'condition') {
        if (function_exists($function = $element['#name'] . '_upgrade')) {
            $element_name = $function($element, $target);
        }
        elseif (isset($element['#info']['base']) && function_exists($function = $element['#info']['base'] . '_upgrade')) {
            $element_name = $function($element, $target);
        }
    }
    drupal_alter('rules_element_upgrade', $element, $target);
    // Recurse down, if necessary.
    foreach (element_children($element) as $key) {
        $child = rules_upgrade_plugin_factory($element[$key]);
        rules_upgrade_convert_element($element[$key], $child);
        $child->setParent($target);
    }
    if ($target instanceof RulesContainerPlugin) {
        $target->sortChildren();
    }
}