public static function CKEditor5::assessActiveTextEditorAfterBuild in Drupal 10
Form #after_build callback: provides text editor state changes.
Updates the internal $this->entity object with submitted values when the form is being rebuilt (e.g. submitted via AJAX), so that subsequent processing (e.g. AJAX callbacks) can rely on it.
See also
\Drupal\Core\Entity\EntityForm::afterBuild()
File
- core/
modules/ ckeditor5/ src/ Plugin/ Editor/ CKEditor5.php, line 509
Class
- CKEditor5
- Defines a CKEditor 5-based text editor for Drupal.
Namespace
Drupal\ckeditor5\Plugin\EditorCode
public static function assessActiveTextEditorAfterBuild(array $element, FormStateInterface $form_state) : array {
// The case of the form being built initially, and the text editor plugin in
// use is already CKEditor 5.
if (!$form_state
->isProcessingInput()) {
$editor = $form_state
->get('editor');
$already_using_ckeditor5 = $editor && $editor
->getEditor() === 'ckeditor5';
}
else {
// Whenever there is user input, this cannot be the initial build of the
// form and hence we need to inspect user input.
$already_using_ckeditor5 = FALSE;
NestedArray::getValue($form_state
->getUserInput(), [
'editor',
'settings',
'is_already_using_ckeditor5',
], $already_using_ckeditor5);
}
$form_state
->set('ckeditor5_is_active', $already_using_ckeditor5);
$form_state
->set('ckeditor5_is_selected', $form_state
->getValue([
'editor',
'editor',
]) === 'ckeditor5');
// Disable inline form errors when using CKEditor 5 because it prevents
// useful error messages from vertical tabs from being visible to the user.
// @todo Remove this workaround in
// https://www.drupal.org/project/drupal/issues/3263668
if ($form_state
->get('ckeditor5_is_selected')) {
$element['#disable_inline_form_errors'] = TRUE;
}
return $element;
}