You are here

public function Facet::setWidget in Facets 8

Sets the facet widget definition.

Parameters

string $id: The widget plugin id.

array $configuration: (optional) The facet widget plugin configuration. If missed, the default plugin configuration will be filled.

Overrides FacetInterface::setWidget

File

src/Entity/Facet.php, line 338

Class

Facet
Defines the facet configuration entity.

Namespace

Drupal\facets\Entity

Code

public function setWidget($id, array $configuration = NULL) {
  if ($configuration === NULL) {
    $instance = $this
      ->getWidgetManager()
      ->createInstance($id);

    // Get the default configuration for this plugin.
    $configuration = $instance
      ->getConfiguration();
  }
  $this->widget = [
    'type' => $id,
    'config' => $configuration,
  ];

  // Unset the widget instance, if exists.
  unset($this->widgetInstance);
}