You are here

public function FacetSourceController::facetSourceConfigForm in Facets 8

Configuration for the facet source.

Parameters

string $facets_facet_source: The plugin id.

Return value

array A renderable array containing the form.

1 string reference to 'FacetSourceController::facetSourceConfigForm'
facets.routing.yml in ./facets.routing.yml
facets.routing.yml

File

src/Controller/FacetSourceController.php, line 24

Class

FacetSourceController
Provides route responses for facet source configuration.

Namespace

Drupal\facets\Controller

Code

public function facetSourceConfigForm($facets_facet_source) {

  // Returns the render array of the FacetSourceConfigForm.
  $form_object = $this
    ->entityTypeManager()
    ->getFormObject('facets_facet_source', 'edit');
  assert($form_object instanceof EntityForm);
  $facet_source_storage = $this
    ->entityTypeManager()
    ->getStorage('facets_facet_source');
  $source_id = str_replace(':', '__', $facets_facet_source);
  $facet_source = $facet_source_storage
    ->load($source_id);
  if (!$facet_source instanceof FacetSourceInterface) {
    $facet_source = $facet_source_storage
      ->create([
      'id' => $source_id,
      'name' => $facets_facet_source,
    ]);
    $facet_source
      ->save();
  }
  $form_object
    ->setEntity($facet_source);
  return $this
    ->formBuilder()
    ->getForm($form_object);
}