You are here

public function DatasourcePluginBase::getAffectedItemsForEntityChange in Search API 8

Identifies items affected by a change to a referenced entity.

A "change" in this context means an entity getting updated or deleted. (It won't get called for entities being inserted, as new entities cannot already have references pointing to them.)

This method usually doesn't have to return the specified entity itself, even if it is part of this datasource. This method should instead only be used to detect items that are indirectly affected by this change.

For instance, if an index contains nodes, and nodes can contain tags (which are taxonomy term references), and the search index contains the name of the tags as one of its fields, then a change of a term name should result in all nodes being reindexed that contain that term as a tag. So, the item IDs of those nodes should be returned by this method (in case this datasource contains them).

This method will only be called if this datasource plugin returns TRUE in canContainEntityReferences().

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The entity that just got changed.

array[] $foreign_entity_relationship_map: Map of known entity relationships that exist in the index. Its structure is identical to the return value of the \Drupal\search_api\Utility\TrackingHelper::getForeignEntityRelationsMap() method.

\Drupal\Core\Entity\EntityInterface|null $original_entity: (optional) The original entity before the change. If this argument is NULL, it means the entity got deleted.

Return value

string[] Array of item IDs that are affected by the changes between $entity and $original_entity entities.

Overrides DatasourceInterface::getAffectedItemsForEntityChange

See also

\Drupal\search_api\Datasource\DatasourceInterface::canContainEntityReferences()

1 method overrides DatasourcePluginBase::getAffectedItemsForEntityChange()
ContentEntity::getAffectedItemsForEntityChange in src/Plugin/search_api/datasource/ContentEntity.php
Identifies items affected by a change to a referenced entity.

File

src/Datasource/DatasourcePluginBase.php, line 171

Class

DatasourcePluginBase
Defines a base class from which other datasources may extend.

Namespace

Drupal\search_api\Datasource

Code

public function getAffectedItemsForEntityChange(EntityInterface $entity, array $foreign_entity_relationship_map, EntityInterface $original_entity = NULL) : array {
  return [];
}