protected function defineOptions() { $options = parent::defineOptions(); $options['expose']['contains']['required'] = array('default' => FALSE); return $options; }
/** * Overrides Drupal\views\Plugin\views\filter\FilterPluginBase::query(). */ public function query() { // Call the parent if this option is enabled. if ($this->options['test_enable']) { parent::query(); } }
/** * {@inheritdoc} */ public function getCacheContexts() { $contexts = parent::getCacheContexts(); // Node access is potentially cacheable per user. $contexts[] = 'cache.context.user'; return $contexts; }
/** * Constructs a new LatestRevision. * * @param array $configuration * A configuration array containing information about the plugin instance. * @param string $plugin_id * The plugin_id for the plugin instance. * @param mixed $plugin_definition * The plugin implementation definition. * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager * Entity Type Manager Service. * @param \Drupal\views\Plugin\ViewsHandlerManager $join_handler * Views Handler Plugin Manager. * @param \Drupal\Core\Database\Connection $connection * Database Connection. */ public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entity_type_manager, ViewsHandlerManager $join_handler, Connection $connection) { parent::__construct($configuration, $plugin_id, $plugin_definition); $this->entityTypeManager = $entity_type_manager; $this->joinHandler = $join_handler; $this->connection = $connection; }
public function buildExposeForm(&$form, FormStateInterface $form_state) { parent::buildExposeForm($form, $form_state); // @todo There are better ways of excluding required and multiple (object flags) unset($form['expose']['required']); unset($form['expose']['multiple']); unset($form['expose']['remember']); }
/** * {@inheritdoc} */ public function getCacheContexts() { $contexts = parent::getCacheContexts(); $contexts[] = 'user.node_grants:view'; return $contexts; }
/** * {@inheritdoc} */ protected function defineOptions() { $options = parent::defineOptions(); $options['operator']['default'] = 'optional'; return $options; }
public function defaultExposeOptions() { parent::defaultExposeOptions(); $this->options['expose']['operator_id'] = ''; $this->options['expose']['label'] = $this->value_value; $this->options['expose']['required'] = TRUE; }
/** * Do some minor translation of the exposed input */ public function acceptExposedInput($input) { if (empty($this->options['exposed'])) { return TRUE; } // rewrite the input value so that it's in the correct format so that // the parent gets the right data. if (!empty($this->options['expose']['identifier'])) { $value =& $input[$this->options['expose']['identifier']]; if (!is_array($value)) { $value = array('value' => $value); } } $rc = parent::acceptExposedInput($input); if (empty($this->options['expose']['required'])) { // We have to do some of our own checking for non-required filters. $info = $this->operators(); if (!empty($info[$this->operator]['values'])) { switch ($info[$this->operator]['values']) { case 1: if ($value['value'] === '') { return FALSE; } break; case 2: if ($value['min'] === '' && $value['max'] === '') { return FALSE; } break; } } } return $rc; }
/** * {@inheritdoc} */ protected function operatorForm(&$form, FormStateInterface $form_state) { parent::operatorForm($form, $form_state); $form['include_endpoints'] = array('#type' => 'checkbox', '#title' => t('Include endpoints'), '#default_value' => $this->options['include_endpoints'], '#description' => t('Whether or not include endpoints into the query.')); }
public function validate() { $this->getValueOptions(); $errors = parent::validate(); // If the operator is an operator which doesn't require a value, there is // no need for additional validation. if (in_array($this->operator, $this->operatorValues(0))) { return array(); } if (!in_array($this->operator, $this->operatorValues(1))) { $errors[] = $this->t('The operator is invalid on filter: @filter.', array('@filter' => $this->adminLabel(TRUE))); } if (is_array($this->value)) { if (!isset($this->valueOptions)) { // Don't validate if there are none value options provided, for example for special handlers. return $errors; } if ($this->options['exposed'] && !$this->options['expose']['required'] && empty($this->value)) { // Don't validate if the field is exposed and no default value is provided. return $errors; } // Some filter_in_operator usage uses optgroups forms, so flatten it. $flat_options = OptGroup::flattenOptions($this->valueOptions); // Remove every element which is not known. foreach ($this->value as $value) { if (!isset($flat_options[$value])) { unset($this->value[$value]); } } // Choose different kind of output for 0, a single and multiple values. if (count($this->value) == 0) { $errors[] = $this->t('No valid values found on filter: @filter.', array('@filter' => $this->adminLabel(TRUE))); } } elseif (!empty($this->value) && ($this->operator == 'in' || $this->operator == 'not in')) { $errors[] = $this->t('The value @value is not an array for @operator on filter: @filter', array('@value' => var_export($this->value), '@operator' => $this->operator, '@filter' => $this->adminLabel(TRUE))); } return $errors; }
/** * {@inheritdoc} */ public function acceptExposedInput($input) { if (empty($this->options['exposed'])) { return TRUE; } // The "All" state for this type of filter could have a default value. If // this is a non-multiple and non-required option, then this filter will // participate, but using the default settings *if* 'limit' is true. if (empty($this->options['expose']['multiple']) && empty($this->options['expose']['required']) && !empty($this->options['expose']['limit'])) { $identifier = $this->options['expose']['identifier']; if ($input[$identifier] == 'All') { return TRUE; } } return parent::acceptExposedInput($input); }
/** * {@inheritdoc} */ public function getCacheContexts() { $contexts = parent::getCacheContexts(); $contexts[] = 'user'; return $contexts; }
/** * {@inheritdoc} */ public function getCacheContexts() { $cache_contexts = parent::getCacheContexts(); $cache_contexts[] = 'views_test_cache_context'; return $cache_contexts; }
public function acceptExposedInput($input) { // A very special override because the All state for this type of // filter could have a default: if (empty($this->options['exposed'])) { return TRUE; } // If this is non-multiple and non-required, then this filter will // participate, but using the default settings, *if* 'limit is true. if (empty($this->options['expose']['multiple']) && empty($this->options['expose']['required']) && !empty($this->options['expose']['limit'])) { $identifier = $this->options['expose']['identifier']; if ($input[$identifier] == 'All') { return TRUE; } } return parent::acceptExposedInput($input); }
/** * {@inheritdoc} */ protected function valueForm(&$form, FormStateInterface $form_state) { parent::valueForm($form, $form_state); $form['value'] = array('#type' => 'textfield', '#title' => !$form_state->get('exposed') ? $this->t('Value') : '', '#size' => 30, '#default_value' => $this->value); }