Problem/Motivation

Tested with a blank 8.0.2 version of drupal on pretty standard environment.

steps to reproduce:
- install drupal 8
- edit basic html text format -> add justiy left, center, right, block to the toolbar (anywhere)
- save text format
- go to node/add/page

-> added buttons are not showing up. tested with cache rebuild and a complete development environment.

if needed:
Database system version 5.5.42
PHP 5.6.10
(but the problem exists on all environment we tested)

Proposed resolution

TBD. See #11.

TEMPORARY WORK-AROUND: see #10.

Remaining tasks

TBD

User interface changes

None.

API changes

TBD

Data model changes

TBD

Comments

nodestroy created an issue. See original summary.

droplet’s picture

Version: 8.0.2 » 8.0.x-dev
Category: Support request » Bug report

It's a bug, the toolbar do not sync with input configs.

we have an issue with patch for that but I can't find it anymore sadly. :(

nodestroy’s picture

ok, thanks for clarifying.
i did some research, but did not found anything, maybe you got another hint for me, where to search?

zviryatko’s picture

Buttons will not be shown if you have "Limit allowed HTML tags and correct faulty HTML" filter enabled, you can disable this filter (security risk) or add to each element in "Allowed HTML tags" setting this few classes: <p class="text-align-left text-align-center text-align-right text-align-justify">. You must add "class" attribute to each element which you want to align.

nodestroy’s picture

thanks for that, works like a charm.
if there is a issue for that bug out there, can we close this? otherwise, how to document that behavior?

zviryatko’s picture

Module Filter provides form element "text_format" and filter plugin (see FilterInterface), then Editor module alter text_format element and apply all editor plugins (see EditorPluginInterface) to this element, btw one of editor plugin contains in ckeditor module (see Drupal\ckeditor\Plugin\Editor\CKEditor)...
In few words: editor module is affects on input form through hook form alter, but can't affect on output filtering, because it's in responsibility of filter module.

echoz’s picture

The solution in #4 is documented in the help text (which I also took a while before noticing!) where it states a wildcard * can be used, so we only need <p class="text-align-*">

cilefen’s picture

Title: Justify buttons no appearing for editors » Justify buttons not appearing for editors
droplet’s picture

Let's see if @Wim Leers could give us some hints.

Hardly to understand the code in editor & filter & CKEditor modules.

Wim Leers’s picture

Title: Justify buttons not appearing for editors » Alignment/justify buttons not appearing for CKEditor, <p class="text-align-left text-align-center text-align-right text-align-justify"> not being whitelisted automatically
Component: editor.module » ckeditor.module
Related issues:

It is indeed related to #2549077: Allow the "Limit allowed HTML tags" filter to also restrict HTML attributes, and only allow a small whitelist of attributes by default, which now causes more strict CKEditor ACF restrictions.

The alignment buttons need classes to function. From \Drupal\ckeditor\Plugin\CKEditorPlugin\Internal::getConfig():

'justifyClasses' => array('text-align-left', 'text-align-center', 'text-align-right', 'text-align-justify'),

So those classes need to be allowed on the <p> tag. i.e. you need to add this to the Limit allowed HTML tags and correct faulty HTML filter setting:

<p class="text-align-left text-align-center text-align-right text-align-justify">

Of course, that should be happening automatically. That's the actual bug to address here.

Wim Leers’s picture

Issue summary: View changes

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.

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.

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.

dxvargas’s picture

While the problem is not solved, my workaround is to put "Allowed HTML tags" like this:
<p id class="">
<h1 id class="">
<a href hreflang>
... etc...

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

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should 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.

katannshaw’s picture

@zviryatko: Thanks for the workaround. I was so happy to find this post. I hope that it's fixed automatically soon.

Wim Leers’s picture

Assigned: Unassigned » Wim Leers
Related issues: +#2904142: Update CKEditor library to 4.7.2

I wonder if https://ckeditor.com/blog/CKEditor-4.7.2-released fixes this, because it specifically mentions an ACF + Justify bugfix. Testing…

Wim Leers’s picture

Assigned: Wim Leers » Unassigned

Nope, updating to 4.7.2. sadly doesn't fix it.

Wim Leers’s picture

https://github.com/ckeditor/ckeditor-dev/issues/455 shows that it's more about the Justify plugin respecting ACF rules, which explains why it didn't fix this.

Wim Leers’s picture

Title: Alignment/justify buttons not appearing for CKEditor, <p class="text-align-left text-align-center text-align-right text-align-justify"> not being whitelisted automatically » [upstream] Alignment/justify buttons not appearing for CKEditor, <p class="text-align-left text-align-center text-align-right text-align-justify"> not being whitelisted automatically
Issue tags: +Needs upstream bugfix
DuaelFr’s picture

Wouldn't it be an option to rewrite this plugin to use our own, based on data-align attributes even for <p> tags?

I tried to figure out how this was already overwritten in our drupalimage implementation but I can't see anything outside drupalimagecaption. I feel like there is something dirty done here ;)

zviryatko’s picture

@DuaelFr, as for me it's question of design, I've described it shortly in #6

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.

Wim Leers’s picture

Assigned: Unassigned » mlewand

Closed #2952740: [upstream] CKEditor alignment buttons not showing up as a duplicate of this.

