Skip to content

Hooks

hook_tagify_autocomplete_match_alter

Defined in tagify.api.php. Runs for every entity in autocomplete suggestions, for the widget's default values, and in the Tagify formatter, so a change shows the same in the form and on display.

function hook_tagify_autocomplete_match_alter(?string &$label, ?string &$info_label, array $context): void
Parameter Description
$label The entity label. Set it to NULL to drop the entity from the results.
$info_label The info label after token replacement.
$context['entity'] The entity.
$context['info_label'] The info label template, before token replacement.

Example, with an object oriented hook implementation:

namespace Drupal\my_module\Hook;

use Drupal\Core\Hook\Attribute\Hook;

final class MyModuleHooks {

  #[Hook('tagify_autocomplete_match_alter')]
  public function tagifyAutocompleteMatchAlter(?string &$label, ?string &$info_label, array $context): void {
    // Hide archived terms from Tagify.
    $entity = $context['entity'];
    if ($entity->hasField('field_archived') && $entity->get('field_archived')->value) {
      $label = NULL;
    }
  }

}

Tagify Icons and Tagify Iconify Icons use this hook to swap the info label for an SVG icon.

hook_tagify_ai_suggestions_prompt_alter

Defined in modules/tagify_ai_suggestions/tagify_ai_suggestions.api.php. Changes the chat system prompt or the decision question that Tagify AI Suggestions sends. Text classification requests carry no instructions, so the hook is not invoked for them.

function hook_tagify_ai_suggestions_prompt_alter(string &$system_prompt, array $context): void
Key in $context Description
candidates Candidate labels keyed by entity ID, as offered to the model.
limit Maximum number of suggestions asked for.
operation_type chat or decision.
question_type Decision only. noul for the per candidate true/false question, choice for the single question over all candidates.
decision_match Decision only. explicit or related.

In a noul question, @label stands for the candidate label and `content` refers to the content sent as state. Leaving the prompt empty keeps the original one.

function my_module_tagify_ai_suggestions_prompt_alter(string &$system_prompt, array $context): void {
  if ($context['operation_type'] === 'decision' && $context['question_type'] === 'noul') {
    $system_prompt = 'Is "@label" a main subject of `content`?';
  }
}

Deprecated hooks

These hooks are documented in the .api.php files but deprecated, and no code in the module invokes them. Use hook_tagify_autocomplete_match_alter() instead. See #3437617.

  • hook_tagify_autocomplete_matches_alter(array &$matches, array $options)
  • hook_tagify_user_list_autocomplete_matches_alter(array &$matches, array $options)