You are here

public function FacetSettingsForm::buildFacetSourceConfigForm in Facets 8

Builds the configuration forms for all possible facet sources.

Parameters

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

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

1 call to FacetSettingsForm::buildFacetSourceConfigForm()
FacetSettingsForm::buildEntityForm in src/Form/FacetSettingsForm.php
Builds the form for editing and creating a facet.

File

src/Form/FacetSettingsForm.php, line 208

Class

FacetSettingsForm
Provides a form for creating and editing facets.

Namespace

Drupal\facets\Form

Code

public function buildFacetSourceConfigForm(array &$form, FormStateInterface $form_state) {
  $facet_source_id = $this
    ->getEntity()
    ->getFacetSourceId();
  if (!is_null($facet_source_id) && $facet_source_id !== '') {

    /** @var \Drupal\facets\FacetSource\FacetSourcePluginInterface $facet_source */
    $facet_source = $this->facetSourcePluginManager
      ->createInstance($facet_source_id, [
      'facet' => $this
        ->getEntity(),
    ]);
    if ($config_form = $facet_source
      ->buildConfigurationForm([], $form_state)) {
      $form['facet_source_configs'][$facet_source_id]['#type'] = 'container';
      $form['facet_source_configs'][$facet_source_id]['#attributes'] = [
        'class' => [
          'facet-source-field-wrapper',
        ],
      ];
      $form['facet_source_configs'][$facet_source_id]['#title'] = $this
        ->t('%plugin settings', [
        '%plugin' => $facet_source
          ->getPluginDefinition()['label'],
      ]);
      $form['facet_source_configs'][$facet_source_id] += $config_form;
    }
  }
}