By UnsettlingTrend


2016-12-05 18:38:54 8 Comments

Using Drupal 8, the Media module, and the CKEditor that comes with D8. When you add an image media item, you get your screen like this... enter image description here

But that caption field only allows 128 characters. Media (I believe) seems to be setting a maxlength of 128 (maxlength="128"). You can still add more characters if you Embed, then edit the source it supplies, but it's still going to chop off what you've added if you double click on that image (it's technically a drupal-entity element) to bring the "Embed media" window up again.

Since this "Caption" field is not dealing with any kind of data/database storage constraints, 1.) can I change this and 2.) does this even make any sense for it to have a maxlength set?

If anyone has a clue how to change it, that'd be most helpful.

2 comments

@user1108509 2018-08-28 22:37:10

This should do the trick no need to install any module, substituting 500 with whatever you want the limit to be

 function mymodule_form_entity_embed_dialog_alter(&$form, $form_state, $form_id) {
      if(isset($form['attributes']['data-caption'])) {
        $form['attributes']['data-caption']['#maxlength'] = '500';
      }
    }

@UnsettlingTrend 2016-12-07 16:46:50

I ended up installing the maxlength module, and altering the form as such:

function mymodule_form_entity_embed_dialog_alter(&$form, $form_state, $form_id) {
  if(isset($form['attributes']['data-caption'])) {
    $form['attributes']['data-caption']['#maxlength'] = '524288';
    $form['attributes']['data-caption']['#maxlength_js'] = TRUE;
  }
}

Works great! It does create a dependency with the maxlength module, and puts the "limit" on the field (I went with what it said was the "default" of 524288), but other than that 👍

@gcalex5 2018-06-05 16:54:34

What does the maxlength module contribute to the solution? I was able to use the same hook as you and only needed to set the #maxlength attribute to increase the limit past the default.

@UnsettlingTrend 2018-06-07 16:43:07

Sorry, it's been a while. For D7, doesn't the module give all of the associated JavaScript for counting down the number of characters left? And also enforce the validation of it on form submission?

Related Questions

Sponsored Content

1 Answered Questions

Need CKEditor to encode special characters

  • 2017-01-09 16:38:48
  • bemarlan
  • 433 View
  • 1 Score
  • 1 Answer
  • Tags:   8 wysiwyg

0 Answered Questions

Caption field with default value inside CKEditor

  • 2019-05-14 13:56:10
  • Moez Boussetta
  • 18 View
  • 1 Score
  • 0 Answer
  • Tags:   8 media wysiwyg

1 Answered Questions

Creating a caption for images in Drupal 7 Media module

  • 2017-08-31 19:31:48
  • themantimeforgot
  • 107 View
  • 0 Score
  • 1 Answer
  • Tags:   media wysiwyg

0 Answered Questions

Media module tokens vs. HTML in CKEDitor

  • 2016-03-18 18:08:33
  • UnsettlingTrend
  • 186 View
  • 0 Score
  • 0 Answer
  • Tags:   7 media wysiwyg

1 Answered Questions

[SOLVED] Media module - CKEditor embed not working - jQuery is not defined

1 Answered Questions

[SOLVED] Unable to link media in CKeditor

  • 2015-06-01 12:23:55
  • Warren
  • 683 View
  • 3 Score
  • 1 Answer
  • Tags:   media wysiwyg

0 Answered Questions

2 Answered Questions

[SOLVED] CKEditor, Media, & Files — oh my

  • 2013-12-18 23:43:11
  • Beatrice
  • 450 View
  • 0 Score
  • 2 Answer
  • Tags:   files wysiwyg media

0 Answered Questions

2 Answered Questions

[SOLVED] Media + WYSIWYG or ICME + CKeditor

Sponsored Content