You are here

function views_ui_add_section in Views (for Drupal 7) 5

Add one of the list sections to the form.

1 call to views_ui_add_section()
views_edit_view in ./views_ui.module
Display all the guts of a view in a form for editing.

File

./views_ui.module, line 1237

Code

function views_ui_add_section(&$form, &$view, $section) {

  // add fields to the form.
  $form += array(
    '#tree' => true,
    '#parents' => array(
      $section,
    ),
  );
  $view_section =& $view->{$section};
  $num_items = count($view_section);

  // Populate the form with fields we need to check to track
  // changes through the form's life.
  $form['count'] = array(
    '#type' => 'hidden',
    '#default_value' => $num_items,
  );
  $form['order'] = array(
    '#type' => 'hidden',
    '#default_value' => $num_items ? implode(',', range(0, $num_items - 1)) : '',
  );

  // Run the builder to get the value on the form.
  views_ui_build_form($form);
  $order = $form['order']['#value'] != '' ? explode(',', $form['order']['#value']) : array();

  // Shortcut because operator precedence gets sticky if using $foo->$bar[]
  for ($i = $num_items; $i < $form['count']['#value']; $i++) {
    $view_section[] = array();
  }
  $new_section = "new_{$section}";

  // instantiate the new field if one was added.
  if ($view->{$new_section}) {
    $view_section[] = $view->{$new_section};
    $order[] = $form['count']['#value'];
    $form['count']['#value']++;
  }
  $func = "views_ui_add_{$section}";
  if ($order) {
    foreach ($order as $key => $i) {
      $form[$i] = array(
        '#tree' => true,
        '#parents' => array(
          $section,
          $i,
        ),
      );
      $form[$i]['id'] = array(
        '#type' => 'hidden',
        '#default_value' => $view_section[$i]['id'],
      );
      views_ui_add_buttons($form[$i]);
      views_ui_build_form($form[$i]);
      $retval = _views_check_sub_ops($form[$i], $order, $key);
      if ($retval !== 'delete') {
        $retval2 = $func($form[$i], $view_section[$i], $order, $key, $i, $view);
      }
      if ($retval || $retval2) {
        $allbut = $section;
      }
    }
    $form['order']['#value'] = implode(',', $order);
  }
  return $allbut;
}