Excluding CMS Pages
1 min
You may wish to exclude certain CMS pages from the sync.
To do this we inject an isIndexableCondition into the isIndexableConditions array for the virtual type Klevu\IndexingCms\Service\Determiner\IsIndexableDeterminer
<virtualType name="Klevu\IndexingCms\Service\Determiner\IsIndexableDeterminer">
<arguments>
<argument name="isIndexableConditions" xsi:type="array">
<item name="pageIsIndexableCondition"
xsi:type="object">Vendor\Module\Service\Determiner\ExcludedPagesIsIndexableCondition</item>
</argument>
</arguments>
</virtualType>Create that class, which must implement the IsIndexableConditionInterface
<?php
namespace Vendor\Module\Service\Determiner;
use Klevu\IndexingApi\Service\Determiner\IsIndexableConditionInterface;
use Magento\Cms\Api\Data\PageInterface;
class ExcludedPagesIsIndexableConditionr implements IsIndexableConditionInterface
{
/**
* Edit routes as required
* Alternatively inject these via di.xml
*
* @param string[]
*/
private array $excludedPages = [
'no-route',
'service-unavailable',
];
public function execute(
ExtensibleDataInterface|PageInterface $entity,
StoreInterface $store,
): bool {
if (!($entity instanceof PageInterface)) {
throw new \InvalidArgumentException(
sprintf(
'Invalid argument provided for "$entity". Expected %s, received %s.',
PageInterface::class,
get_debug_type($entity),
),
);
}
return !in_array(
needle: $page->getIdentifier(),
haystack: $this->excludedPages,
strict: true,
);
}
}
See Entities Is Indexable Determiner for more information.