You are here

public function YieldToArgumentTrait::buildExposedForm in Lightning Core 8

Same name and namespace in other branches
  1. 8.5 src/YieldToArgumentTrait.php \Drupal\lightning_core\YieldToArgumentTrait::buildExposedForm()
  2. 8.2 src/YieldToArgumentTrait.php \Drupal\lightning_core\YieldToArgumentTrait::buildExposedForm()
  3. 8.3 src/YieldToArgumentTrait.php \Drupal\lightning_core\YieldToArgumentTrait::buildExposedForm()
  4. 8.4 src/YieldToArgumentTrait.php \Drupal\lightning_core\YieldToArgumentTrait::buildExposedForm()

File

src/YieldToArgumentTrait.php, line 15

Class

YieldToArgumentTrait
Allows exposed an Views filter to disappear if an argument is present.

Namespace

Drupal\lightning_core

Code

public function buildExposedForm(&$form, FormStateInterface $form_state) {
  parent::buildExposedForm($form, $form_state);
  if (empty($this->options['exposed'])) {
    return;
  }
  if (empty($this->options['expose']['argument'])) {
    return;
  }
  $argument = $this->options['expose']['argument'];
  $argument = $this->view->argument[$argument];

  /** @var \Drupal\views\Plugin\views\argument\ArgumentPluginBase $argument */
  $value = $argument
    ->getValue();
  $key = $this->options['expose']['identifier'];
  $form[$key]['#access'] = is_null($value) || $argument
    ->isException($value);
}