I think there are already lots of issues and documentation covering the fact that the Xss filter will ignore on* and style attributes. Since that is the case, I think the "Alignment" under "Image Properties" (after double clicking an image within a text edit field) should be re-worked. Right now, if I select the "Right" blip in the Alignment section of Image Properties, for example, the result is to add style="float:right" to the image tag's HTML. Because of this, the alignment options only work if the "Text Format" is set to "Full HTML", or if the "Limit allowed HTML tags and correct faulty HTML" box is unchecked when using an alternate Text Format.

To resolve the problem, couldn't the "Alignment" options instead add a simple css class to the image HTML (example: .float-right), and Drupal core CSS could handle floating these classes appropriately (example: .float-right {float: right;})? This would allow the alignment options to work for all Text Formats, assuming the site administrator has enabled <img class> in the "Allowed HTML tags" field if using "Limit allowed HTML tags and correct faulty HTML".

I don't see how this solution would go against any Drupal policies. But, if for whatever reason this is unacceptable, and there is no acceptable solution, I think that at the very least the Alignment settings shouldn't be shown in "Image Properties" when the "Text format" is using "Limit allowed HTML tags and correct faulty HTML", as they are simply misleading and confusing in this context currently.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

xeM8VfDh created an issue. See original summary.

xeM8VfDh’s picture

Issue summary: View changes
Wim Leers’s picture

Category: Bug report » Support request
Status: Active » Postponed (maintainer needs more info)

HUH!???!!

Can you please record a video showing this? What I see, is class="align-right" being added.

Also, how are you even seeing Image Properties? That's something that lives in CKEditor's native image dialog, which Drupal does not use. That'd explain why you're seeing floats; you should be seeing Drupal's own image dialog for CKEditor, not CKEditor's default one.

Very curious to see how this could have happened!

xeM8VfDh’s picture

Okay. This is very weird. Sometimes when using the alignment options it applies a style float to the image html, and other times, it applies a class to the parent <p> tag. I have done lots of testing, and the best that I can determine is that, with Full HTML, aligning left and aligning right applies the style attribute, while aligning center applies the class to the parent <p>. When using a Text Format that implements the HTML Filter (Basic HTML in my case), neither the left, center, or right alignments in Image Properties work, leading me to believe that all of them are trying to add a style attribute. If I create some text and use the center align CKEDITOR button, it properly aligns the text in the center. If I click the image and click the center align button (instead of using the Image Properties alignment), it still does not center the image. Well, sometimes it doesn't, but sometimes it does (see second video). It seems that I need to highlight the image and click right align for it to work. If I just have the cursor right before/after the image and click the right align button, it works in the editor window, but upon saving, it doesn't.

It seems to me that there is some method by which style attributes are applied

  1. Image Properties left and right align in unfiltered Text Format
  2. any Image Properties alignments when using a Text Format that implements HTML Filter
  3. not highlighting image and clicking alignment buttons

and other methods by which it properly adds a class to the parent <p>

  1. Image Properties center align in unfiltered Text Format
  2. highlighting image and using alignment buttons in filtered Text Format

I don't know. This is a weird one.

Here's what the videos show:

1_image_properties_alignment.ogv

  • create new page
  • use Full HTML
  • add image
  • right click image to get to "Image Properties" (you can also double click the image)
  • align image right in Image Properties (THIS ADDS STYLE FLOAT CSS)
  • edit page, float image left with Image Properties (THIS ADDS STYLE FLOAT CSS)
  • edit page, float image center with Image Properties (THIS ADDS CLASS TO PARENT)
  • edit page, change to Basic HTML (filtered)
  • center text with alignment button (THIS ADDS CLASS TO PARENT)
  • center align image with Image Properties (WORKS IN EDITOR, BUT STYLING STRIPPED, or at least no class added to parent)

