I can not assign a class to the img element using the new "Styles Dropdown" for the relevant CKEditor profile. I can do so with block or inline elements, such as h1 or span elements.

Steps to replicate

  1. Navigate to "Configure" the "Full HTML" text format profile at admin/config/content/formats/manage/full_html
  2. Under "Toolbar Navigation" drag the "Style" dropdown menu into the active toolbar
  3. This will add a new vertical navbar to the profile page, "Styles Dropdown"
  4. Create a rule for an image element, i.e., img.testStyle|Test Style and save the configuration update
  5. Create a new "Base page" node and add an image to the body field
  6. Select the image either by directly clicking it or by using the CKEditor element selector in the ckeditor pane footer (the span#cke_1_bottom region) The styles button remains inactive

Note: If I change "img.testStyle|Test Style" to "image.testStyle|Test Style" I can apply the style through the styles dropdown, but CKEditor will wrap the img element in an image element, which itself will be "corrected" to two img tags.

Original markup:
<p><img alt="test" data-entity-type="file" data-entity-uuid="558bfafa-8b58-4c18-b529-41a58a53c795" src="/sites/default/files/inline-images/take-two.JPG" /></p>

Applied markup:
<p><image class="testStyle"><img alt="test" data-entity-type="file" data-entity-uuid="558bfafa-8b58-4c18-b529-41a58a53c795" src="/sites/default/files/inline-images/take-two.JPG" /></image></p>

"Corrected" markup:
<p><img class="testStyle" /><img alt="test" data-entity-type="file" data-entity-uuid="558bfafa-8b58-4c18-b529-41a58a53c795" src="/sites/default/files/inline-images/take-two.JPG" /></p>

Comments

Screenack created an issue. See original summary.

wim leers’s picture

Assigned: Unassigned » mac_weber

Thank you for your very thorough, very clear issue! I wish all issues were as clear as this one :)


This requires rather deep CKEditor knowledge. I suspect the answer is going to be something like Images in Drupal's CKEditor are handled by a CKEditor Widget, and to style widgets, you need widget styles, whereas Drupal's integration with the Styles dropdown currently only supports block and object styles..

See http://docs.ckeditor.com/#!/guide/dev_styles-section-style-types.

Pinging @mlewand.

wim leers’s picture

Assigned: mac_weber » Unassigned

Oops.

mlewand’s picture

Assigned: Unassigned » mlewand

I'll take a look on it this week.

Screenack’s picture

mlewand’s picture

It all depends on how img.testStyle|Test Style string is translated into config.stylesSet property. For a standard element it would be translated into something like:

{ name: 'Test Style', element: 'img', attributes: { 'class': 'testStyle' } },

Which is not enough for a widget. According to docs widget requires two different properties: type and widget. So in your case this expression should be translated into a following object:

{ name: 'Image decoration', type: 'widget', widget: 'image', attributes: { 'class': 'testStyle' } }

Just like I did in this demo: https://jsfiddle.net/cddgs15x/

wim leers’s picture

Issue summary: View changes
StatusFileSize
new24.54 KB

#6: Please read #2 again. Then look at the screenshot I uploaded here:

Then the question becomes: How can we let users configure the available styles in a simple way yet also let them target elements that are always transformed in a widget?

In other words, we do not want to complicate the syntax/configuration UI shown in that screenshot, but we do want this to work.


