Skip to content

Ancestor Criterion

The Ancestor Search Criterion searches for content that is an ancestor of the provided Location, including this Location.

Arguments

  • value - array of Location pathStrings

Example

PHP

1
$query->query = new Criterion\Ancestor([$this->locationService->loadLocation(62)->pathString]);

REST API

1
2
3
4
5
<Query>
    <Filter>
        <AncestorCriterion>/81/82/</AncestorCriterion>
    </Filter>
</Query>
1
2
3
4
5
"Query": {
    "Filter": {
        "AncestorCriterion": "/81/82/"
    }
}

Use case

You can use the Ancestor Search Criterion to create a list of breadcrumbs leading to the Location:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
$query = new LocationQuery();
$query->query = new Criterion\Ancestor([$this->locationService->loadLocation($locationId)->pathString]);

$results = $this->searchService->findLocations($query);
$breadcrumbs = [];
foreach ($results->searchHits as $searchHit) {
    $breadcrumbs[] = $searchHit;
}

return $this->render('parts/breadcrumbs.html.twig', [
    'breadcrumbs' => $breadcrumbs,
]);
1
2
3
4
5
6
7
8
{% for breadcrumb in breadcrumbs %}
    {% if not loop.first %} -> {% endif %}
    {% if not loop.last %}
        <a href="{{ ibexa_path( breadcrumb.valueObject ) }}">{{ breadcrumb.valueObject.contentInfo.name }}</a>
    {% else %}
        {{ breadcrumb.valueObject.contentInfo.name }}
    {% endif %}
{% endfor %}