clickSortable example

public function buildOptionsForm(&$form, FormStateInterface $form_state) {
    parent::buildOptionsForm($form$form_state);
    $this->view->initStyle();

    // Allow to choose all fields as possible     if ($this->view->style_plugin->usesFields()) {
      $options = [];
      foreach ($this->view->display_handler->getHandlers('field') as $name => $field) {
        // Only allow clickSortable fields. Fields without clickSorting will         // probably break in the Combine filter.         if ($field->clickSortable()) {
          $options[$name] = $field->adminLabel(TRUE);
        }
      }
      if ($options) {
        $form['fields'] = [
          '#type' => 'select',
          '#title' => $this->t('Choose fields to combine for filtering'),
          '#description' => $this->t("This filter doesn't work for very special field handlers."),
          '#multiple' => TRUE,
          '#options' => $options,
          '#default_value' => $this->options['fields'],
        ];
/** * Tests whether the filters are click sortable as expected. */
  public function testClickSortable() {
    // Test that clickSortable is TRUE by default.     $item = [
      'table' => 'views_test_data',
      'field' => 'name',
    ];
    $plugin = $this->container->get('plugin.manager.views.field')->getHandler($item);
    $this->assertTrue($plugin->clickSortable(), 'TRUE as a default value is correct.');

    // Test that clickSortable is TRUE by when set TRUE in the data.     $item['field'] = 'id';
    $plugin = $this->container->get('plugin.manager.views.field')->getHandler($item);
    $this->assertTrue($plugin->clickSortable(), 'TRUE as a views data value is correct.');

    // Test that clickSortable is FALSE by when set FALSE in the data.     $item['field'] = 'job';
    $plugin = $this->container->get('plugin.manager.views.field')->getHandler($item);
    $this->assertFalse($plugin->clickSortable(), 'FALSE as a views data value is correct.');
  }

  
foreach ($columns as $field => $column) {
      $column_selector = ':input[name="style_options[columns][' . $field . ']"]';

      $form['columns'][$field] = [
        '#title' => $this->t('Columns for @field', ['@field' => $field]),
        '#title_display' => 'invisible',
        '#type' => 'select',
        '#options' => $field_names,
        '#default_value' => $column,
      ];
      if ($handlers[$field]->clickSortable()) {
        $form['info'][$field]['sortable'] = [
          '#title' => $this->t('Sortable for @field', ['@field' => $field]),
          '#title_display' => 'invisible',
          '#type' => 'checkbox',
          '#default_value' => !empty($this->options['info'][$field]['sortable']),
          '#states' => [
            'visible' => [
              $column_selector => ['value' => $field],
            ],
          ],
        ];
        
Home | Imprint | This part of the site doesn't use cookies.