Note: In Drupal's CKEditor, all <img> elements are transformed into a widget. Why can't CKEditor then apply this reasoning automatically:

  1. All <img> become image widgets.
  2. The user has configured { name: 'Test Style', element: 'img', attributes: { 'class': 'testStyle' } }
  3. Therefore (through CKE's reasoning) the above style is automatically also applied to image widgets, i.e. it auto-generates { name: 'Test style', type: 'widget', widget: 'image', attributes: { 'class': 'testStyle' } }, and treats is as one and the same as the above.
wim leers’s picture

Title: Can not apply an img rule using CKEditor's Styles Dropdown » CKEditor Style for <img> not working because it is an "image" widget
Version: 8.0.1 » 8.0.x-dev
Issue tags: -CKEditor in core, -styles, -dropdown menu +CKEditor Widgets

Clarifying title.

mlewand’s picture

The reason for it is that you don’t know what markup widget will produce. For example image2 widget produces <img> element, or a <figure> depending if you want to include caption or not. Also a different API needs to be called when you’re applying/removing styles to a widget.

If you wish to avoid adding widget information to styleSet rules, and provide a way to tell that img rules are always accepted by all widget instances of given type, you could play around and add your custom style handler that would essentially play as a proxy to default style methods. So that it detects styles for <img> elem, and if image widget is focused it will tell that “it’s fine to apply this style”, and will implement proper apply/remove style. In any other case, it will just call default style implementation.

mlewand’s picture

Assigned: mlewand » wim leers
wim leers’s picture

Assigned: wim leers » mlewand

The reason for it is that you don’t know what markup widget will produce. For example image2 widget produces <img> element, or a <figure> depending if you want to include caption or not. Also a different API needs to be called when you’re applying/removing styles to a widget.

This doesn't make sense, because:

  1. You could always add the class to the outer element, i.e. <img> or <figure>
  2. Most importantly, in Drupal 8, image2/drupalimage always results in a <img> tag after downcasting.

If you wish to avoid adding widget information to styleSet rules, and provide a way to tell that img rules are always accepted by all widget instances of given type, you could play around and add your custom style handler that would essentially play as a proxy to default style methods. So that it detects styles for <img> elem, and if image widget is focused it will tell that “it’s fine to apply this style”, and will implement proper apply/remove style. In any other case, it will just call default style implementation.

Sounds great! Could you provide a prototype implementation of that? Let's give it a type of 'drupalimage'.

wim leers’s picture

katannshaw’s picture

I'm having the same issue for my client as the OP when trying to add two Bootstrap 3 responsive classes like this:

img.img-responsive|Responsive Image
table.table|Responsive Table

I was excited to see the setting but bummed that it wasn't working properly. I'm here to test patches out when ready because we really need this feature as well.

wim leers’s picture

Priority: Normal » Major

#13: To be clear, table.table is working correctly, right? (Strange classname BTW!) Also note that for Responsive Images, we have #2061377: [drupalImage] Optionally apply image style to images uploaded in CKEditor 5, which has a patch.

Thanks for helping to show that this issue is actually important! I'm increasing its priority to Major. This issue is currently blocked on the CKEditor team.

katannshaw’s picture

Hi @Wim: No it's not working at all. After setting it up, when I select an image or text within the editor, the "Styles" dropdown becomes disabled and I cannot select either of the classes I've added in config. Here's a screenshot:

For the class names, that's what Bootstrap has for making their tables and images responsive.

<table class="table" ...
<img class=img-responsive" ...
wim leers’s picture

Can you please export the relevant text format & text editor and post it here?

katannshaw’s picture

katannshaw’s picture

"Can you please export the relevant text format & text editor and post it here?"

I'm not sure how you export it but here's the relevant info: Drupal 8 CKEditor Full HTML. Here are 2 screenshots of the settings.

wim leers’s picture

You can export them at /admin/config/development/configuration/single/export :) You get YAML there, that you can post here, which I can then import and reproduce exactly what you are seeing. One of the big Drupal 8 wins :)

katannshaw’s picture

StatusFileSize
new1.28 KB

Very cool! That's how we learn. I"m still learning D8. Here you go.

wim leers’s picture

:) Can you also export filter.format.full_html.yml?

katannshaw’s picture

StatusFileSize
new1.18 KB

Sure. Thanks for your help.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

amazingrando’s picture

Has there been any progress made on this issue? I'm working on a project and this is a blocker. Thanks!

Greg Garner’s picture

Yes, please give an update on this. Not being able to style images with the WYSIWYG is a big deal.

FYI, when I enter:
image.img-border|Bordered Image

It at least shows up under styles when an image is clicked. But nothing is applied.

