getValueOptions example

'#title' => $this->t('Output machine name'),
      '#description' => $this->t('Display field as machine name.'),
      '#type' => 'checkbox',
      '#default_value' => !empty($this->options['machine_name']),
    ];
  }

  /** * {@inheritdoc} */
  public function preRender(&$values) {
    $this->getValueOptions();
  }

  /** * {@inheritdoc} */
  public function render(ResultRow $values) {
    $value = $values->{$this->field_alias};
    if (!empty($this->options['machine_name']) || !isset($this->valueOptions[$value])) {
      $result = $this->sanitizeValue($value);
    }
    else {
      
$this->executeView($view);

    // Test we have all the results, with all types selected.     $this->assertCount($entities['count']$view->result);

    // Test the valueOptions of the filter handler.     $expected = [];
    foreach ($bundle_info as $key => $info) {
      $expected[$key] = $info['label'];
    }
    $this->assertSame($expected$view->filter['type']->getValueOptions());

    $view->destroy();

    // Test each bundle type.     foreach ($bundle_info as $key => $info) {
      // Test each bundle type.       $view->initDisplay();
      $filters = $view->display_handler->getOption('filters');
      $filters['type']['value'] = [$key => $key];
      $view->display_handler->setOption('filters', $filters);
      $this->executeView($view);

      

  protected function assertPluginStates(array $states): void {
    $plugin = Views::pluginManager('filter')->createInstance('moderation_state_filter', []);
    $view = Views::getView('test_content_moderation_state_filter_base_table');
    $plugin->init($view$view->getDisplay());
    $this->assertEquals($states$plugin->getValueOptions());
  }

  /** * Assert the nodes appear when the test view is executed. * * @param \Drupal\node\NodeInterface[] $nodes * Nodes to assert are in the views result. * @param array $filters * An array of filters to apply to the view. * @param string $view_id * The view to execute for the results. * * @internal */
protected function defineOptions() {
    $options = parent::defineOptions();

    $options['value']['default'] = FALSE;

    return $options;
  }

  protected function valueForm(&$form, FormStateInterface $form_state) {
    if (empty($this->valueOptions)) {
      // Initialize the array of possible values for this filter.       $this->getValueOptions();
    }
    if ($exposed = $form_state->get('exposed')) {
      // Exposed filter: use a select box to save space.       $filter_form_type = 'select';
    }
    else {
      // Configuring a filter: use radios for clarity.       $filter_form_type = 'radios';
    }
    $form['value'] = [
      '#type' => $filter_form_type,
      

      $this->assertIdenticalResultset($view$expected['views_test_data_name' => 'name']);

      $expected = [
        '***LANGUAGE_site_default***',
        '***LANGUAGE_language_interface***',
        'en',
        'xx-lolspeak',
        'und',
        'zxx',
      ];
      $this->assertSame($expectedarray_keys($view->filter['langcode']->getValueOptions()));

      $view->destroy();
    }
  }

}
$this->executeView($view);
    $this->assertCount(1, $view->result);
    $expected = [];
    $expected[] = ['uid' => 4];
    $this->assertIdenticalResultset($view$expected$column_map);
    $view->destroy();

    $view->initDisplay();
    $view->initHandlers();

    // Test the value options.     $value_options = $view->filter['permission']->getValueOptions();

    $permission_by_module = [];
    $permissions = \Drupal::service('user.permissions')->getPermissions();
    foreach ($permissions as $name => $permission) {
      $permission_by_module[$permission['provider']][$name] = $permission;
    }
    foreach (['system' => 'System', 'user' => 'User'] as $module => $title) {
      $expected = array_map(function D$permission) {
        return Html::escape(strip_tags($permission['title']));
      }$permission_by_module[$module]);

      
protected function valueForm(&$form, FormStateInterface $form_state) {
    $form['value'] = [];
    $options = [];

    $exposed = $form_state->get('exposed');
    if (!$exposed) {
      // Add a select all option to the value form.       $options = ['all' => $this->t('Select all')];
    }

    $this->getValueOptions();
    $options += $this->valueOptions;
    $default_value = (array) $this->value;

    $which = 'all';
    if (!empty($form['operator'])) {
      $source = ':input[name="options[operator]"]';
    }
    if ($exposed) {
      $identifier = $this->options['expose']['identifier'];

      if (empty($this->options['expose']['use_operator']) || empty($this->options['expose']['operator_id'])) {
        

  public function testUserNameApi() {
    $view = Views::getView('test_user_name');

    $view->initHandlers();
    $view->filter['uid']->value = [$this->accounts[0]->id()];

    $this->executeView($view);
    $this->assertIdenticalResultset($view[['uid' => $this->accounts[0]->id()]]$this->columnMap);

    $this->assertNull($view->filter['uid']->getValueOptions());
  }

  /** * Tests using the user interface. */
  public function testAdminUserInterface() {
    $admin_user = $this->drupalCreateUser([
      'administer views',
      'administer site configuration',
    ]);
    $this->drupalLogin($admin_user);

    
'test_user_role' => 'test_user_role',
      ],
      'operator' => 'not empty',
      'plugin_id' => 'user_roles',
    ];
    $view->save();
    $this->assertEquals($expected$view->getDependencies());

    $view = Views::getView('test_user_name');
    $view->initDisplay();
    $view->initHandlers();
    $this->assertEquals(['test_user_role']array_keys($view->filter['roles_target_id']->getValueOptions()));

    $view = View::load('test_user_name');
    $display = &$view->getDisplay('default');
    $display['display_options']['filters']['roles_target_id'] = [
      'id' => 'roles_target_id',
      'table' => 'user__roles',
      'field' => 'roles_target_id',
      'value' => [],
      'plugin_id' => 'user_roles',
    ];
    $view->save();
    
Home | Imprint | This part of the site doesn't use cookies.