You are here

public function Facet::getFacetSourceConfig in Facets 8

Returns the facet source configuration object.

Return value

\Drupal\facets\FacetSourceInterface A facet source configuration object.

Overrides FacetInterface::getFacetSourceConfig

File

src/Entity/Facet.php, line 744

Class

Facet
Defines the facet configuration entity.

Namespace

Drupal\facets\Entity

Code

public function getFacetSourceConfig() {

  // Return the facet source config object, if it's already set on the facet.
  if ($this->facetSourceConfig instanceof FacetSource) {
    return $this->facetSourceConfig;
  }
  $storage = \Drupal::entityTypeManager()
    ->getStorage('facets_facet_source');
  $source_id = str_replace(':', '__', $this->facet_source_id);

  // Load and return the facet source config object from the storage.
  $facet_source = $storage
    ->load($source_id);
  if ($facet_source instanceof FacetSource) {
    $this->facetSourceConfig = $facet_source;
    return $this->facetSourceConfig;
  }

  // We didn't have a facet source config entity yet for this facet source
  // plugin, so we create it on the fly.
  $facet_source = new FacetSource([
    'id' => $source_id,
    'name' => $this->facet_source_id,
    'filter_key' => 'f',
    'url_processor' => 'query_string',
  ], 'facets_facet_source');
  return $facet_source;
}