kevinwal’s picture

Could we just have generic classes or a wildcard option that allows for a class to be applied to anything? In situations like this wouldn't we just want to apply a class?

xem8vfdh’s picture

+1, I'm here for the exact same reason as @jayhawkfan75 (#13). Thanks everyone for the work above. Looks like progress was being made, so I too am curious about an update on this.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

wim leers’s picture

Sorry, I lost track of this issue.

@jayhawkfan75 (#13#22): your allowed_html setting lists <table>. It needs to be modified to <table class="table">.

For the image case, that is an upstream bug in CKEditor per #9 + #11.

I pinged the CKEditor team again, specifically for:

Sounds great! Could you provide a prototype implementation of that? Let’s give it a type of 'drupalimage'.

xem8vfdh’s picture

and we're back, thanks @Wim Leers for jumping in!

benstjohn’s picture

I'm still seeing this issue - for me if I view the source and remove the data-entity-uuid property it works as expected. Can anyone shed more light on this?

wim leers’s picture

@benstjohn: the entire explanation can be found in the comments above ;)

mlewand’s picture

The reason for it is that you don&rsquor;t know what markup widget will produce. For example image2 widget produces <img> element, or a <figure> depending if you want to include caption or not. Also a different API needs to be called when you&rsquor;re applying/removing styles to a widget.

This doesn't make sense, because:

You could always add the class to the outer element, i.e. <img> or <figure>

That'd be true as long as widget downcasts to an element - there's nothing wrong with downcasting widget into a text, e.g. our placeholder plugin does just that. In addition to that you don't want to create styles that apply to every element.

Most importantly, in Drupal 8, image2/drupalimage always results in a <img> tag after downcasting.

CKE core can't know it, because downcasting is a method that is highly dependent on widget state as mentioned previously.

I've checked how we could add a custom styles handler to implement this, but it's actually way overcomplex - not worth going this way.

Looking again, after all this time we missed the obvious and simplest solution: while converting your custom format like:

img.img-responsive|Responsive Image
table.table|Responsive Table

You can check rule tag name, if it's img then translate rule into:

{ name: 'Rule name', type: 'widget', widget: 'drupalimage', attributes: { 'class': 'providedClass' } }

Rather than regular:

{ name: 'Rule name', element: 'img', attributes: { 'class': 'providedClass' } }

That fixes the problem.

mlewand’s picture

Assigned: mlewand » Unassigned
wim leers’s picture

I've checked how we could add a custom styles handler to implement this, but it's actually way overcomplex - not worth going this way.

This is what I feared/expected, which is why I asked for a sample implementation to get us started.

You can check rule tag name, if it's img then translate rule into:

{ name: 'Rule name', type: 'widget', widget: 'drupalimage', attributes: { 'class': 'providedClass' } }
Rather than regular:

{ name: 'Rule name', element: 'img', attributes: { 'class': 'providedClass' } }
That fixes the problem.

It fixes it in the default setup. But it's possible to disable the drupalimage plugin and use a different one. Then this won't work. This is why I was so interested in what you wrote at #9: I was very enthusiastic about that in #11.

So… would it be okay for us to generate both of those rules? The problem would be that CKEditor would be showing two separate styles, would it not?

mlewand’s picture

It fixes it in the default setup. But it's possible to disable the drupalimage plugin and use a different one. Then this won't work. This is why I was so interested in what you wrote at #9: I was very enthusiastic about that in #11.

True, and I suppose you can't do magic to tell if drupalimage is loaded or not, because compilation from the text format to object format happens when you save what is visible on CKE styles configuration.png.

So… would it be okay for us to generate both of those rules? The problem would be that CKEditor would be showing two separate styles, would it not?

CKEditor will hide the rules that are not matched for current selection - so this would work.

awasson’s picture

@mlewand, I've been struggling with this for a while as well. I don't understand what is meant in your post #33:

Looking again, after all this time we missed the obvious and simplest solution: while converting your custom format like:

