function views_ui_rearrange_form

Form to rearrange items in the views UI.

1 string reference to 'views_ui_rearrange_form'
views_ui_ajax_forms in drupal/core/modules/views/views_ui/admin.inc
Returns information about subforms for editing the pieces of a view.

File

drupal/core/modules/views/views_ui/admin.inc, line 805
Provides the Views' administrative interface.

Code

function views_ui_rearrange_form($form, &$form_state) {
  $view =& $form_state['view'];
  $display_id = $form_state['display_id'];
  $type = $form_state['type'];
  $types = ViewExecutable::viewsHandlerTypes();
  $executable = $view
    ->get('executable');
  if (!$executable
    ->setDisplay($display_id)) {
    views_ajax_error(t('Invalid display id @display', array(
      '@display' => $display_id,
    )));
  }
  $display =& $executable->displayHandlers[$display_id];
  $form['#title'] = t('Rearrange @type', array(
    '@type' => $types[$type]['ltitle'],
  ));
  $form['#section'] = $display_id . 'rearrange-item';
  if ($display
    ->defaultableSections($types[$type]['plural'])) {
    $form_state['section'] = $types[$type]['plural'];
    views_ui_standard_display_dropdown($form, $form_state, $form_state['section']);
  }
  $count = 0;

  // Get relationship labels
  $relationships = array();
  foreach ($display
    ->getHandlers('relationship') as $id => $handler) {
    $relationships[$id] = $handler
      ->label();
  }

  // Filters can now be grouped so we do a little bit extra:
  $groups = array();
  $grouping = FALSE;
  if ($type == 'filter') {
    $group_info = $executable->display_handler
      ->getOption('filter_groups');
    if (!empty($group_info['groups']) && count($group_info['groups']) > 1) {
      $grouping = TRUE;
      $groups = array(
        0 => array(),
      );
    }
  }
  foreach ($display
    ->getOption($types[$type]['plural']) as $id => $field) {
    $form['fields'][$id] = array(
      '#tree' => TRUE,
    );
    $form['fields'][$id]['weight'] = array(
      '#type' => 'textfield',
      '#default_value' => ++$count,
    );
    $handler = $display
      ->getHandler($type, $id);
    if ($handler) {
      $name = $handler
        ->adminLabel() . ' ' . $handler
        ->adminSummary();
      if (!empty($field['relationship']) && !empty($relationships[$field['relationship']])) {
        $name = '(' . $relationships[$field['relationship']] . ') ' . $name;
      }
      $form['fields'][$id]['name'] = array(
        '#markup' => $name,
      );
    }
    else {
      $form['fields'][$id]['name'] = array(
        '#markup' => t('Broken field @id', array(
          '@id' => $id,
        )),
      );
    }
    $form['fields'][$id]['removed'] = array(
      '#type' => 'checkbox',
      '#id' => 'views-removed-' . $id,
      '#attributes' => array(
        'class' => array(
          'views-remove-checkbox',
        ),
      ),
      '#default_value' => 0,
    );
  }

  // Add javascript settings that will be added via $.extend for tabledragging
  $form['#js']['tableDrag']['arrange']['weight'][0] = array(
    'target' => 'weight',
    'source' => NULL,
    'relationship' => 'sibling',
    'action' => 'order',
    'hidden' => TRUE,
    'limit' => 0,
  );
  $name = NULL;
  if (isset($form_state['update_name'])) {
    $name = $form_state['update_name'];
  }
  $view
    ->getStandardButtons($form, $form_state, 'views_ui_rearrange_form');
  return $form;
}