You are here

function views_rules_add_view_loop_submit in Views Rules 7

Provides a variant of rules_ui_add_element_submit() to create a view loop.

1 string reference to 'views_rules_add_view_loop_submit'
views_rules_add_view_loop in rules/views_rules.rules_admin.inc
Provides a variant of rules_ui_add_element() to present a view display selector for creating a view loop.

File

rules/views_rules.rules_admin.inc, line 80
Extensions to Rules UI.

Code

function views_rules_add_view_loop_submit($form, &$form_state) {
  if (!isset($form_state['rules_element'])) {
    $display = $form_state['values']['views_rules_display'];
    list($viewName, $displayName) = explode(':', $display, 2);
    $element = views_rules_loop($viewName, $displayName);

    // Always add the new element at the bottom, thus set an appropriate weight.
    $iterator = $form_state['parent_element']
      ->getIterator();
    if ($sibling = end($iterator)) {
      $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;
}