diff --git a/src/Plugin/facets/widget/DateArrayWidget.php b/src/Plugin/facets/widget/DateArrayWidget.php new file mode 100644 index 0000000..b0c41ae --- /dev/null +++ b/src/Plugin/facets/widget/DateArrayWidget.php @@ -0,0 +1,95 @@ + $this->t('Year'), + SearchApiDate::FACETAPI_DATE_MONTH => $this->t('Month'), + SearchApiDate::FACETAPI_DATE_DAY => $this->t('Day'), + SearchApiDate::FACETAPI_DATE_HOUR => $this->t('Hour'), + SearchApiDate::FACETAPI_DATE_MINUTE => $this->t('Minute'), + SearchApiDate::FACETAPI_DATE_SECOND => $this->t('Second'), + ); + } + + /** + * {@inheritdoc} + */ + public function defaultConfiguration() { + return [ + 'display_relative' => FALSE, + 'granularity' => SearchApiDate::FACETAPI_DATE_MONTH, + 'date_display' => '', + 'relative_granularity' => 1, + 'relative_text' => TRUE, + ] + parent::defaultConfiguration(); + } + + /** + * {@inheritdoc} + */ + public function buildConfigurationForm(array $form, FormStateInterface $form_state, FacetInterface $facet) { + $configuration = $this->getConfiguration(); + + $form += parent::buildConfigurationForm($form, $form_state, $facet); + + $form['display_relative'] = [ + '#type' => 'radios', + '#title' => $this->t('Date display'), + '#default_value' => $configuration['display_relative'], + '#options' => [ + FALSE => $this->t('Actual date with granularity'), + TRUE => $this->t('Relative date'), + ], + ]; + + $form['granularity'] = [ + '#type' => 'radios', + '#title' => $this->t('Granularity'), + '#default_value' => $configuration['granularity'], + '#options' => $this->granularityOptions(), + ]; + $form['date_display'] = [ + '#type' => 'textfield', + '#title' => $this->t('Date format'), + '#default_value' => $configuration['date_display'], + '#description' => $this->t('Override default date format used for the displayed filter format. See the PHP manual for available options.'), + '#states' => [ + 'visible' => [':input[name="widget_config[display_relative]"]' => ['value' => 0]], + ], + ]; + + return $form; + } + + /** + * {@inheritdoc} + */ + public function getQueryType($query_types) { + return $query_types['date']; + } + +}