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 = array(); 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'] = array( '#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'], ); } else { $form_state->setErrorByName('', $this->t('You have to add some fields to be able to use this filter.')); } } }
/** * Build the options form. */ public function buildOptionsForm(&$form, FormStateInterface $form_state) { parent::buildOptionsForm($form, $form_state); if ($this->canExpose() && !empty($form['expose'])) { $field_options_all = $this->view->display_handler->getFieldLabels(); // Limit options to fields with the same name. foreach ($this->view->display_handler->getHandlers('field') as $id => $handler) { if ($handler->realField == $this->realField) { $field_options[$id] = $field_options_all[$id]; } } if (empty($field_options)) { $field_options[''] = $this->t('Add some fields to view'); } elseif (empty($this->options['expose']['autocomplete_field']) && !empty($field_options[$this->options['id']])) { $this->options['expose']['autocomplete_field'] = $this->options['id']; } // Build form elements for the right side of the exposed filter form $states = array('visible' => array(' :input[name="options[expose][autocomplete_filter]"]' => array('checked' => TRUE))); $form['expose'] += array('autocomplete_filter' => array('#type' => 'checkbox', '#title' => $this->t('Use Autocomplete'), '#default_value' => $this->options['expose']['autocomplete_filter'], '#description' => $this->t('Use Autocomplete for this filter.')), 'autocomplete_items' => array('#type' => 'textfield', '#title' => $this->t('Maximum number of items in Autocomplete'), '#default_value' => $this->options['expose']['autocomplete_items'], '#description' => $this->t('Enter 0 for no limit.'), '#states' => $states), 'autocomplete_min_chars' => array('#type' => 'textfield', '#title' => t('Minimum number of characters to start filter'), '#default_value' => $this->options['expose']['autocomplete_min_chars'], '#element_validate' => array('element_validate_integer'), '#states' => $states), 'autocomplete_dependent' => array('#type' => 'checkbox', '#title' => $this->t('Suggestions depend on other filter fields'), '#default_value' => $this->options['expose']['autocomplete_dependent'], '#description' => $this->t('Autocomplete suggestions will be filtered by other filter fields'), '#states' => $states), 'autocomplete_field' => array('#type' => 'select', '#title' => $this->t('Field with autocomplete results'), '#default_value' => $this->options['expose']['autocomplete_field'], '#options' => $field_options, '#description' => $this->t('Selected field will be used for dropdown results of autocomplete. In most cases it should be the same field you use for filter.'), '#states' => $states), 'autocomplete_raw_dropdown' => array('#type' => 'checkbox', '#title' => $this->t('Unformatted dropdown'), '#default_value' => $this->options['expose']['autocomplete_raw_dropdown'], '#description' => $this->t('Use unformatted data from database for dropdown list instead of field formatter result. Value will be printed as plain text.'), '#states' => $states), 'autocomplete_raw_suggestion' => array('#type' => 'checkbox', '#title' => $this->t('Unformatted suggestion'), '#default_value' => $this->options['expose']['autocomplete_raw_suggestion'], '#description' => $this->t('The same as above, but for suggestion (text appearing inside textfield when item is selected).'), '#states' => $states)); } }
/** * {@inheritdoc} */ public function buildOptionsForm(&$form, FormStateInterface $form_state) { parent::buildOptionsForm($form, $form_state); $form['expose']['hide_no_continuous'] = ['#type' => 'checkbox', '#title' => t('Hide this filter if there are no continuous jobs.'), '#default_value' => $this->options['expose']['hide_no_continuous']]; }