2_alignment_buttons.ogv

  • create (filtered) Basic HTML page
  • insert image
  • click right align button (WORKS IN EDITOR BUT NOT ON PAGE)
  • edit page, highlight image, click right align button (PROPERLY ADDS CSS TO PARENT)

As for why "Image Properties" is even showing in my setup, I don't know. I have Imce File Manager installed, and a few other modules. Not sure if any of them may be responsible.

FOR WHAT ITS WORTH: All of the above aside, assuming we resolved the wonkiness, I do think the Image Properties alignment should be adding float classes, not "text-align" classes. I think this because, if one wants "text-align", they can simply use the alignment buttons. The Image Properties alignment options should offer float options so that one can properly position the image relative to it's context, one of the more popular application being wrapping text around an image, as shown here: https://www.youtube.com/watch?v=xFVfX2sevNI

Wim Leers’s picture

Thanks for that video. The first one shows me after 20 seconds that you are NOT using the Drupal CKEditor image plugin. You're using something custom. What module did you install to get that?

xeM8VfDh’s picture

Category: Support request » Bug report
Status: Postponed (maintainer needs more info) » Active

Where would I go in my system to check which image plugin I am using instead of Drupal CKEditor? My first guess would be that it is provided by IMCE File Manager....

MODULE: https://www.drupal.org/project/imce
D7 DEMO: http://ufku.com/drupal/imce/demo

Wim Leers’s picture

Title: Alignment in "Image Properties" should use class instead of raw style attribute floats » IMCE module is not integrating with the DrupalImage CKEditor plugin that D8 ships with, causes problems
Project: Drupal core » IMCE
Version: 8.1.9 » 8.x-1.x-dev
Component: ckeditor.module » Code
Priority: Normal » Major

Right, that means that that is the problem. We saw a similar problem with IMCE at #2666596: Link cannot be placed around an image without the image button's presence, also caused by it not building upon the infrastructure that D8 provides.

So, retitling and moving to the IMCE issue queue.

xeM8VfDh’s picture

Thanks very much @Wim Leers, you've been super helpful, and I really appreciate the quick responses!

Wim Leers’s picture

You're welcome :)

  • ufku committed 637ed5b on 8.x-1.x
    Issue #2798959: Added drupalimage as a requirement for CKEditor...
ufku’s picture

Status: Active » Fixed

Added drupalimage as a requirement for imce plugin.

xeM8VfDh’s picture

thanks @ufku. Just to clarify, I see DrupalImage.php here: https://api.drupal.org/api/drupal/core%21modules%21ckeditor%21src%21Plug...

I see this file on my filesystem. Is it something we users enable somehow, or is it and internal include the IMCE must utilize to resolve the issue at hand?

Thanks again for the quick help!

Wim Leers’s picture

This maybe makes things better, but it's certainly not a complete solution. The real problem is that http://cgit.drupalcode.org/imce/tree/js/plugins/ckeditor/imce.ckeditor.j... does not extend the DrupalImage CKEditor plugin.

xeM8VfDh’s picture

thanks for the feedback @Wim Leers

Wim Leers’s picture

You're welcome!

xeM8VfDh’s picture

@Wim Leers, I should have asked in my last comment... should I switch the status from fixed to Needs Work (or Active) since this doesn't look sufficient to you?

Wim Leers’s picture

That depends: did this commit actually address the problem described in the issue summary? Then fine, let's keep this marked as fixed, and open a separate issue.

But if this did not actually fix the problem, then this probably needs to go back to active/NW, and the commit then needs to be reverted.

xeM8VfDh’s picture

@Wim Leers, I haven't personally tested the patch

Wim Leers’s picture

Status: Fixed » Active

Well then… how can this be marked Fixed?

xeM8VfDh’s picture

@Wim Leers, right you are, thanks for changing. If I can set up an environment to test it I will and report back.

Wim Leers’s picture

You're handling this in an exemplary way :) Looking forward to see IMCE be nicely integrated with Drupal 8's text editor! :)

xeM8VfDh’s picture

