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

Was it helpful?

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;
  }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with drupal.stackexchange
scroll top