Developer corner
Architecture overview
ai3-alttext follows the capability pattern introduced by wegewerk/ai3_core . The central pieces are:
| Class | Responsibility |
|---|---|
Zak | Extends Abstract; resizes the image and
calls the /alttexts REST endpoint |
Alttext | Registers the alt text capability under the key alttext
so the core task queue can dispatch jobs to it |
Alttext (Ajax) | Manages the generation task lifecycle: create, poll status, review, and select a suggestion |
Filelist (Ajax) | Lists files in a folder and saves approved alt texts back to
sys_ |
Folder (Ajax) | Lists sub-folders and bulk-accepts suggestions recursively |
Ai3Alttext | FormEngine Abstract that renders the batch button in
the file metadata edit form |
After | Loads the extension language labels whenever a FormEngine page is initialised |
ZakAiAlttext API class
Wegewerk\ extends
Wegewerk\ (implementing
Zak) and exposes a single public method:
public function generate(array $options = []): string
The method accepts an options array:
image(string, required): Absolute local path to the image file.Path caption(string, optional): Contextual text / caption for the image.language(string, optional): Target language code.previous(mixed, optional): Previous suggestions to avoid duplication.
The generation flow:
- Verifies the image file exists on disk (in
prepare).Payload () - Resizes the image to a maximum of 512 × 512 px using
ImageandService Imageto keep API payload sizes small.Processing Service - Base64-encodes the resized image into the
imagepayload field and POSTs it to the/alttextsendpoint viaZak.Ai Client:: post Json () - Returns the
alttextstring from the API response, or an empty string if the API reports an error.
Ajax routes
All Ajax endpoints are registered in
Configuration/Backend/AjaxRoutes.php:
| Route identifier | Target |
|---|---|
ai3_ | Alttext |
ai3_ | Alttext |
ai3_ | Alttext |
ai3_ | Alttext |
ai3_ | Filelist |
ai3_ | Filelist |
ai3_ | Filelist |
ai3_ | Folder |
ai3_ | Folder |
Capability registration
Alttext is registered as a DI-tagged service so that the
wegewerk/ai3_core
capability registry picks it up
automatically:
Wegewerk\Ai3Alttext\Domain\Capabilities\AlttextCapability:
autowire: false
arguments:
$key: 'alttext'
$title: 'Alt Text'
$endpoint: '@Wegewerk\Ai3Alttext\Api\ZakAiAlttext'
tags:
- name: ai3.capability
FormEngine field control
The field control is registered as a custom FormEngine node in
ext_localconf.php:
$GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['nodeRegistry'][1759225979] = [
'nodeName' => 'ai3AlttextAddToBatch',
'priority' => 30,
'class' => \Wegewerk\Ai3Alttext\FormEngine\FieldControl\Ai3AlttextAddToBatch::class,
];
The TCA override in
Configuration/TCA/Overrides/sys_file_metadata.php attaches
this node to the alternative field of sys_ as a
field.
Event listener
After listens to
After and injects the extension
language labels into the page renderer so that the JavaScript modules
can use them via the TYPO3 inline label API.