SocialDate.php in Open Social 10.2.x
File
modules/social_features/social_search/src/Plugin/views/filter/SocialDate.php
View source
<?php
namespace Drupal\social_search\Plugin\views\filter;
use Drupal\Core\Form\FormStateInterface;
use Drupal\search_api\Plugin\views\filter\SearchApiDate as DateTimeDate;
class SocialDate extends DateTimeDate {
public function acceptExposedInput($input) {
if (empty($this->options['exposed'])) {
return TRUE;
}
if (!empty($this->options['expose']['use_operator']) && !empty($this->options['expose']['operator_id'])) {
$operator = $input[$this->options['expose']['operator_id']];
}
else {
$operator = $this->operator;
}
if (!empty($input['type']) && $input['type'] !== 'event') {
$input['field_event_date']['value'] = '';
$input['field_event_date']['max'] = '';
$input['field_event_date']['min'] = '';
}
$operatorfromurl = NULL;
if ($operator === NULL && $this->realField === 'created') {
$operatorfromurl = \Drupal::request()->query
->get('created_op');
if (!empty($operatorfromurl)) {
$this->operator = $operatorfromurl;
$input['created_op'] = $operatorfromurl;
$this->view->exposed_raw_input = $this->view
->getExposedInput();
}
}
if ($operator === NULL && $operatorfromurl === NULL) {
return FALSE;
}
$return = parent::acceptExposedInput($input);
if (!$return) {
$operators = $this
->operators();
if ($operators[$this->operator]['values'] === 0) {
return TRUE;
}
}
return $return;
}
public function operators() {
$operators = parent::operators();
$operators['<']['title'] = $this
->t('Before');
$operators['>']['title'] = $this
->t('After');
$operators['between']['title'] = $this
->t('Between');
$operators_to_keep = [
'<',
'>',
'between',
];
foreach ($operators as $operator_name => $value) {
if (is_string($operator_name) && !in_array($operator_name, $operators_to_keep, FALSE)) {
if (!empty($operators[$operator_name])) {
unset($operators[$operator_name]);
}
}
}
return $operators;
}
protected function valueForm(&$form, FormStateInterface $form_state) {
parent::valueForm($form, $form_state);
$form_keys = [
'field_event_date_op' => $this
->t('Date of Event'),
'created_op' => $this
->t('Registration Date'),
];
foreach ($form_keys as $key => $title) {
if (!empty($form[$key])) {
$form['settings'] = [
'#type' => 'details',
'#title' => $title,
'#attributes' => [
'class' => [
'filter',
],
],
];
$form[$key]['#title'] = '';
if (!empty($form['value'])) {
if (!empty($form['value']['value'])) {
$form['value']['value']['#type'] = 'date';
}
if (!empty($form['value']['min'])) {
$form['value']['min']['#type'] = 'date';
$form['value']['min']['#title'] = '';
}
if (!empty($form['value']['max'])) {
$form['value']['max']['#type'] = 'date';
}
}
}
}
}
}