defaultExposeOptions example

if (empty($this->valueOptions)) {
      $this->getValueOptions();
    }
    // Now that we have the valid options for this filter, just return the     // human-readable label based on the current value. The valueOptions     // array is keyed with either 0 or 1, so if the current value is not     // empty, use the label for 1, and if it's empty, use the label for 0.     return $this->operator . ' ' . $this->valueOptions[!empty($this->value)];
  }

  public function defaultExposeOptions() {
    parent::defaultExposeOptions();
    $this->options['expose']['operator_id'] = '';
    $this->options['expose']['label'] = $this->value_value;
    $this->options['expose']['required'] = TRUE;
  }

  /** * {@inheritdoc} */
  public function query() {
    $this->ensureMyTable();
    $field = "$this->tableAlias.$this->realField";

    
/** * Displays the Expose form. */
  public function displayExposedForm($form, FormStateInterface $form_state) {
    $item = &$this->options;
    // flip     $item['exposed'] = empty($item['exposed']);

    // If necessary, set new defaults:     if ($item['exposed']) {
      $this->defaultExposeOptions();
    }

    $view = $form_state->get('view');
    $display_id = $form_state->get('display_id');
    $type = $form_state->get('type');
    $id = $form_state->get('id');
    $view->getExecutable()->setHandler($display_id$type$id$item);

    $view->addFormToStack($form_state->get('form_key')$display_id$type$id, TRUE, TRUE);

    $view->cacheSet();
    
$options['expose']['contains']['placeholder'] = ['default' => ''];
    $options['expose']['contains']['min_placeholder'] = ['default' => ''];
    $options['expose']['contains']['max_placeholder'] = ['default' => ''];

    return $options;
  }

  /** * {@inheritdoc} */
  public function defaultExposeOptions() {
    parent::defaultExposeOptions();
    $this->options['expose']['min_placeholder'] = NULL;
    $this->options['expose']['max_placeholder'] = NULL;
    $this->options['expose']['placeholder'] = NULL;
  }

  /** * {@inheritdoc} */
  public function buildExposeForm(&$form, FormStateInterface $form_state) {
    parent::buildExposeForm($form$form_state);

    
$options['expose']['contains']['required'] = ['default' => FALSE];
    $options['expose']['contains']['placeholder'] = ['default' => ''];

    return $options;
  }

  /** * {@inheritdoc} */
  public function defaultExposeOptions() {
    parent::defaultExposeOptions();
    $this->options['expose']['placeholder'] = NULL;
  }

  /** * {@inheritdoc} */
  public function buildExposeForm(&$form, FormStateInterface $form_state) {
    parent::buildExposeForm($form$form_state);
    $form['expose']['placeholder'] = [
      '#type' => 'textfield',
      '#default_value' => $this->options['expose']['placeholder'],
      
$this->valueOptions = call_user_func($this->definition['options callback']);
      }
    }
    else {
      $this->valueOptions = [$this->t('Yes')$this->t('No')];
    }

    return $this->valueOptions;
  }

  public function defaultExposeOptions() {
    parent::defaultExposeOptions();
    $this->options['expose']['reduce'] = FALSE;
  }

  public function buildExposeForm(&$form, FormStateInterface $form_state) {
    parent::buildExposeForm($form$form_state);
    $form['expose']['reduce'] = [
      '#type' => 'checkbox',
      '#title' => $this->t('Limit list to selected items'),
      '#description' => $this->t('If checked, the only items presented to the user will be the ones selected here.'),
      // Safety.       '#default_value' => !empty($this->options['expose']['reduce']),
    ];
Home | Imprint | This part of the site doesn't use cookies.