img.img-responsive|Responsive Image
table.table|Responsive Table
You can check rule tag name, if it's img then translate rule into:

{ name: 'Rule name', type: 'widget', widget: 'drupalimage', attributes: { 'class': 'providedClass' } }
Rather than regular:

{ name: 'Rule name', element: 'img', attributes: { 'class': 'providedClass' } }
That fixes the problem.

The class entries are self explanatory but the part: You can check rule tag name, if it's img then translate rule into ...

I don't follow... Are you referring to something within the UI or patching the CKEdit core module or a CKEdit plugin?

Thanks.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

kferencz91’s picture

Has there been any progress with this? This is a huge deal for us - not being able to add specific classes to images through the WYSIWYG and being forced to go into the source code is a big roadblock for many of our use cases.

awasson’s picture

Agreed with kferencz91 on post #39. This is a pretty major concern.

I'll contribute to the solution be will need some direction to get going on it.

awasson’s picture

Ok, just circling around to this issue again.... I'm not sure if it's critical but it's highly frustrating now that I have half a dozen production sites live and can't effectively apply styles to images.

Three months ago @mlewand came up with a solution in post #33 but I don't know where to apply it. I assume that this has something to do with CKEdit's Styles Declaration file? Can someone pipe in with some direction.

Appreciate it.

Andrew

wim leers’s picture

awasson’s picture

@Wim Leers, do you know what @mlewand had in mind for a solution for this? I'm beating my head into a wall while my clients are snapping at me because we can't apply responsive classes to our images.

awasson’s picture

Ok, since there's seems to be no fix for this bug in the past year and a a bit, it's time for a workaround.

I've managed to workaround this issue by installing the IMCE module with the following settings on the ckeditor configuration page:

I've also enabled filters for the following but they may have no effect on this workaround:

  • Align images
  • Caption images
  • Track images uploaded via a Text Editor

Note: I've found in my testing that you'll need to leave the existing Drupal image widget on the toolbar because the workaround does not seem to work if it's removed.

With the IMCE image widget I can of course upload and manage images but it also allows me to select images and apply classes to them regardless of whether they were added to the site through the included image tool or IMCE's image tool. This has been shown to work with the full "Edit" admin screen as well as from the "Quick Edit" mode. Best of all, it does the job right and once someone fixes the issue, there will be no need to undo any of these config settings. This is the way it should work.

I've got this working in a couple of sites now. Ping me back if you can't get it to work and I'll try to help pointing interested parties in the right direction.

awasson’s picture

Related Issue

I've found a related issue/bug with the Drupal <image> widget (and workaround) so I'll post it here as it may come in handy for those following this issue.

The issue is that is that the <image> widget inside ckeditor will not apply links to images correctly. If I select an image and then use the link tool to apply a link to an image, the link will be added as a text link beside the image, rather than a link that wraps the image.

The Workaround

The <img> widget in ckeditor works just fine so the workaround is to again use the IMCE image tool to place images. They will be handled within ckeditor as a regular image instead of the Drupal <image> widget.

If you run into an instance where the images are being handled by the <image> widget because they were placed by the native Drupal 8 ckeditor image tool or where the content was brought in via a migration, you'll need to strip the image tags in the html markup of their data-entity attributes. Then they will be handled as regular images and everything will be good.

tomatkins’s picture

Issue tags: +Baltimore2017

I'm Triaging this at Baltimore DrupalCon 2017.

tomatkins’s picture

Version: 8.3.x-dev » 8.4.x-dev
Issue tags: +Needs issue summary update

Tested in Drupal 8.4 dev, 8.3.1 and 8.1.10.
I was able to replicate this issue and I verify that this issue needs a Needs an issue summary update and fix.

If the class is written as "img.testStyle|Test Style" in (admin/config/content/formats/manage/full_html) the style drop down will be unclickable/faded out when the image is selected.

If the class is written as "image.testStyle2|Test Style 2", the style dropdown is still visible when the image is selected.
Upon saving the content with the image, the code is "corrected" into "img" as included below.

