public function RptMapWidget::build in Search API Location 8
Builds the facet widget for rendering.
Parameters
\Drupal\facets\FacetInterface $facet: The facet we need to build.
Return value
array A renderable array.
Overrides WidgetPluginBase::build
File
- modules/
facets_map_widget/ src/ Plugin/ facets/ widget/ RptMapWidget.php, line 22
Class
- RptMapWidget
- A widget class that provides a map interface to narrow down facet results.
Namespace
Drupal\facets_map_widget\Plugin\facets\widgetCode
public function build(FacetInterface $facet) {
/** @var \Drupal\facets\Result\Result[] $results */
$results = $facet
->getResults();
$build['map'] = [
'#type' => 'html_tag',
'#tag' => 'div',
'#attributes' => [
'class' => [
'facets-map',
],
'id' => $facet
->id(),
],
];
$build['#attached']['library'][] = 'facets_map_widget/facets_map';
$build['#attached']['drupalSettings']['facets']['map'] = [
'id' => $facet
->id(),
'url' => $results[0]
->getUrl()
->toString(),
'results' => json_encode($results[0]
->getRawValue()),
];
return $build;
}