Hooks
The AI Context module implements several hooks and provides one alter hook for third-party modules.
Alter hooks
hook_ai_context_scope_values_alter()
Allows modules to add, modify, or remove values from any scope plugin. Called when scope values are retrieved for display in forms or for matching.
function hook_ai_context_scope_values_alter(
array &$values,
string $scope_id,
): void {
if ($scope_id === 'use_case') {
$values['custom_workflow'] = t('Custom Workflow');
}
if ($scope_id === 'language') {
unset($values['und']);
}
}
Parameters:
$values-- associative array ofvalue_id => labelpairs (by reference)$scope_id-- plugin ID of the scope (e.g.,use_case,language)
API group: @ingroup ai_context_scope_api
Implemented hooks
hook_ENTITY_TYPE_delete() for ai_context_item
When a parent context item is deleted, clears the parent and
subcontext_type fields from all children to prevent orphaned references.
hook_cron()
Purges old usage records based on configured limits (usage_max_records
and usage_max_age). Runs during each cron execution.
hook_theme()
Registers two theme hooks:
ai_context_overview-- the overview dashboard pageai_context_pill_list-- renders a list of labels as pill-style tags
hook_local_tasks_alter()
Conditionally shows or hides the Overview tab based on the
show_overview_page setting.
hook_module_implements_alter()
Ensures the module's hook_form_alter() runs after Scheduler's, so it can
modify Scheduler form elements.
hook_form_alter()
Applies to AI Context Item entity forms and the AI Agent edit form:
- Moves Scheduler fields to the sidebar
- Groups moderation state with revision information
- Hides
target_entitiesfield when no entity types are allowed - Adds a "Context Control Center" section to the agent form with a link to agent context settings
hook_form_FORM_ID_alter() for ai_context_item_type_edit_form
Customizes Scheduler fieldset labels on the bundle type edit form.
hook_field_widget_single_element_form_alter()
Restricts the dynamic entity reference widget on target_entities to only
show allowed entity types and enforces one entity per field row.
hook_page_attachments_alter()
Attaches the ai_context/ai_context library globally.
hook_gin_content_form_routes()
Registers context item add/edit form routes with the Gin admin theme for content-form styling.
hook_preprocess_html()
Adds a page-ai-context-item-view body class on context item view pages.
hook_entity_type_alter()
Delegates to DiffHooks for Diff module integration (adding diff field
builders to entity type definitions).
hook_modules_installed()
Delegates to DiffHooks to register diff field builders when the Diff
module is installed.