Here is the code as reproduced on 8.4:

<p><image class="testStyle2"><a href="http://www.highstrungpro.com"><img alt="fun image" data-entity-type="file" data-entity-uuid="0d8933b1-07cb-4abf-9935-9947d96f906e" src="/sites/drupal84.dd/files/inline-images/allavailable_5.png" /></a></image></p>

and then on save:

<p><img class="testStyle2" /><a href="http://www.google.com"><img alt="fun image" data-entity-type="file" data-entity-uuid="35846eb3-79a9-41d1-adf6-988197316e1e" src="/sites/drupal84.dd/files/inline-images/allavailable_4.png" /></a></p>

Here is the code as reproduced on 8.3:

<p><image class="testStyle2"><a href="http://www.google.com"><img alt="fun image" data-entity-type="file" data-entity-uuid="807c287b-7d4e-4ed2-a3c7-9849e9f232c7" src="/sites/drupal831.dd/files/inline-images/allavailable_3.png" /></a></image></p>

and then once saved:

<p><img class="testStyle2" /><a href="http://www.google.com"><img alt="fun image" data-entity-type="file" data-entity-uuid="807c287b-7d4e-4ed2-a3c7-9849e9f232c7" src="/sites/drupal831.dd/files/inline-images/allavailable_3.png" /></a></p>

As run on 8.1 :

<p><image class="testStyle2"><a href="http://www.google.com"><img alt="fun image" data-entity-type="file" data-entity-uuid="3166c436-3d5d-4836-b381-f0c74b867665" src="/sites/d8.dd/files/inline-images/allavailable_2.png" /></a></image></p>

and then once saved:

<p><img class="testStyle2" /><a href="http://www.highstrungpro.com"><img alt="Test Image" data-entity-type="file" data-entity-uuid="2f290368-0a19-42eb-8199-e5a105cf701c" src="/sites/d8.dd/files/inline-images/allavailable_0.png" /></a></p>

Important note: The process I went thru was the same as on the list, which is uploading the image, adding a link and then adding the style. The style was not visible unless the class was called "image.testStyle...." DONT SKIP ANY STEPS (I forgot to create a content type of "Base Page" initially.)

tomatkins’s picture

Issue tags: -Needs issue summary update +needs initial patch

Correcting previous post - summary is excellent - I am verifying that the problem exists and needs a patch. I have not tested the workaround.

mjchadwick’s picture

I can also confirm that the issue remains (only tested it on 8.4-dev so far), and acts like @tomatkins reported in #47.

However, instead of the Styles dropdown being unclickable/faded-out, the dropdown is enabled, but the broken style doesn't display (the whole Inline Styles section is missing). Also, the missing section doesn't display regardless of which element you try to apply it to, rather than just images.

tomatkins’s picture

cilefen’s picture

I am updating credit for the triage work. @tomatkins (and anyone): When doing issue triage, please be sure to complete and document all steps of the triage. In this case, I haven't seen whether there was a search for duplicate issues, and the issue hasn't been given the triage tag.

It would be great if we could get those things finished on this issue. I feel you did some good work so I credited you.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

nickdickinsonwilde’s picture

There is a workaround that works very easily - just use span instead of image.
So in editor config:
span.image-round|Styled image
and in your css:

.image-round img {
  border-radius: 50%;
}

Obviously that isn't ideal because it isn't good DX with no information.

However, an easy fix would be to add that to documentation *and* in place help/examples.
If that seems like a decent approach given that a proper fix/improved integration with ckeditor would be much more time consuming, I can toss up a patch this afternoon with that.

tomatkins’s picture

That would be awesome Nick!!!!

nickdickinsonwilde’s picture

Version: 8.5.x-dev » 8.4.x-dev
Status: Active » Needs review
StatusFileSize
new1.52 KB

Here is a patch that provides an in-place documentation improvement.
It doesn't remove the problem per se but it does suggest a fully functional work around. The *only* negative to using the workaround is one extra span element per use. So very minimal.
Given that this is a documentation only fix rather than a fix for the underlying issue, I believe that it may be back patchable to 8.4 still.

