This question is similar to: CKEditor 4.5.1 How to remove tabs from image dialogue box? but in this case, I am instead looking to find out how to remove attributes such as 'hspace' and 'vspace' from the image pop-up dialogue box.

I had hoped that omitting those attributes from the img tag like below would've solved the issue, but so far, no luck.

<?php
/**
 * Implements hook_wysiwyg_editor_settings_alter().
 */
function MYMODULE_wysiwyg_editor_settings_alter(&$settings, $context) {
  if ($context['profile']->editor == 'ckeditor') {
      $settings['extraAllowedContent'] = array(
        'img[src,title,alt,style,width,height,class,view_mode,format,fid]',
      );
  }
}

If anyone can point out a working solution, that would be really appreciated. I am using wysiwyg 7.x-2.2+63-dev with the CKEditor 4.5.1 full library. Thanks.

CommentFileSizeAuthor
#3 ckeditor-remove-border-v1.jpg77.77 KBrajmataj

Issue fork wysiwyg-2542426

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:

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

rajmataj’s picture

Issue summary: View changes
TwoD’s picture

Status: Active » Fixed

I'm sorry for the delay.

You're on the right track, disallowing those attributes should remove the fields for those settings since they have properties like requiredContent: 'img{margin-top,margin-bottom}',.

However, the extraAllowedContent setting does not allow you to do that. Try the disallowedContent setting instead. There is an example of exactly how to do what you need on http://docs.ckeditor.com/#!/guide/dev_disallowed_content, example 5.

rajmataj’s picture

@TwoD,

Thanks for your quick reply. Just had a chance now to try it out, but it didn't seem to affect the Image Properties dialogue box. Maybe I'm not using the correct syntax? This is what I have in my code and I've attached the results after clearing the cache in Drupal and my browser.

<?php
/**
 * Implements hook_wysiwyg_editor_settings_alter().
 */
function wysiwyg_cke_helper_wysiwyg_editor_settings_alter(&$settings, $context) {
  if ($context['profile']->editor == 'ckeditor') {
		
    // Remove tabs from Link and Image dialogue box 
    $settings['removeDialogTabs'] = 'link:target;link:advanced;image:Link;image:advanced';

    // default height of editor
    $settings['height'] = 450;
		
    // Remove border, hspace, vspace from Image dialogue box
    $settings['disallowedContent'] = 'img{border*,margin*}';
  }
}

What's happening is that the first two config settings are being read properly (so, there's no Advanced tab on an Image Property box, plus the height is set to 450) but the border, vspace and hspace boxes are still showing. Perhaps the syntax is incorrect?

rajmataj’s picture

Status: Fixed » Active
rajmataj’s picture

Status: Active » Closed (works as designed)

I figured out why it wasn't working: disallowedContent only works if the Advanced Content Filter mode is turned on. This can be found at: /admin/config/content/wysiwyg/profile/[your-input-format]/edit, at the bottom of the page in the tab named 'Cleanup and Output'. Once that was set to 'Automatic' then the disallowedContent attributes that I specified in my custom module were acted upon and in my case, the image's border and margin controls were no longer visible. Success!

For more info on ACF, read here: http://docs.ckeditor.com/#!/guide/dev_disallowed_content

I hope this helps others!

rajmataj’s picture

It looks like the #5 solution opened a Pandora's box, creating more issues [on the site I inherited. Maybe yours will work]. Since implementing this solution, I noticed issues with images inserted with the Media module which had been previously sized to a smaller size, or aligned. It wasn't as simple as the attributes being stripped out, but when a person would edit a node, the size was back to the original size and there was no alignment set even though the attributes for allowing both of those were still there. This led to potentially having to add in an allowedContent or extraAllowedContent (depending on whether you're using the ACF Automatic or Custom modes). Since I've already stated the allowed tags and attributes with the wysiwyg_filter module, I was loathe to explicitly define all tags and attributes yet again for ACF in my custom module or on the admin/config/content/wysiwyg/profile/[your-input-format]/edit page

So, out of frustration and lack of time, I decided to do two things:

  1. Set ACF back to 'Disabled'
  2. Hide the pop-up box elements visually only, using CSS

To do this, I copied the 'moono' skin out of /sites/all/libraries/ckeditor, renamed it as 'nrs' and put it into a directory within custom module (called wysiwyg_cke_helper). For anyone else at their wit's end with this, here is the code I used to specify a relocated custom skin:

$settings['skin'] = 'nrs,' . base_path() . 'sites/all/modules/custom/wysiwyg_cke_helper/ckeditor_skins/nrs/';

A very inelegant solution but as I said, I'm out of time and most importantly, it accomplishes what I need for now. The height declaration was still honored, btw. All other editor elements were sized properly and in place as expected.

Using:

  • Drupal 7.34
  • wysiwyg 7.x-2.2+63-dev
  • CKEditor 4.5.1 full library
  • WYSIWYG Filter 7.x-1.6-rc2
  • Media 7.x-2.0-alpha3+12-dev
TwoD’s picture

Ah, right. ACF is disabled by Wysiwyg because of the difficulties in maintaining backwards compatibility.
Thanks for the details of the problems and workaround, it'll likely help if I ever try to manage ACF via Wysiwyg again. (I've made some attempts before, including allowing plugins defined through 3rd party modules specify which tags they want/require, but always hit problems with adapting it to work with all editors.)

rajmataj’s picture

Thanks for your comment TwoD. I think with so many issues, questions and potential solutions, everyone could benefit from solid tutorial on how to setup wysiwyg, ckeditor 4.x, some sort of tag filtering (whether in Drupal core, or wysiwyg_filter [which is quite old but very useful]) and the media module - in the ideal world. I suppose the one constant is that things are always changing. If a working solution was at hand for getting these all to play nicely, I would glad put together a one-page tutorial for the community.

It sounds to me like you're not in favor of using ACF because of its redundancy. Is that correct? If you find solutions that work for CKE 4.x, please let us [the community] know.

This so-called 'solution' of mine is very inelegant but it was the best answer in the time I had for hiding various elements. Hiding the tabs was easy but hiding things like the hspace and vspace fields is really tricky since the classes are used in a lot of places on the same page - so one has to be very careful with the css declarations to target.

Things seemed so much simpler with the stable wysiwyg and CKEditor 3.x in terms of hiding elements but now that IE11 doesn't play well with CKEditor 3.x, there's little choice but to go with CKE 4.x or TinyMCE. Since Drupal 8 is going the CKE 4.x route, my preference was to use that as well - just for the sake of getting used to it.

Any guidance or advice you have on this original issue is definitely welcome. Thanks again for your time and work in all this.

sahal_va’s picture

>

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