Assigning to CKEditor maintainer @mlewand for feedback.

Wim Leers’s picture

Dakwamine’s picture

Does the workaround makes the align buttons appear in the toolbar?

Because I cannot get them displayed in the toolbar. I can set the classes in source mode though.

Nevermind, I have found why. We were using a custom setting on the editor which conflicts with the buttons:

function MODULE_editor_js_settings_alter(array &$settings) {
  foreach ($settings['editor']['formats'] as $name => $value) {
    // Use <br> instead of <p> on enter.
    // See: https://docs.ckeditor.com/ckeditor4/latest/api/CKEDITOR.html#property-ENTER_BR.
    // CKEditor natively converts double <br> into <p> on rendering.
    $settings['editor']['formats'][$name]['editorSettings']['enterMode'] = '2';
  }
}

Well, we got to find another workaround, I guess...

kokrull’s picture

Still in 8.5.6.

10 fixed it for me.... thanks

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.

seppeltheflash’s picture

Hi,

i'm only trying to make my site a little bit prettier und stumbled upon this thread. I read Nr. 10 over and over again, but i don't know how to get there to activate my justify buttons nor in which file i have to set these lines. May someone please write a step by step guide, so a newbie like me can follow it? It ist very frustrating to set the justify argument by hand in every P Tag.

I would be glad to hear from you again.

indigoxela’s picture

@seppelttheflash the fix is: put <p class="text-align-left text-align-center text-align-right text-align-justify"> into "allowed HTML tags".

Confirmed: the problem still exists in Drupal 8.6.1.

Another issue: not only p can have an alignment, but all block level elements (div, h1, h2...). So putting in just "p" won't be enough.
Wouldn't it be smarter to not force a tag for global attributes, as they can get added to many different tags.

https://www.w3schools.com/tags/ref_standardattributes.asp

dkre’s picture

Is this really a bug? I thought this was just how the input filter works. Out of box you can't create a table or insert and image with the default allowed tags that is populated when you enable limit allow HTML.

If you add any contrib modules you have to dig around to find every attribute the module wants to use and then whitelist it.

Here is the limit list I have to run for LinkIt, Entity Embed, tables and custom formats:

<a href hreflang data-entity-substitution data-entity-type data-entity-uuid class target name> <em> <strong> <cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id class> <h3 id class> <h4 id class> <h5 id class> <h6 id class> <u> <s> <sup> <sub> <drupal-entity data-entity-type data-entity-uuid data-entity-embed-display data-entity-embed-display-settings data-align data-caption data-embed-button> <p class> <img src alt data-entity-type data-entity-uuid data-align data-caption height width> <blockquote cite class id> <hr> <table> <caption> <tbody> <thead> <tfoot> <th> <td> <tr> <div class data-blazy data-media-gallery data-media data-url style> <span class>

Absurd, but it's very much a Drupal way to do things.

I would recommend boilerplating this better, out of the box you can't really create much or provide a cheatsheet and documentation around this.

Mile23’s picture

Adding <p class> to the allowed filter lets the user do justification.

AlviMurtaza’s picture

Agree with @Mile23 #34 Adding <p class> in Allowed HTML tags shows the configured Alignment options in CKEditor, since these options are adding classes and we are allowing the classes to be applied on p tag.

scotwith1t’s picture

I have an input format which is only for headings, so only h1, h2, etc. allowed and specified in the Styles dropdown. I shouldn't have to add <p class=""> to my allowed tags if I don't allow paragraphs, right? The only way I can get this to work is to add that as well as all the h tags I want with the class allowed on them as well. Without that last piece, the buttons are grayed out when I change the text entered into a heading tag. So mine ends up looking like <u> <em> <strong> <h1 class=""> <h2 class=""> <h3 class=""> <h4 class=""> <p class=""> in order for it to work "as expected".

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.

Kartagis’s picture

In addition to not being able to see the alignment buttons, I am also not able to see buttons created by this module. I can now see the alignment buttons thanks to this comment but I've yet to find out what tag/class that project adds.

ashique12009’s picture

Issue tags: -JavaScript +JavaScript

#4 works, thank you.

phenaproxima’s picture

Title: [upstream] Alignment/justify buttons not appearing for CKEditor, <p class="text-align-left text-align-center text-align-right text-align-justify"> not being whitelisted automatically » [upstream] Alignment/justify buttons not appearing for CKEditor, <p class="text-align-left text-align-center text-align-right text-align-justify"> not being allowed automatically

Re-titling, since we have retired the terms "whitelist" and "blacklist" in core.

blacklabel_tom’s picture

Can confirm the solution in #4 works for me on 9.1.6 core.

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

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

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

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

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should 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.

quietone’s picture

Project: Drupal core » CKEditor 4 - WYSIWYG HTML editor
Version: 9.4.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

JeroenT’s picture

I tried to reproduce this on Ckeditor 5 but it was working.
So +1 for moving it to the CKEditor 4 issue queue

Wim Leers’s picture

Assigned: mlewand » Unassigned
Status: Active » Closed (outdated)

This module is EOL/unsupported and #2567801: Deprecate core/modules/editor/js/editor.admin.js JS APIs in Drupal 10, for removal in Drupal 11 is deprecated in Drupal >=10.3 and will be removed in >=11.

This will never get fixed at this point.