class ConfigItemGroup

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

Hierarchy

Expanded class hierarchy of ConfigItemGroup

File

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

Namespace

Drupal\views_ui\Form\Ajax
View source
class ConfigItemGroup extends ViewsFormBase {

  /**
   * Constucts a new ConfigItemGroup object.
   */
  public function __construct($type = NULL, $id = NULL) {
    $this
      ->setType($type);
    $this
      ->setID($id);
  }

  /**
   * Implements \Drupal\views_ui\Form\Ajax\ViewsFormInterface::getFormKey().
   */
  public function getFormKey() {
    return 'config-item-group';
  }

  /**
   * Overrides \Drupal\views_ui\Form\Ajax\ViewsFormBase::getForm().
   */
  public function getForm(ViewStorageInterface $view, $display_id, $js, $type = NULL, $id = NULL) {
    $this
      ->setType($type);
    $this
      ->setID($id);
    return parent::getForm($view, $display_id, $js);
  }

  /**
   * Implements \Drupal\Core\Form\FormInterface::getFormID().
   */
  public function getFormID() {
    return 'views_ui_config_item_group_form';
  }

  /**
   * Implements \Drupal\Core\Form\FormInterface::buildForm().
   */
  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;
  }

  /**
   * Overrides \Drupal\views_ui\Form\Ajax\ViewsFormBase::submitForm().
   */
  public function submitForm(array &$form, array &$form_state) {
    $item =& $form_state['handler']->options;
    $type = $form_state['type'];
    $id = $form_state['id'];
    $handler = views_get_handler($item, $type);
    $executable = $form_state['view']
      ->get('executable');
    $handler
      ->init($executable, $executable->display_handler, $item);
    $handler
      ->submitGroupByForm($form, $form_state);

    // Store the item back on the view
    $executable
      ->setItem($form_state['display_id'], $form_state['type'], $form_state['id'], $item);

    // Write to cache
    $form_state['view']
      ->cacheSet();
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ConfigItemGroup::buildForm public function Implements \Drupal\Core\Form\FormInterface::buildForm(). Overrides FormInterface::buildForm
ConfigItemGroup::getForm public function Overrides \Drupal\views_ui\Form\Ajax\ViewsFormBase::getForm(). Overrides ViewsFormBase::getForm
ConfigItemGroup::getFormID public function Implements \Drupal\Core\Form\FormInterface::getFormID(). Overrides FormInterface::getFormID
ConfigItemGroup::getFormKey public function Implements \Drupal\views_ui\Form\Ajax\ViewsFormInterface::getFormKey(). Overrides ViewsFormInterface::getFormKey
ConfigItemGroup::submitForm public function Overrides \Drupal\views_ui\Form\Ajax\ViewsFormBase::submitForm(). Overrides ViewsFormBase::submitForm
ConfigItemGroup::__construct public function Constucts a new ConfigItemGroup object.
ViewsFormBase::$id protected property The ID of the item this form is manipulating.
ViewsFormBase::$type protected property The type of item this form is manipulating.
ViewsFormBase::getFormState public function Implements \Drupal\views_ui\Form\Ajax\ViewsFormInterface::getFormState(). Overrides ViewsFormInterface::getFormState 1
ViewsFormBase::setID protected function Sets the ID for this form.
ViewsFormBase::setType protected function Sets the type for this form.
ViewsFormBase::validateForm public function Implements \Drupal\Core\Form\FormInterface::validateForm(). Overrides FormInterface::validateForm 3