function rules_ui_add_element_submit

Add element submit callback.

Used for "abstract plugins" to create the initial element object with the given implementation name and rebuild the form.

File

ui/ui.forms.inc, line 317

Code

function rules_ui_add_element_submit($form, &$form_state) {
    $element = rules_plugin_factory($form_state['plugin'], $form_state['values']['element_name']);
    // Always add the new element at the bottom, thus set an appropriate weight.
    $iterator = $form_state['parent_element']->getIterator();
    $iterator_array = iterator_to_array($iterator, TRUE);
    if ($sibling = end($iterator_array)) {
        $element->weight = $sibling->weight + 1;
    }
    // Clear the element settings so they won't be processed on serialization as
    // there is nothing to be processed yet.
    $element->settings = array();
    $element->setParent($form_state['parent_element']);
    $form_state['rules_element'] = $element;
    $form_state['rebuild'] = TRUE;
}