public function ConfigItemGroup::buildForm

Implements \Drupal\Core\Form\FormInterface::buildForm().

Overrides FormInterface::buildForm

File

drupal/core/modules/views_ui/lib/Drupal/views_ui/Form/Ajax/ConfigItemGroup.php, line 52
Contains \Drupal\views_ui\Form\Ajax\ConfigItemGroup.

Class

ConfigItemGroup
Provides a form for configuring grouping information for a Views UI item.

Namespace

Drupal\views_ui\Form\Ajax

Code

public function buildForm(array $form, array &$form_state) {
  $view =& $form_state['view'];
  $display_id = $form_state['display_id'];
  $type = $form_state['type'];
  $id = $form_state['id'];
  $form = array(
    'options' => array(
      '#tree' => TRUE,
      '#theme_wrappers' => array(
        'container',
      ),
      '#attributes' => array(
        'class' => array(
          'scroll',
        ),
      ),
    ),
  );
  $executable = $view
    ->get('executable');
  if (!$executable
    ->setDisplay($display_id)) {
    views_ajax_render(t('Invalid display id @display', array(
      '@display' => $display_id,
    )));
  }
  $executable
    ->initQuery();
  $item = $executable
    ->getItem($display_id, $type, $id);
  if ($item) {
    $handler = $executable->display_handler
      ->getHandler($type, $id);
    if (empty($handler)) {
      $form['markup'] = array(
        '#markup' => t("Error: handler for @table > @field doesn't exist!", array(
          '@table' => $item['table'],
          '@field' => $item['field'],
        )),
      );
    }
    else {
      $handler
        ->init($executable, $executable->display_handler, $item);
      $types = ViewExecutable::viewsHandlerTypes();
      $form['#title'] = t('Configure aggregation settings for @type %item', array(
        '@type' => $types[$type]['lstitle'],
        '%item' => $handler
          ->adminLabel(),
      ));
      $handler
        ->buildGroupByForm($form['options'], $form_state);
      $form_state['handler'] =& $handler;
    }
    $view
      ->getStandardButtons($form, $form_state, 'views_ui_config_item_group_form');
  }
  return $form;
}