- Issue created by @dan_metille
- 🇰🇬Kyrgyzstan dan_metille
I’ve tried to digg into both this issue #3521351 and the related #3521350 (remove button in multivalue widgets).
The attached patch captures the current state of work so others can test/review.What the patch does
- Adds a proper AJAX callback to the Provider select
- Rebuilds the entire widget wrapper so the Model and Voice lists refresh when the provider changes.
- Synchronises widget-state values (provider / model) on every rebuild and in generateSubmit().
- Falls back to the first available model if the user never touches the Model list.
Current test results
- Model / Voice lists do update when switching providers.
But:
- After changing provider and clicking Generate audio, the form still reloads without producing a file and silently reverts to the original provider.
- When provider is changed via AJAX, the Drupal-core remove control briefly reappears, leaving us with two Remove buttons again until the next full reload.
So the patch is an improvement, but it does not completely fix either issue yet.
Any feedback or follow-up patches very welcome! - 🇰🇬Kyrgyzstan dan_metille
The attached patch addresses these two reported issues in the AI Audio Field module:
- Issue #3521351: Fixed audio not generating properly after changing the AI provider (current issue)
- Issue #3521350: Fixed the missing remove buttons for unlimited cardinality fields (related issue)
The patch includes the following improvements:
Remove Button Fix
- Added proper implementation of remove buttons for multi-value fields following Drupal core patterns
- Implemented correct AJAX callbacks and submit handlers for the remove functionality
- Fixed button visibility and positioning that was broken during AJAX operations
Audio Generation Fix
- Fixed form state management to properly handle provider changes
- Improved AJAX callbacks to return the correct form elements
- Added proper JavaScript support to maintain field state during AJAX operations
- Enhanced audio player rendering using HTML5 elements and proper caching controls
Additional Improvements
- Fixed widget state management to maintain values across AJAX requests
- Added proper initialization for new field items with default provider values
- Improved widget rebuilding for dependent fields (model, configuration options)
- Added comprehensive logging for easier debugging and maintenance
Testing
The patch has been tested in both Drupal 10 environment with the following test cases:
- Creating new AI audio fields
- Adding multiple field items
- Removing field items
- Changing providers and verifying dependent fields update properly
- Generating audio with different providers
- Verifying audio playback works correctly after AJAX operations
Notes
This patch follows Drupal best practices by using:
- Proper form state management via WidgetState API
- Standard form AJAX callbacks and wrappers
- Drupal's form API for widget elements
- Standard HTML5 audio elements with proper attributes
- JavaScript behaviors with proper DOM event handling
The patch is ready for review and should resolve both issues completely.
- 🇰🇬Kyrgyzstan dan_metille
Now the patch has been updated to include the fix for the "Call to undefined function element_children()" error. The changes include:
- Added the proper import: use Drupal\Core\Render\Element;
- Updated the function call to use the namespaced version: Element::children($element)
This will fix the error encountered when visiting the Media content page. The patch now addresses both original issues (#3521350 and #3521351) plus this new issue with the undefined function.
- 🇰🇬Kyrgyzstan dan_metille
The updated patch now includes:
- Changed element_children() to Element::children() with proper import
- Added method_exists() check before calling getFieldDefinition() to handle Search API fields
The patch is now comprehensive and addresses all three issues:
- Original issue #3521350: Remove button functionality for unlimited cardinality fields
- Original issue #3521351: Audio not generating properly after changing AI providers
- New issues: Element function imports and proper handling of Search API fields
These changes make the module more robust and compatible with other Drupal modules like Search API.