Skip to content
Snippets Groups Projects
Commit 2aaa169c authored by Valery Lourie's avatar Valery Lourie
Browse files

Issue #3005058 by valthebald: React on entity insert

parent 82d4ecb7
Branches
Tags 8.x-1.3
No related merge requests found
......@@ -89,6 +89,38 @@ function entity_language_fallback_form_language_admin_edit_form_builder($entity_
);
}
/**
* Implements hook_entity_insert().
*
* Modified version of search_api_entity_insert().
* @see search_api_entity_insert()
*/
function entity_language_fallback_entity_insert(EntityInterface $entity) {
if (!\Drupal::moduleHandler()->moduleExists('search_api')) {
return;
}
// Check if the entity is a content entity.
if (!($entity instanceof ContentEntityInterface) || $entity->search_api_skip_tracking) {
return;
}
$indexes = ContentEntityFallback::getIndexesForEntity($entity);
if (!$indexes) {
return;
}
// Compute the item IDs for all languages of the entity.
$item_ids = [];
$entity_id = $entity->id();
foreach (array_keys($entity->getTranslationLanguages()) as $langcode) {
$item_ids[] = $entity_id . ':' . $langcode;
}
$datasource_id = 'entity_language_fallback:' . $entity->getEntityTypeId();
foreach ($indexes as $index) {
$filtered_item_ids = ContentEntityFallback::filterValidItemIds($index, $datasource_id, $item_ids);
$index->trackItemsInserted($datasource_id, $filtered_item_ids);
}
}
/**
* Implements hook_entity_update().
*
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment