Search by

vectorbross / vb_ai_widget_actions

vectorbross

Config action for recipes: adds an AI generate button to a field, only on bundles that have that field.

Package info

bitbucket.org/vectorbross/vb_ai_widget_actions

Type:drupal-module

pkg:composer/vectorbross/vb_ai_widget_actions

Statistics

Installs: 0

Dependents: 2

Suggesters: 0

dev-master 2026-11-27 11:22 UTC

This package is not auto-updated.

Last update: 2026-12-03 21:57:21 UTC


README

Helper module for VB recipes. It provides one config action, addAiGenerateButton, that adds an AI generate button to a field, but only on the bundles that have that field.

Recipes cannot say "only if the content type has this field". This action does that check, so a recipe can target every form display with a wildcard and leave bundles without the field alone.

Used by vb_ai_seo_meta and vb_ai_summary.

What it installs

ModulePurpose
ai_automatorsRuns the prompt (part of drupal/ai)
field_widget_actionsShows the generate button under the field

maxlength is optional. When it is enabled, the action can also add a character counter.

What it configures

Nothing on its own. Enabling the module makes the config action available to recipes and adds the permission described under Permissions.

The config action, per bundle

  1. Skips the bundle if the field does not exist, is hidden on the form, or its field or widget type is not supported (plain text and formatted text fields, single and long).
  2. Creates an AI Automator <entity_type>.<bundle>.<field>.default with the "simple" LLM rule and worker field_widget_actions, so it only runs on click. It uses the default chat provider. An existing automator is kept.
  3. Adds the automator_text field widget action, unless the field already has an action for that automator.
  4. Adds the Maxlength counter, unless the widget already has one.

Nothing existing is overwritten, so re-applying a recipe is safe.

Usage in a recipe

install:
  - vb_ai_widget_actions

config:
  actions:
    core.entity_form_display.node.*.default:
      addAiGenerateButton:
        - field_name: field_seo_title
          button_label: 'Generate SEO title'
          prompt: 'Write an SEO title for: {{ context }}'
          context_fields: [body, field_body]
          max_length: 60
KeyRequiredDescription
field_nameyesMachine name of the field that gets the button
button_labelyesText on the button
promptyesPrompt for the AI. Must contain {{ context }}
context_fieldsnoFields the AI reads; the first existing one wins. Falls back to the entity label
max_lengthnoAdds a Maxlength counter (soft limit) when Maxlength is enabled
enable_refinementnoOpens a dialog to refine the result before inserting. Default false

Permissions

PermissionEffect
use ai generate buttonsSee and click AI Automator buttons under form fields

Field Widget Actions itself only checks whether the user may edit the entity. This module hides every AI Automator button (any field widget action provided by ai_automators) from users without the permission. The button gets #access FALSE, so a crafted AJAX request cannot run the AI either. The administrator role has every permission.

The recipes that use this module (vb_ai_seo_meta, vb_ai_summary) grant the permission to the webmaster role.

Requirements

  • Drupal 11.2+
  • drupal/ai 1.5+ (ai_automators)
  • drupal/field_widget_actions 1.5+
  • drupal/maxlength 3.2+ (optional, for the counter)

Install

Normally you don't install this module yourself: a recipe such as vb_ai_seo_meta requires it. To use it in your own recipe:

ddev composer require vectorbross/vb_ai_widget_actions

Verify

ddev drush pm:list --status=enabled --filter=vb_ai_widget_actions

Skipped fields (unsupported type or widget, hidden field) are logged in the vb_ai_widget_actions channel in Recent log messages.

Tests

ddev exec vendor/bin/phpunit -c web/core web/modules/contrib/vb_ai_widget_actions/tests

License

GPL-2.0-or-later. See LICENSE.txt.