You are here

public function FacetSourceEditForm::buildForm in Facets 8

Form constructor.

Parameters

array $form: An associative array containing the structure of the form.

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

Return value

array The form structure.

Overrides EntityForm::buildForm

File

src/Form/FacetSourceEditForm.php, line 64

Class

FacetSourceEditForm
Provides a form for editing facet sources.

Namespace

Drupal\facets\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {

  /** @var \Drupal\facets\FacetSourceInterface $facet_source */
  $facet_source = $this
    ->getEntity();
  $form['#tree'] = TRUE;
  $form['filter_key'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Filter key'),
    '#size' => 20,
    '#maxlength' => 255,
    '#default_value' => $facet_source
      ->getFilterKey(),
    '#description' => $this
      ->t('The key used in the url to identify the facet source.
        When using multiple facet sources you should make sure each facet source has a different filter key.'),
  ];
  $url_processors = [];
  $url_processors_description = [];
  foreach ($this->urlProcessorPluginManager
    ->getDefinitions() as $definition) {
    $url_processors[$definition['id']] = $definition['label'];
    $url_processors_description[] = $definition['description'];
  }
  $form['url_processor'] = [
    '#type' => 'radios',
    '#title' => $this
      ->t('URL Processor'),
    '#options' => $url_processors,
    '#default_value' => $facet_source
      ->getUrlProcessorName(),
    '#description' => $this
      ->t('The URL Processor defines the url structure used for this facet source.') . '<br />- ' . implode('<br>- ', $url_processors_description),
  ];
  $breadcrumb_settings = $facet_source
    ->getBreadcrumbSettings();
  $form['breadcrumb'] = [
    '#type' => 'fieldset',
    '#title' => $this
      ->t('Breadcrumb'),
  ];
  $form['breadcrumb']['active'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Append active facets to breadcrumb'),
    '#default_value' => isset($breadcrumb_settings['active']) ? $breadcrumb_settings['active'] : FALSE,
  ];
  $form['breadcrumb']['before'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Show facet label before active facet'),
    '#default_value' => isset($breadcrumb_settings['before']) ? $breadcrumb_settings['before'] : TRUE,
    '#states' => [
      'visible' => [
        ':input[name="breadcrumb[active]"]' => [
          'checked' => TRUE,
        ],
      ],
    ],
  ];
  $form['breadcrumb']['group'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Group active items under same crumb (not implemented yet - now always grouping)'),
    '#default_value' => isset($breadcrumb_settings['group']) ? $breadcrumb_settings['group'] : FALSE,
    '#states' => [
      'visible' => [
        ':input[name="breadcrumb[active]"]' => [
          'checked' => TRUE,
        ],
      ],
    ],
  ];

  // The parent's form build method will add a save button.
  return parent::buildForm($form, $form_state);
}