You are here

function webform_delete_empty_subconditionals in Webform 7.4

Helper. Delete any subconditionals which contain no rules.

Parameters

array $conditional: Conditional array containing the rules.

Return value

array Array of deleted subconditionals. Empty array if none were deleted.

2 calls to webform_delete_empty_subconditionals()
webform_component_delete in includes/webform.components.inc
Delete a Webform component.
webform_conditionals_form in includes/webform.conditionals.inc
Form builder; Provide the form for adding conditionals to a webform node.

File

includes/webform.conditionals.inc, line 835
Form elements and menu callbacks to provide conditional handling in Webform.

Code

function webform_delete_empty_subconditionals(array &$conditional) {
  $deleted = array();
  do {
    $empty_deleted = FALSE;
    $open_rid = NULL;
    foreach ($conditional['rules'] as $rid => $rule) {
      switch ($rule['source_type']) {
        case 'conditional_start':
          $open_rid = $rid;
          break;
        case 'conditional_end':
          if ($open_rid) {

            // A conditional_start rule was immediately followed by a
            // conditional_end rule. Delete them both. Repeat the check in case
            // the parent is now empty.
            $deleted[$open_rid] = $open_rid;
            $deleted[$rid] = $rid;
            unset($conditional['rules'][$open_rid], $conditional['rules'][$rid]);
            $open_rid = NULL;
            $empty_deleted = TRUE;
          }
          break;
        default:
          $open_rid = NULL;
      }
    }
  } while ($empty_deleted);
  return $deleted;
}