Problem/Motivation

Unfortunately, because #3206522: Add FunctionalJavascript test coverage for media library had not yet been ported, we didn't realize until now that captioning and alignment support are still missing from the DrupalMedia CKEditor 5 plugin… only alt override has been ported so far. Still missing: data-caption.

Fortunately #3201646: Add support for image caption (<img data-caption>) provides a pretty clear example of how to implement captioning — but this is done in an image-specific way so could be a bit more tricky

That will allow us to unskip/get passing, respectively:

  1. \Drupal\Tests\ckeditor5\FunctionalJavascript\MediaTest::testEditableCaption()

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Issue fork drupal-3246385

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

Wim Leers created an issue. See original summary.

wim leers’s picture

Title: Add support for captioning and alignment » Support captions and alignment on <drupal-media>
wim leers’s picture

Priority: Critical » Major
wim leers’s picture

Title: Support captions and alignment on <drupal-media> » [drupalMedia] Support captions and alignment on <drupal-media>
Project: CKEditor 5 » Drupal core
Version: 1.0.x-dev » 9.3.x-dev
Component: Code » ckeditor5.module
Issue tags: +Needs tests, +JavaScript

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

lauriii made their first commit to this issue’s fork.

lauriii’s picture

Title: [drupalMedia] Support captions and alignment on <drupal-media> » [drupalMedia] Support captions on <drupal-media>
Issue summary: View changes

Moved alignment to #3260554: [drupalMedia] Support alignment on <drupal-media> because it can be worked separately from captions.

lauriii’s picture

The issue summary also mentions data-view-mode. I think we should open another new issue for that.

bnjmnm made their first commit to this issue’s fork.

wim leers’s picture

nod_’s picture

Status: Active » Needs work

Need rebase at least, currently looking at the code

nod_’s picture

nod_’s picture

At render time this is adding a figcaption element in the frontend without a parent figure element. This is not valid HTML5, spec says it's

<figure>
  <!-- something something -->
  <figcaption></figcaption>
</figure>

// OR

<figure>
  <figcaption></figcaption>
  <!-- something something -->
</figure>

At the moment it's only adding a caption below the image, not sure we want to add more settings to set the caption above or below the image.

As for the validity of the HTML generated I'm guessing this is out of scope. Why are media wrapped in an <article> tag and not <figure>, because the purpose of the figure element seems to match the use we have for embedding media in the body of an article. My mistake, it does it properly.

This is not the case inside the CKEditor instance though: we have

<div class="" contenteditable="false" data-entity-type="media" data-entity-uuid="">
  <article>
    <img>
  </article>
  <figcaption data-placeholder="Enter media caption" contenteditable="true"></figcaption>
</div>

Here the wrapping div should be a figure tag no? that's the case for ckeditor image plugin.

lauriii’s picture

Good point that we need to change the wrapping <div> to <figure> on editing view. Somehow missed that as I was working on this 🤦‍♂️

I'm wondering if we should open a follow-up for figuring out how to configure whether the caption preview should render before or after. We might want to do this for both, <drupal-media> and <img>.

nod_’s picture

The placement of the caption is definitely out of scope for this issue. It's not available in the upstream imagecaption plugin so might make sense to open something upstream first? and see how they do it so we can just copy/paste :D

lauriii’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests
nod_’s picture

Thanks for the explanations lauriii, this looks good to me now.

wim leers’s picture

Status: Needs review » Needs work

Manually tested, works perfectly.

Reviewed MR in detail. Three main concerns:

  1. From Enter caption here in CKE4 to Enter media caption in CKE5 — why?
  2. Copy/pasting comments from the CKE4 test coverage would help make the tests maintainable/understandable.
  3. There is some test coverage that \Drupal\Tests\media\FunctionalJavascript\CKEditorIntegrationTest::testEditableCaption() has that this does not yet. Porting it should be pretty easy. And then we can be extra confident.
wim leers’s picture

Issue tags: +Needs followup

Once a follow-up exists for https://git.drupalcode.org/project/drupal/-/merge_requests/1736#note_71991, I think this is RTBC :)

lauriii’s picture

Status: Needs work » Needs review

@Wim Leers I've added similar test coverage that works around the limitations we have on selecting text in CKEditor. Wondering if you think we still need the follow-up after this?

wim leers’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: -Needs followup

Yes, I agree that's a reasonably equivalent piece of test coverage! Well done! 👏🥳

I just left one tiny remark, but even that is not commit-blocking.

lauriii’s picture

bnjmnm’s picture

Status: Reviewed & tested by the community » Needs work

Switching to NW due to a failing test that is part of the MR and not one of those randoms we run into at inopportune times.

bnjmnm’s picture

BTW I'm not getting the test failure locally, sharing the CI output since it took a very time to load and I want to save people that step:

Drupal\Tests\ckeditor5\FunctionalJavascript\MediaTest::testEditableCaption
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'Llamas are the most awesome ever'
+'Llamas are the most awesome ever'

/var/www/html/vendor/phpunit/phpunit/src/Framework/Constraint/Equality/IsEqual.php:96
/var/www/html/core/modules/ckeditor5/tests/src/FunctionalJavascript/MediaTest.php:371
/var/www/html/vendor/phpunit/phpunit/src/Framework/TestResult.php:726
lauriii’s picture

Status: Needs work » Needs review

That was indeed failing 9/10 times on DrupalCI... I think I managed to fix that. I ran this 50x on #2488258-195: [ignore] Patch testing issue.

wim leers’s picture

Status: Needs review » Reviewed & tested by the community

Holy crap! :O chromedriver madness strikes again. 😬

#2488258-195: [ignore] Patch testing issue is very convincing.

(And that last commit also addressed the tiny nit I still had: https://www.drupal.org/project/drupal/issues/3246385#mr1736-note72324 👍)

lauriii’s picture

StatusFileSize
new113.61 KB
new113.89 KB
lauriii’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs reroll
nod_’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
StatusFileSize
new119.87 KB

D10 reroll, working on 9.4

nod_’s picture

StatusFileSize
new120.16 KB

D9

lauriii’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new119.27 KB
new119.55 KB

There was a small problem with the CSS caused by the reroll in #31 which I fixed on MR and here's that again as patches.

lauriii’s picture

StatusFileSize
new119.49 KB
new119.77 KB
lauriii’s picture

StatusFileSize
new119.74 KB
new120.02 KB

  • bnjmnm committed 4191464 on 10.0.x
    Issue #3246385 by lauriii, nod_, Wim Leers: [drupalMedia] Support...

  • bnjmnm committed f8136d4 on 9.4.x
    Issue #3246385 by lauriii, nod_, Wim Leers: [drupalMedia] Support...

  • bnjmnm committed 2a2a662 on 9.3.x
    Issue #3246385 by lauriii, nod_, Wim Leers: [drupalMedia] Support...
bnjmnm’s picture

Version: 9.4.x-dev » 9.3.x-dev
Status: Reviewed & tested by the community » Fixed

Very nice to see Media captions! Excellent addition.

Committed to 10.0.x/9.4.x and cherry-picked to 9.3.x as CKEditor 5 is experimental.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.