Drupal is a registered trademark of Dries Buytaert
cms 2.1.1 Update released for Drupal core (2.1.1)! drupal 11.3.6 Update released for Drupal core (11.3.6)! drupal 10.6.6 Update released for Drupal core (10.6.6)! cms 2.1.0 Update released for Drupal core (2.1.0)! bootstrap 8.x-3.40 Minor update available for theme bootstrap (8.x-3.40). menu_link_attributes 8.x-1.7 Minor update available for module menu_link_attributes (8.x-1.7). moderated_content_bulk_publish 2.0.52 Minor update available for module moderated_content_bulk_publish (2.0.52). klaro 3.0.10 Minor update available for module klaro (3.0.10). klaro 3.0.9 Minor update available for module klaro (3.0.9). layout_paragraphs 2.1.2 Minor update available for module layout_paragraphs (2.1.2). geofield_map 11.1.8 Minor update available for module geofield_map (11.1.8). editoria11y 2.2.22 Minor update available for module editoria11y (2.2.22). ai 1.2.13 Minor update available for module ai (1.2.13). ai 1.3.2 Minor update available for module ai (1.3.2). moderated_content_bulk_publish 2.0.51 Minor update available for module moderated_content_bulk_publish (2.0.51). moderated_content_bulk_publish 2.0.50 Minor update available for module moderated_content_bulk_publish (2.0.50). editoria11y 2.2.21 Minor update available for module editoria11y (2.2.21). eca 3.1.0 Minor update available for module eca (3.1.0). sophron 3.1.1 Minor update available for module sophron (3.1.1). ai 1.3.1 Minor update available for module ai (1.3.1).

AI Metatag Generator

A Drupal module that leverages AI to automatically generate metatags based on the content
(title, description, keywords, abstract) for content nodes.

Features

  • AI-powered metatag generation (title, description, keywords, abstract) from node view
  • Per-language prompt configuration
  • Default prompt template with language placeholder
  • Configurable content types and metatag field
  • Selectable AI provider and model
  • HTML content stripping and cleanup
  • One-click AJAX generation from node edit forms
  • Success/error feedback via modal dialog popups
  • Comprehensive error handling with try-catch and logging

Requirements

  • Drupal 10+
  • AI module (`drupal/ai`)
  • Metatag module (`drupal/metatag`)
  • PHP 8+

Installation

  1. Enable the module via Drupal admin or Drush: drush en ai_metatag_generator
  2. For site-wide installation, add to core.extension.yml

Configuration

Navigate to Configuration > AI > AI Metatag Generator
(`/admin/config/ai/ai-metatag-generator`).

Settings

  • Content Types: Select which content types allow AI metatag generation.
  • Meta tag field machine name: The metatag field on the content type (e.g. `field_meta_tag`).
  • AI Provider and Model: Select the AI provider/model for chat operations. Falls back to the default provider if not set.
  • Content Processing:
    • Strip HTML Tags: Remove HTML before sending to AI.
    • Display Mode: View mode used to render node content. (default: `full`)
  • Prompts
    • Default Prompt: A read-only reference prompt showing the template used when no language-specific prompt is set.
    • Per-language prompts: Customize the prompt for each enabled language.

Default Configuration

content_types: {}
metatag_field: 'field_meta_tag'
provider_model: ''
strip_html: true
display_mode: 'full'
prompts: {}
black_list: ''

Usage

From Node Edit Forms

  1. Edit a node of an enabled content type that has the configured metatag field.
  2. Click Generate Metatags with AI in the form actions area.
  3. The module will:
    • Render the node content using the configured display mode.
    • Strip HTML if configured.
    • Send content to the AI provider with the language-specific prompt (or the default prompt).
    • Parse the JSON response.
    • Populate the metatag form fields (title, description, keywords, abstract) via AJAX.
  4. A popup dialog confirms success or displays errors.
  5. Review and save the node to apply changes.

Programmatic Usage

$ai_service = \Drupal::service(
  'ai_metatag_generator.ai_service'
);

// Generate metatags for a node.
$metatags = $ai_service->generateMetatags($node);
// Returns: ['title' => ..., 'description' => ...,
//   'keywords' => ..., 'abstract' => ...] or NULL.

// Update node metatag fields.
$ai_service->updateNodeMetatags($node, $metatags);

Permissions

  • Administer AI Metatag Generator: Configure module settings (`administer ai metatag generator`).
  • Use AI Metatag Generator: Generate metatags for content (`use ai metatag generator`)

Error Handling

  • All service methods and form handlers use try-catch blocks with logging to the `ai_metatag_generator` channel.
  • AJAX errors are displayed in modal dialog popups.
  • Configuration save failures show messenger errors.
  • AI provider unavailability is handled gracefully with a user-facing message on the config form.

Development

Running Tests

All tests

./vendor/bin/phpunit <module_path>/ai_metatag_generator/tests/

Specific test

./vendor/bin/phpunit <module_path>/ai_metatag_generator/tests/src/Unit/Services/AiMetatagServiceTest.php

Code Standards

./vendor/bin/phpcs <module_path>/ai_metatag_generator/

Troubleshooting

  • Generate button not showing: Check that the node's content type is selected in config, the metatag field name matches, the node is not new, and the user has the use ai metatag generator permission.
  • AI calls failing: Verify the AI module is configured with valid API keys and a chat provider is available.
  • Empty responses: Check the prompt template.
  • Config form errors: If AI providers fail to load, the form will display an error message instead of settings.
  • AJAX requests prevent page reloads
  • Asynchronous processing for better user experience

Support

For issues related to this module, check:

  1. Module configuration at /admin/config/ai/ai-metatag-generator
  2. Drupal logs at /admin/reports/dblog
  3. AI module configuration
  4. Network connectivity to AI services

Activity

Total releases
1
First release
Apr 2026
Latest release
18 hours ago
Release cadence
Stability
0% stable

Releases

Version Type Release date
1.0.0-alpha1 Pre-release Apr 14, 2026