getSearchablePages

The getSearchablePages hook is triggered when the the search index is rebuilt. It passes the array of pages and the ID of the root page as arguments and expects an array of absolute URLs as return value.

Parameters

  1. array $pages

    List of absolute URLs that should be indexed.

  2. int $root

    ID of the current root page. This parameter is not always available.

  3. bool $isSitemap

    true if the hook is triggered when updating XML sitemap. This parameter is not always available.

  4. string $language

    Language of the generated root page. This parameter is not always available.

Return Values

Return the list of pages that should be indexed. Be aware that this means these URLs will be requested, and each page is responsible for its indexing. By checking $isSitemap, you can decide wether to include your pages in the XML sitemap or only for the search index.

Example

// src/EventListener/GetSearchablePagesListener.php
namespace App\EventListener;

use Contao\CoreBundle\ServiceAnnotation\Hook;
use Terminal42\ServiceAnnotationBundle\ServiceAnnotationInterface;

class GetSearchablePagesListener implements ServiceAnnotationInterface
{
    /**
     * @Hook("getSearchablePages")
     */
    public function onGetSearchablePages(array $pages, int $root = null, bool $isSitemap = false, string $language = null): array
    {
        // Modify the $pages array …

        return $pages;
    }
}

References