1 layout.admin.inc layout_condition_return_form($form, &$form_state)

Helper function to return a partial condition settings form.

This can be used to add a condition to either a layout, block, or menu item, based on the values in the $form_state parameter.

File

core/modules/layout/layout.admin.inc, line 2197
Admin page callbacks for the Layout module.

Code

function layout_condition_return_form($form, &$form_state) {
  /* @var Layout $layout */
  $layout = $form_state['layout'];
  /* @var Block $block */
  $block = $form_state['block'];
  /* @var LayoutMenuItem $menu_item */
  $menu_item = $form_state['menu_item'];
  $condition_id = $form_state['condition_id'];

  // If no condition has yet been selected, there is no sub-form to display.
  if (!isset($form_state['values']['condition'])) {
    return array();
  }
  else {
    $handler_id = $form_state['values']['condition'];
  }

  if (isset($condition_id)) {
    if ($menu_item) {
      $handler = &$menu_item->conditions[$condition_id];
    }
    elseif ($block) {
      $handler = &$block->conditions[$condition_id];
    }
    else {
      $handler = &$layout->conditions[$condition_id];
    }

    // Update the condition in the same place if the type of condition has
    // changed entirely (note the $handler is assigned by reference above).
    if (!is_numeric($handler_id) && $condition_id != $handler_id) {
      $handler = layout_create_access($handler_id);
    }
  }
  else {
    $handler = layout_create_access($handler_id);
    $handler->is_new = TRUE;
  }

  $form['#title'] = layout_condition_edit_title($layout, $block, $menu_item, $handler_id);
  $form_state['layout'] = $layout;
  $form_state['block'] = $block;
  $form_state['menu_item'] = $menu_item;
  $form_state['handler'] = $handler;
  $handler->form($form, $form_state);

  return $form;
}