You are here

public function DateItemProcessor::buildConfigurationForm in Facets 8

Adds a configuration form for this processor.

Parameters

array $form: The form.

\Drupal\Core\Form\FormStateInterface $form_state: The current form state.

\Drupal\facets\FacetInterface $facet: The facet this processor is being added to.

Overrides ProcessorPluginBase::buildConfigurationForm

File

src/Plugin/facets/processor/DateItemProcessor.php, line 52

Class

DateItemProcessor
Provides a processor for dates.

Namespace

Drupal\facets\Plugin\facets\processor

Code

public function buildConfigurationForm(array $form, FormStateInterface $form_state, FacetInterface $facet) {
  $this
    ->getConfiguration();
  $build['date_display'] = [
    '#type' => 'radios',
    '#title' => $this
      ->t('Date display'),
    '#default_value' => $this
      ->getConfiguration()['date_display'],
    '#options' => [
      'actual_date' => $this
        ->t('Actual date with granularity'),
      'relative_date' => $this
        ->t('Relative date'),
    ],
  ];
  $build['granularity'] = [
    '#type' => 'radios',
    '#title' => $this
      ->t('Granularity'),
    '#default_value' => $this
      ->getConfiguration()['granularity'],
    '#options' => $this
      ->granularityOptions(),
  ];
  $build['date_format'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Date format'),
    '#default_value' => $this
      ->getConfiguration()['date_format'],
    '#description' => $this
      ->t('Override default date format used for the displayed filter format. See the <a href="http://php.net/manual/function.date.php">PHP manual</a> for available options.'),
    '#states' => [
      'visible' => [
        ':input[name="facet_settings[date_item][settings][date_display]"]' => [
          'value' => 'actual_date',
        ],
      ],
    ],
  ];
  return $build;
}