Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01ShDspHaZGwHoRZCsPBJzsM
69 lines
2.0 KiB
PHP
69 lines
2.0 KiB
PHP
<?php
|
|
|
|
/**
|
|
* @file
|
|
* Hooks of materio_ai: keep the vectors in step with the nodes.
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
use Drupal\node\NodeInterface;
|
|
use Drupal\taxonomy\TermInterface;
|
|
|
|
/**
|
|
* Implements hook_ENTITY_TYPE_insert() for node.
|
|
*/
|
|
function materio_ai_node_insert(NodeInterface $node): void {
|
|
\Drupal::service('materio_ai.vectorizer')->enqueue($node);
|
|
}
|
|
|
|
/**
|
|
* Implements hook_ENTITY_TYPE_update() for node.
|
|
*
|
|
* Also covers a new translation, an unpublished node and a workflow change.
|
|
*/
|
|
function materio_ai_node_update(NodeInterface $node): void {
|
|
\Drupal::service('materio_ai.vectorizer')->enqueue($node);
|
|
}
|
|
|
|
/**
|
|
* Implements hook_ENTITY_TYPE_translation_delete() for node.
|
|
*/
|
|
function materio_ai_node_translation_delete(NodeInterface $translation): void {
|
|
\Drupal::service('materio_ai.embedding_storage')->delete((int) $translation->id(), $translation->language()->getId());
|
|
}
|
|
|
|
/**
|
|
* Implements hook_ENTITY_TYPE_delete() for node.
|
|
*
|
|
* Done at once, even when vectorization is switched off: no model needed.
|
|
*/
|
|
function materio_ai_node_delete(NodeInterface $node): void {
|
|
\Drupal::service('materio_ai.embedding_storage')->delete((int) $node->id());
|
|
}
|
|
|
|
/**
|
|
* Implements hook_ENTITY_TYPE_update() for taxonomy_term.
|
|
*
|
|
* A renamed tag, thesaurus term or company changes the text of its nodes.
|
|
*/
|
|
function materio_ai_taxonomy_term_update(TermInterface $term): void {
|
|
\Drupal::service('materio_ai.vectorizer')->enqueueForTerm($term);
|
|
}
|
|
|
|
/**
|
|
* Implements hook_ENTITY_TYPE_translation_delete() for taxonomy_term.
|
|
*/
|
|
function materio_ai_taxonomy_term_translation_delete(TermInterface $translation): void {
|
|
\Drupal::service('materio_ai.vectorizer')->enqueueForTerm($translation, TRUE);
|
|
}
|
|
|
|
/**
|
|
* Implements hook_ENTITY_TYPE_predelete() for taxonomy_term.
|
|
*
|
|
* Predelete: the node references still exist, so the nodes can be found.
|
|
*/
|
|
function materio_ai_taxonomy_term_predelete(TermInterface $term): void {
|
|
\Drupal::service('materio_ai.vectorizer')->enqueueForTerm($term, TRUE);
|
|
}
|