public function NodeExclude::alterIndexedItems in Search API exclude 8
Alter the items to be indexed.
Parameters
\Drupal\search_api\Item\ItemInterface[] $items: An array of items to be indexed, passed by reference.
Overrides ProcessorPluginBase::alterIndexedItems
File
- src/
Plugin/ search_api/ processor/ NodeExclude.php, line 41
Class
- NodeExclude
- Class NodeExclude.
Namespace
Drupal\search_api_exclude\Plugin\search_api\processorCode
public function alterIndexedItems(array &$items) {
/** @var \Drupal\search_api\Item\ItemInterface $item */
foreach ($items as $item_id => $item) {
$object = $item
->getOriginalObject()
->getValue();
$exclude = FALSE;
if ($object instanceof NodeInterface) {
/** @var \Drupal\node\NodeTypeInterface $type */
$type = $object->type->entity;
if ($type
->getThirdPartySetting('search_api_exclude', 'enabled', FALSE)) {
$exclude = (bool) $object
->get('sae_exclude')
->getString();
}
}
if ($exclude) {
unset($items[$item_id]);
}
}
}