@Wim Leers, since @ufku's fix was a commit, not a patch posted to this issues, am I correct in assuming that if I simply test against the current Dev branch of IMCE, that will suffice?

xeM8VfDh’s picture

@Wim Leers and @ufku, the proposed change does not seem to work. Additionally, it appears to break other Image Properties functionality. I created a fresh D8 site, added an image to a page using the default image button, and the alignment options worked. I then installed the 8.x-1.3 release of IMCE to confirm that the problem reported by this issue still existed on a fresh site install (to rule out the possibility of my current site's environment playing a role in the problem). The problem still existed.

I then disabled the 8.x-1.3 release and removed the imce folder from the modules directory on my filesystem. I then installed the 8.x-1.x-dev branch tar (2016-Oct-02), replaced the regular Image button in the Text Formatter with the IMCE provided "Insert image using IMCE File Manager" button, and the behavior is altogether different. Now when I right/double click the image added via the "Insert image using IMCE File Manager" button, then selected "Image Properties", the only options are to to browse for a new file and add/edit the "Alternative Text" value. So the change pushed to the dev branch altogether removed the options to edit width, height, alignment, and caption.

The change may be in the right direction, but it currently doesn't appear to be implemented correctly, given my testing experience. IMO, the commit should be rolled back or the above described issues should be resolved before tagging a new release, since it breaks more functionality than does the original issue.

@ufku, did you test this before committing and experience different behavior?

ufku’s picture

Status: Active » Fixed

Those who want proper Image support can use the core Image button without the Upload option. You'll see IMCE integrated into the URL field.

xeM8VfDh’s picture

Status: Fixed » Active
xeM8VfDh’s picture

Apologies @ufku, but there must be some sort of communication gap here.

For starters, can we abide by the best practice of not closing the issue until the solution has been tested and confirmed as working? That seems reasonable to me.

It sounds to me like you are suggesting: "If users care about image alignment, they should use the standard Drupal provided 'image' button instead of the IMCE provided 'Insert images using IMCE File Manager' button".

If that is not what you are suggesting, I would greatly appreciate you clarifying your statement. If this IS what you are suggesting, its simply a bad suggestion. While the standard image button's alignment functionality does work, this button does not allow users to browse/select files that are already on the server instead of uploading a new file. This is the entire reason people download IMCE. So, an IMCE dev suggesting users appeal to the standard Drupal image button instead of the IMCE image button simply does. not. compute. The other reason that this suggestion is bad is because it completely ignores the fact that your most recent commit is an inarguable downgrade of the IMCE button's functionality.

You said: "use the core Image button without the Upload option. You'll see IMCE integrated into the URL field."

What does this mean? Please provide further detail and/or screen shots. My testing indicates that there is no url field when clicking the standard Drupal image button, and that you haven't affected the standard Drupal image button at all, but rather broken the IMCE image button further.

I've attached screen shot to compare the results of using standard Drupal Image button/properties and IMCE image button/properties.

See comment below

xeM8VfDh’s picture

@ufku, I gathered, from your comment #10 comment on the other ticket (for those out there not following both issues) that the Text Format in question must have " Enable image uploads" unchecked. Once that is taken care of, the url/browse functionality appears on the regular button.

See attachment.

xeM8VfDh’s picture

Unfortunately, there is still a problem.

SCENARIO 1: IMCE is not installed. I add an image to a page using the drupal core image button. I can align the image, save the page, and the alignment is enforced. I can then edit the page, and the alignment is preserved. I can right/rouble click the image and change the alignment if I want to. No problems here.

SCENARIO 2: IMCE is installed and enabled. The Test Format in question has "Enable Image Uploads" unchecked. I add an image to a page using the standard drupal image button, then use the new IMCE integration to browse for a file, the image is inserted into the page, then I right/double click the image to get to Image Properties and align it accordingly. The alignment is enforced on the page. I then edit the page, and the alignment is not enforced in the WYSIWYG editor. Furthermore, now when I right/double click the image, there is no "Image Properties" option, which means I cannot adjust alignment. If I save the page, the alignment is preserved, but if I want to adjust it, I need to remove the image, add it back, and adjust it there when adding it.

Since everything works as expected without IMCE installed/enabled, but does not work as expected when IMCE is installed/enabled, my instinct is that IMCE is not implementing the core drupal image functionality properly. This may be an incorrect interpretation. What do you think @ufku and @Wim Leers?

Corregidor’s picture

Any updates here? Adding links to images is currently broken, as is Drupal's file cleanup, for images added with IMCE. Is this the recommended module for managing images in Drupal 8's CKEditor?

xeM8VfDh’s picture

@Corregidor, unfortunately I don't have an update, and am interested myself. Maybe @ufku and/or @Wim Leers have more info

FreMun’s picture

We have the same problem as @xeM8VfDh (Scenario 2).

What I noticed is, that if I push on Source Code, the data-entity-uuid and data-entity-type are both empty. If I fill them with proper data: data-entity-type="file" and data-entity-uuid="aabb9abe-1e5b-4c17-9608-6347ee0964f8"(this is the real uuid of my node) everything works as expected.

I don't know how to resolve this, but I hope that the people who works on this project do :-)

xeM8VfDh’s picture

thanks @FreMun, that's really helpful info. Hopefully @ufku will know what to do to get the proper data in those html properties and resolve this issue.

FreMun’s picture

I found this line of code in core/modules/editor/src/Form/. I suppose this has something to do with it?

$existing_file = isset($image_element['data-entity-uuid']) ? \Drupal::entityManager()->loadEntityByUuid('file', $image_element['data-entity-uuid']) : NULL;

xeM8VfDh’s picture

Great find! Paging @ufku

dylf’s picture

Status: Active » Needs review
FileSize
1.23 KB

The issue is the fid in the form_state is not being set on upload, causing the data-entity-uuid & data-entity-type to not be set in the submit handler. Added a little validation function to the image dialog form to set the fid based on the source, not sure if its the cleanest solution but it works!

xeM8VfDh’s picture

thanks @dylanf! Can a commiter (@ufku ?) review and merge the patch?

Hubbs’s picture

Patch didn't work for me. Applied to 2 different composer based sites. I tried both 1.4 and 1.x-dev versions on IMCE. I even tried to manually apply the patch instead of using composer. Everything else on the site was using latest versions.

A co-worker did get it to work successfully on a different D8 site with the exact same settings, the only difference being his wasn't using composer and so he manually installed the latest dev version of IMCE and had applied the patch manually. I'm not sure what would be different.

xeM8VfDh’s picture

huh... that's odd. I'll chime in if I get a chance to test the patch. Thanks for the feedback @Hubbs

Hubbs’s picture

Following up on my previous comment, my co-worker applied this patch successfully on a composer based site. So I guess the issues I'm having are conflicting on my end. If I find out why and it's applicable here, I'll post another follow-up. Otherwise, I think this patch is probably good to go.

xeM8VfDh’s picture

Great, thanks @Hubbs. I've been swamped, with no time to test myself. Will report back if I do.

ufku’s picture

farse’s picture

my problem is regarding Scenario 2 in https://www.drupal.org/node/2798959#comment-11727617

I tried the patch at https://www.drupal.org/node/2798959#comment-11882065 and it seems only to work for some files but not others. Not completely sure why, maybe it could be the manner in which the images have been uploaded to the site?

I just check the above issue and the comment at https://www.drupal.org/node/2771837#comment-11820119 states that "Also, it doesn't work for images added by any other module or ckeditor plugin which does not set the attributes (IMCE for instance)." But with that said, I tried the patch in there and it now works..
But is it really a duplicate?

xeM8VfDh’s picture

Thanks for the info @farse, hopefully the issue this one was closed in reference to (duplicate) will address the problem: https://www.drupal.org/node/2771837

I am still experiencing it too.