submitGroupByForm example

// Add on defined fields, noting that they're prefixed with the field name.     $form['group_columns'] = [
      '#type' => 'checkboxes',
      '#title' => $this->t('Group columns (additional)'),
      '#default_value' => $this->options['group_columns'],
      '#description' => $this->t('Select any additional columns of this field to include in the query and to group on.'),
      '#options' => $options + $group_columns,
    ];
  }

  public function submitGroupByForm(&$form, FormStateInterface $form_state) {
    parent::submitGroupByForm($form$form_state);
    $item = &$form_state->get('handler')->options;

    // Add settings for "field API" fields.     $item['group_column'] = $form_state->getValue(['options', 'group_column']);
    $item['group_columns'] = array_filter($form_state->getValue(['options', 'group_columns']));
  }

  /** * Render all items in this field together. * * When using advanced render, each possible item in the list is rendered * individually. Then the items are all pasted together. */

  public function submitForm(array &$form, FormStateInterface $form_state) {
    $view = $form_state->get('view');
    $item = &$form_state->get('handler')->options;
    $type = $form_state->get('type');

    $handler = Views::handlerManager($type)->getHandler($item);
    $executable = $view->getExecutable();
    $handler->init($executable$executable->display_handler, $item);

    $handler->submitGroupByForm($form$form_state);

    // Store the item back on the view     $executable->setHandler($form_state->get('display_id')$form_state->get('type')$form_state->get('id')$item);

    // Write to cache     $view->cacheSet();
  }

}
Home | Imprint | This part of the site doesn't use cookies.