diff --git a/composer.json b/composer.json index ffb1acc226829a4372e85da79f16867957a7cfd3..a444f860fbad8d7c6c5afcd1781d662687aad1d9 100755 --- a/composer.json +++ b/composer.json @@ -10,8 +10,16 @@ } ], "require": { + "cweagans/composer-patches": "^2", "drupal/ai": "^1.0", "drupal/core": "^11.1", "1x-contrib-modules/xi_html_markdown": "^1.0" + }, + "extra": { + "patches": { + "drupal/core": { + "[https://drupal.org/i/2476569] - Suppress validation of required fields on ajax calls": "https://www.drupal.org/files/issues/2025-03-18/2476569-ajax-skip-required-fields-validation-53.patch" + } + } } } diff --git a/src/Hook/AiContentSuggestions.php b/src/Hook/AiContentSuggestions.php index 122b1cb3f04ad26ff5b98e50fd482b4886b60edc..c9152fc9ed2e1954430c259ef10b989e4d78edf3 100644 --- a/src/Hook/AiContentSuggestions.php +++ b/src/Hook/AiContentSuggestions.php @@ -138,6 +138,7 @@ class AiContentSuggestions { ], '#ajax' => [ 'callback' => '\Drupal\xi_ai_helper\Hook\AiContentSuggestions::aiContentSuggestionsAjax', + 'suppress_required_fields_validation' => TRUE, ], '#ai_content_suggestion_settings' => $settings, ]; @@ -243,7 +244,10 @@ class AiContentSuggestions { $prompt = $triggering_element['#ai_content_suggestion_settings']['prompt']; // Get the content entity from form object. /** @var \Drupal\Core\Entity\ContentEntityInterface $entity */ - $entity = $form_state->getFormObject()->getEntity(); + $entity = $form_state->getFormObject()->buildEntity($form, $form_state); + if ($entity->isNew()) { + $entity->in_preview = TRUE; + } // Convert entity to markdown. $prompt .= \Drupal::service('xi_ai_helper.entity_to_markdown')->convert($entity); /** @var \Drupal\ai\AiProviderInterface $ai_provider */