You are here

protected function JsonApiResponseWidget::buildListItems in JSON:API Search API 8

Builds a renderable array of result items.

Parameters

\Drupal\facets\FacetInterface $facet: The facet we need to build.

\Drupal\facets\Result\ResultInterface $result: A result item.

Return value

array A renderable array of the result.

Overrides WidgetPluginBase::buildListItems

1 call to JsonApiResponseWidget::buildListItems()
JsonApiResponseWidget::build in modules/jsonapi_search_api_facets/src/Plugin/facets/widget/JsonApiResponseWidget.php
Builds the facet widget for rendering.

File

modules/jsonapi_search_api_facets/src/Plugin/facets/widget/JsonApiResponseWidget.php, line 50

Class

JsonApiResponseWidget
A simple widget class that returns for inclusion in JSON:API Search API.

Namespace

Drupal\jsonapi_search_api_facets\Plugin\facets\widget

Code

protected function buildListItems(FacetInterface $facet, ResultInterface $result) {
  if ($children = $result
    ->getChildren()) {
    $items = $this
      ->prepare($result);
    $children_markup = [];
    foreach ($children as $child) {
      $children_markup[] = $this
        ->buildChildren($child);
    }
    $items['children'] = [
      $children_markup,
    ];
  }
  else {
    $items = $this
      ->prepare($result);
  }
  return $items;
}