setHandlerOption example

$view = Views::getView('test_group_rows');

    // Test grouped rows.     $this->executeView($view);
    $output = $renderer->executeInRenderContext(new RenderContext()function D) use ($view) {
      return $view->field['field_group_rows']->advancedRender($view->result[0]);
    });
    $this->assertEquals('a, b, c', $output);

    // Change the group_rows checkbox to false.     $view = Views::getView('test_group_rows');
    $view->setHandlerOption('default', 'field', 'field_group_rows', 'group_rows', FALSE);

    // Test ungrouped rows.     $this->executeView($view);
    $view->render();

    $view->row_index = 0;
    $output = $renderer->executeInRenderContext(new RenderContext()function D) use ($view) {
      return $view->field['field_group_rows']->advancedRender($view->result[0]);
    });
    $this->assertEquals('a', $output);
    $view->row_index = 1;
    
          // it to none.           $base_fields = Views::viewsDataHelper()->fetchFields($view->get('base_table')$type$executable->display_handler->useGroupBy());
          if (isset($base_fields[$item['table'] . '.' . $item['field']])) {
            $relationship_options = array_merge(['none' => $this->t('Do not use a relationship')]$relationship_options);
          }
          $rel = empty($item['relationship']) ? 'none' : $item['relationship'];
          if (empty($relationship_options[$rel])) {
            // Pick the first relationship.             $rel = key($relationship_options);
            // We want this relationship option to get saved even if the user             // skips submitting the form.             $executable->setHandlerOption($display_id$type$id, 'relationship', $rel);
            $save_ui_cache = TRUE;
            // Re-initialize with new relationship.             $item['relationship'] = $rel;
            $handler->init($executable$executable->display_handler, $item);
          }

          $form['options']['relationship'] = [
            '#type' => 'select',
            '#title' => $this->t('Relationship'),
            '#options' => $relationship_options,
            '#default_value' => $rel,
            

    $tid = $view->result[0]->_entity->id();
    $vocabulary = Vocabulary::load($this->terms[$tid]->bundle());
    $expected = $vocabulary->get('name');

    $this->assertEquals($expected$actual, 'Displayed vocabulary name should match that loaded from the term.');
    $this->assertEquals('aaa', $vocabulary->id(), 'First result should be vocabulary "aaa", due to ASC sorting.');

    // Reverse sorting.
    $view = Views::getView('test_taxonomy_vid_field');
    $view->setHandlerOption('default', 'sort', 'vid', 'order', 'DESC');
    $this->executeView($view);

    $actual = $renderer->executeInRenderContext(new RenderContext()function D) use ($view) {
      return $view->field['vid']->advancedRender($view->result[0]);
    });
    $tid = $view->result[0]->_entity->id();
    $vocabulary = Vocabulary::load($this->terms[$tid]->bundle());
    $expected = $vocabulary->get('name');

    $this->assertEquals($expected$actual, 'Displayed vocabulary name should match that loaded from the term.');
    $this->assertEquals('bbb', $vocabulary->id(), 'First result should be vocabulary "bbb", due to DESC sorting.');
  }
Home | Imprint | This part of the site doesn't use cookies.