oriol_e9g’s picture

Status: Needs review » Reviewed & tested by the community

I think that we can commit this documentation improvement and then reopen for a better fix, if it's possible.

wim leers’s picture

Title: CKEditor Style for <img> not working because it is an "image" widget » [upstream] CKEditor Style for <img> not working because it is an "image" widget
Status: Reviewed & tested by the community » Needs review
Issue tags: -needs initial patch +Needs upstream bugfix
StatusFileSize
new1018 bytes
new39.44 KB

I'm not sure documenting a work-around is a good solution.

This is still really kind of a bug in CKEditor itself, which is why I've involved @mlewand from the CKEditor team. It's unfortunate they haven't fixed this yet — I think it's quite natural that any styles for <img> should also work for the Image widget.

So until they fix this upstream, I'd then much rather add a work-around like #33 to Drupal core. That's what the attached patch does. Unfortunately, it still doesn't work. Pinged @mlewand again.

Screenshot of the auto-generated Image widget rule:

(This demonstrates that this does what http://docs.ckeditor.com/#!/guide/dev_styles-section-widget-styles prescribes: widget – Must be set to the name of the widget to which this style will be applicable. Widget names can be verified by browsing the editorInstance.widgets.registered object in your browser's developer tools.)

sic’s picture

hey guys, any idea when there will be any progress on this?

gifad’s picture

FWIW, I added the following snippet in the drupalimage/plugin.js :

init: function(editor) {
  $.each(editor.config.stylesSet, function(i, style) {
    if (style.element == "img") {
      delete style.element;
      style.type = "widget";
      style.widget = "image";
    }
  });
},

It's not a generic solution, but it just works…

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

amaisano’s picture

Is this still the correct/current issue for this on the upstream repo?

https://dev.ckeditor.com/ticket/16998

It seems they moved to github but I was unable to find a matching ticket there. Should we add one to their new backlog?

See https://github.com/ckeditor/ckeditor-dev/issues?utf8=%E2%9C%93&q=is%3Ais...

socialnicheguru’s picture

StatusFileSize
new65.62 KB

I got the following on the first save of content when adding an image using the image widget in ckeditor.
On the second save I got the image.

Anonymous’s picture

Hi all.
FYI, my experience with this... I researched for a couple of days for a fix for this img class issue until I found this thread.
I applied patch #57 and then when I added the img class in the styles dropdown it gives the error "Each style must have a unique label."
I don't know exactly why it shows it because I don't have any identical labels and I also tested it with just one line and still the same error.
So I went and commented the line 107 and then the error was obviously gone.

if (count($style_names) !== count(array_unique($style_names))) {
    $form_state->setError($element, $this->t('Each style must have a unique label.'));
}

The good part is the patch actually works and the class was added to the <img> tag correctly.
Another little issue is that (in my case at least) I got 2 entries of that class in ckeditor styles menu.

So my thoughts are:
- Is it ok to comment that "if" to get read of the error? Is there another way to keep the validation but not get the error?
- Why is that class twice in the menu? Can it be fixed?

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

s427’s picture

I also applied patch #57, which solved the initial problem but introduced a new one. Now when trying to make any modification on the text format config page (e.g. admin/config/content/formats/manage/full_html), I get the error "Each style must have a unique label." upon saving.

I don't see any duplicate label in my "styles dropdown" field.
If I empty the "styles dropdown" field, then I am able to save the page.
If I undo the patch, then I am also able to save the page (without the need to empty the "styles dropdown" field).

With the patch applied, I tried removing the styles I'm using one by one, and it seems the problem specifically occurs if there are styles targeting the <img> tag.

E.g. even if I only have this style (and nothing else):
img.img-left|Image left
I get the error "Each style must have a unique label."

But if I change it to
p.img-left|Image left

Then I get no error.

(I'm using Drupal 8.6.1)

Anonymous’s picture

StatusFileSize
new935 bytes

To prevent the the error "Each style must have a unique label." upon saving, use this patch.

gaspounet’s picture

Hello all,

I'm using Drupal 8.6.5 and patches #57 and #66 are not working for me.

But strangely, if I switch to another content format from the filter list for my text field while editing and switch back to the previous format, the image style now appears in the dropdown menu (only when you select an image in the editor, it remains hidden otherway).

OK I found it, the image style doesn't appear in the dropdown menu if you click on the image but only if you select the image

https://imgur.com/a/obpXHfE

yojohnyo’s picture

We are using Drupal 8.8.1 and still experiencing this problem. I tried applying patch #66 with no luck.

mmaranao’s picture

StatusFileSize
new923 bytes

We were having the same issue on Drupal 8.8.1 and patch #66 does work for us!
I've modified the patch to remove the suffix 'Widget' and only keep the name as per the configuration

chris burge’s picture

Re #50, https://dev.ckeditor.com/ticket/16998. CKEditor moved its issues to GitHub and this ticket was not migrated. As far as the CKEditor project is concerned, this issue no longer exists.

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

sayco’s picture

The patch #69 is buggy. I can't understand what removing the phrase ' Widget' could cause (maybe some name uniqueness), but it now does not allow to save the text format form.
I reverted the patch and use the one from #65 which works like a charm.

kristen pol’s picture

Version: 8.9.x-dev » 9.1.x-dev
Status: Needs review » Needs work
Issue tags: +Bug Smash Initiative

Both patches from #69 and #66 (file says it's for comment 65) apply cleanly to 9.1.x.

Back to needs work for nitpicks as there are some extraneous spaces noted below. If you update this, look at comment #73 to decide which patch you want to update.

+++ b/core/modules/ckeditor/src/Plugin/CKEditorPlugin/StylesCombo.php
@@ -161,6 +161,17 @@ protected function generateStylesSetSetting($styles) {
       $styles_set[] = $configured_style;
+      ¶
+++ b/core/modules/ckeditor/src/Plugin/CKEditorPlugin/StylesCombo.php
@@ -161,6 +161,17 @@ protected function generateStylesSetSetting($styles) {
+      }
+      ¶
awasson’s picture

Is it me, or is it weird that after almost 5 years this is still an unresolved issue ¯\_(ツ)_/¯

Three years ago, on #45 I commented that a workaround was to use the IMCE CKEditor image plugin because it had a flaw that didn't respect CKEditor's img / image behaviour... Well, in the ensuing years IMCE have fixed that flaw and now that workaround is no longer effective.

For a longer-term workaround (hopefully), I've put together a Drupal 8/9 StylesCombo plugin that is a clone of the original and uses the excellent patch from #65. Working out the conflicts and requirements was a major pain in the butt so hopefully others can benefit from my efforts and the efforts of the patches in the issue queue. You can find it here: https://www.drupal.org/project/stylescomboplus

Cheers,
Andrew

Sorry, I had to edit it because I had put in image and img tags in my original response.

xem8vfdh’s picture

Is it me, or is it weird that after almost 5 years this is still an unresolved issue ¯\_(ツ)_/¯

For sure. It's a huge pain for our content editors, and I feel like a complete dunce when all I can offer them is... ¯\_(ツ)_/¯

Sorry, I had to edit it because I had put in image and img tags in my original response.

lol

fkelly12054@gmail.com’s picture

Is it me, or is it weird that after almost 5 years this is still an unresolved issue ¯\_(ツ)_/¯

@awasson. I'll be the second person in a row to quote you. Despite many efforts by developers with skills well beyond mine, this has never been resolved. Like many things Drupal, no one really is in charge. The downside of Open Source I suppose.

By the way I use IMCE all the time to insert images into my content. It works just fine as far as I can see. I upload hundreds, if not thousands of jpgs as part of photo galleries that are presented using the Juicebox contrib module. I use a FTP client (Beyond Compare) and have a "structured" set of directories for my Galleries (images and thumbnails). I can browse those directories with IMCE very easily to select images for my article content type. I'll look at stylescomboplus as a possible enhancement. Thanks.

awasson’s picture

@fkelly,
Sorry I probably didn't explain my motivation with regard to IMCE very well.

My reference to IMCE is only that it used to be a viable workaround for this particular issue; when you needed the ability to place an image within your CKEditor and then apply CSS classes to the image.

IMCE used to have a "flaw" that prevented IMCE placed images to undergo the IMG to IMAGE transformation within CKEditor and therefore we could apply classes to them. That was fixed recently which lead me to look at alternative workarounds.

Eventually I hope this issue will be resolved in Core and my utility module won't be necessary. In the meantime It seems to be a good bandaid and doesn't require modifying Drupal or CKEditor itself.

Cheers,
Andrew

awasson’s picture

Hey all,

Now that I've got a workaround for this, I'm reviewing the issue a little further to see what's preventing us from resolving it within Drupal core and I'm reminded that it's actually a problem with CKEditor.

In patch #50 @tomatkins references a CKEditor issue he logged (https://dev.ckeditor.com/ticket/16998) but that was a few years ago and when CKEditor moved to GitHub, that issue doesn't appear to have been migrated to their new queue.

There is an issue in the CKEditor queue on Github that covers the same problem and it had a lot of activity but it appears to have become frozen for some reason. I just added a comment to ask if it has been resolved: https://github.com/ckeditor/ckeditor4/pull/1681

Cheers,
Andrew

xem8vfdh’s picture

Thanks @awasson for doing the detective work and keeping us updated!

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

thatguy’s picture

I'm having this issue and found out that I can get the styles applied to normal image with the patch from #66 or adding custom style such as 'p.image-with-border|Image with border' which will wrap the image in p-tag and I can then use to style the image.

However neither of these solutions seem to work when I want to add an image caption and the image element is turned into figure-element with the image inside it. I have tried adding custom style such as 'figure.image-with-border|Image with border' which I can apply to the image but the class is not added. I also tried modifying the provided patch to work with figure-element but no luck.

Is there currently any solution how I could add the possibility to add style to image with caption and have the class apply correctly either to the figure-element or to the img-element inside it?

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

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

joao.ramos.costa’s picture

For those who might be interested, for the workaround, inspired by #57 I've extended the plugin class. but I still had to keep the element field for "img". (8.9.x) .

        $widget_styles[] = [
          'element' => 'img',
          'name' => $style['name']. ' (image)',
          'type' => 'widget',
          'widget' => 'image',
          'attributes' => $style['attributes'],
        ];

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.

idebr’s picture

StatusFileSize
new9.61 KB

I can conform the 'element' => 'img' is required to have the Styles show up.

Attach patch is the workaround of #84 that can be applied with composer patches.

idebr’s picture

StatusFileSize
new953 bytes
anneke_vde’s picture

I tested the patch from #87 and I can now choose a style from the dropdown.

gaspounet’s picture

I confirm that patch #87 is working on my Drupal 9.3.5 website, thank you (finally, 6 years later) !

simgui8’s picture

#87 works for me too.

simgui8’s picture

Status: Needs work » Needs review
simgui8’s picture

We should be close to RTBC right?

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

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

amin.ankit’s picture

Assigned: Unassigned » amin.ankit
amin.ankit’s picture

Assigned: amin.ankit » Unassigned
ameymudras’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new59.79 KB
new466.19 KB
new465.61 KB

Tested on Drupal 9.5.x and php 8.1

- The issue summary is clear and explains the issue along with testing steps
- Was able to replicate the issue using steps provided
- The patch applies cleanly & fixes the issue please see the screenshots provided
- No notices / warnings in the logs too.

Changing the status to RTBC

quietone’s picture

Project: Drupal core » CKEditor 4 - WYSIWYG HTML editor
Version: 9.5.x-dev » 1.0.x-dev
Component: ckeditor.module » Code

CKEditor has been removed from core, CKEditor 4 is removed from Drupal Core in 10.0.0