Question

Using Drupal 8 Ckeditor Core plugins -> drupalimage/drupalimagecaption how do I make an image caption required? The checkbox shown should always be clicked. enter image description here

Était-ce utile?

La solution

The CKEditor image dialog is a form, so you can change it via Drupal Form API with hook_form_alter:

/**
 * Implements hook_form_alter().
 */
function MyModule_form_alter(&$form, $form_state, $form_id) {
  // Check if the form is editor_image_dialog.
  if ($form_id == 'editor_image_dialog') {
    // Make caption required.
    $form['caption']['#required'] = TRUE;
    // Change default_value to true.
    $form['caption']['#default_value'] = TRUE;
  }
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à drupal.stackexchange
scroll top