Hello,

Sorry I feel like this is answered somewhere, but after 30 mins of diligent searching I just cannot find it.

I have my function in my module....

function MYMODULE_wysiwyg_editor_settings_alter(&$settings, $context) {
  if ($context['profile']->editor == 'ckeditor') {
    $settings['height'] = 150;
    $settings['entities_greek'] = TRUE;
   $settings['entities_additional'] = 'quot';
  }
}

Which is loading correctly, the height does change to 150. I tried taking the code from comment #7 in #1108046: Can't Insert Special Characters WYSIWYG with CKEDITOR but I don't see greek entities or the additional quote. I've found http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.config.html#.spec... which seems like I'm supposed to somehow use config.specialChars = config.specialChars.concat( [ '"', [ '’', 'Custom label' ] ] ); but somehow translated to the above Drupal/Wysiwyg function.

I've started taking stabs in the dark and tried...

$settings['specialChars.concat'] = array('clubs', 'clubs');

$settings['specialChars.concat'] = 'clubs';

$settings['specialChars'] = 'clubs';

The first two do nothing, the last one prints out c, l, u, b, s as individual characters in the character map and nothing else.

How do I go about adding a few special characters to the end?

Thanks for reading,
-Tim

CommentFileSizeAuthor
#8 add_greek_chars.info218 bytesdigitalhorde
#2 DEFAULT.png36.68 KBTimG1
#2 THIRD.png9.96 KBTimG1
#2 SECOND.png9.88 KBTimG1
#2 FIRST.png9.91 KBTimG1
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

TwoD’s picture

Status: Active » Fixed

The first two don't work because Wysiwyg doesn't know specialChars.concat is a function (it just sets a setting called 'specialChars.concat' to a value, which never gets used).

specialChars.concat appears to be the regular array concatenation function in JavaScript, and by comparing that to the plugin code we can deduce what the setting value should actually look like.
The base appears to be a simple array of characters or HTML entities in it. If the array value is a plain string, that string is also used as the value shown to the user for that character, the label. To show a more user friendly label, we can use a nested array instead of a string. That array should in turn have two values; the character/HTML entity and the label.

Now, since we set these settings in PHP, which then gets translated to a JSON object and passed to the editor, we need to use PHP's array syntax.

function MYMODULE_wysiwyg_editor_settings_alter(&$settings, $context) {
  if ($context['profile']->editor == 'ckeditor') {
    $settings['height'] = 150;
    $settings['entities_greek'] = TRUE;
    $settings['entities_additional'] = array('quot');
    $settings['specialChars'] = array('♣');
  }
}

That should show you the clubs entity. It printed out c, l, u, b, s earlier because a string can be treated as an array of characters.
Say you wanted to use the word "Clubs" for that entity, you'd replace '♣' with array('♣', 'Clubs'), so the complete line becomes

    $settings['specialChars'] = array(
      array('♣', 'Clubs'),
    );

Say you also want the quote entities from the example, you'd be able to mix using custom lables or not, and thus do something like:

    $settings['specialChars'] = array(
      array('♣', 'Clubs label'),
      "'",
      array('"', 'Double quote label'),
    );
TimG1’s picture

Status: Fixed » Active
FileSize
9.91 KB
9.88 KB
9.96 KB
36.68 KB

Thanks for that TwoD.

I tried your three example codes to see what is produced. I've attached the output in attached screenshots FIRST, SECOND, and THIRD.

<?php
    $settings['entities_greek'] = TRUE;
    $settings['entities_additional'] = array('quot');
    $settings['specialChars'] = array('&clubs;');
?>

Produces FIRST.png. It seems that adding anything to the specialChars array will overwrite the entire character map.

<?php
    $settings['specialChars'] = array(
      array('&clubs;', 'Clubs'),
    );
?>

Produces SECOND.png. Same here. Only Clubs.

<?php
    $settings['specialChars'] = array(
      array('&clubs;', 'Clubs label'),
      "'",
      array('"', 'Double quote label'),
    );
?>

Produces THIRD.png. All three characters. I could rebuild the character map using this method. But is it possible to just add a character to the end of the default character map without rebuilding? Basically just add the clubs character to the end of the attached DEFAULT.png so it appears right after the Almost Equal To ≈ sign. I tried using entities_additional but that doesn't seem to change anything at all.

Thanks again,
-Tim

TwoD’s picture

Ah, sorry, I should have been more clear on that setting a value like this will overwrite the setting's default value.
Now, there's currently no list of the default values for each editor setting in Wysiwyg (huge amount of data to keep updated for each version), so you'll have to include these when you override the setting.

So, yes, you'll need to rebuild the complete character map.

The default value of specialChars is

specialChars = [
  '!','"','#','$','%','&',"'",'(',')','*','+','-','.','/',
  '0','1','2','3','4','5','6','7','8','9',':',';',
  '<','=','>','?','@',
  'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O',
  'P','Q','R','S','T','U','V','W','X','Y','Z',
  '[',']','^','_','`',
  'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p',
  'q','r','s','t','u','v','w','x','y','z',
  '{','|','}','~',
  "€", "‘", "’", "“", "”", "–", "—", "¡", "¢", "£", "¤", "¥", "¦", "§", "¨", "©", "ª", "«", "¬", "®", "¯", "°", "²", "³", "´", "µ", "¶", "·", "¸", "¹", "º", "»", "¼", "½", "¾", "¿", "À", "Á", "Â", "Ã", "Ä", "Å", "Æ", "Ç", "È", "É", "Ê", "Ë", "Ì", "Í", "Î", "Ï", "Ð", "Ñ", "Ò", "Ó", "Ô", "Õ", "Ö", "×", "Ø", "Ù", "Ú", "Û", "Ü", "Ý", "Þ", "ß", "à", "á", "â", "ã", "ä", "å", "æ", "ç", "è", "é", "ê", "ë", "ì", "í", "î", "ï", "ð", "ñ", "ò", "ó", "ô", "õ", "ö", "÷", "ø", "ù", "ú", "û", "ü", "ý", "þ", "ÿ", "Œ", "œ", "Ŵ", "Ŷ", "ŵ", "ŷ", "‚", "‛", "„", "…", "™", "►", "•", "→", "⇒", "⇔", "♦", "≈"
];

as defined in the specialchars plugin file.

The translation to PHP value types is pretty straight forward:

$settings['specialChars'] = array(
  '!','"','#','$','%','&',"'",'(',')','*','+','-','.','/',
  '0','1','2','3','4','5','6','7','8','9',':',';',
  '<','=','>','?','@',
  'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O',
  'P','Q','R','S','T','U','V','W','X','Y','Z',
  '[',']','^','_','`',
  'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p',
  'q','r','s','t','u','v','w','x','y','z',
  '{','|','}','~',
  "€", "‘", "’", "“", "”", "–", "—", "¡", "¢", "£", "¤", "¥", "¦", "§", "¨", "©", "ª", "«", "¬", "®", "¯", "°", "²", "³", "´", "µ", "¶", "·", "¸", "¹", "º", "»", "¼", "½", "¾", "¿", "À", "Á", "Â", "Ã", "Ä", "Å", "Æ", "Ç", "È", "É", "Ê", "Ë", "Ì", "Í", "Î", "Ï", "Ð", "Ñ", "Ò", "Ó", "Ô", "Õ", "Ö", "×", "Ø", "Ù", "Ú", "Û", "Ü", "Ý", "Þ", "ß", "à", "á", "â", "ã", "ä", "å", "æ", "ç", "è", "é", "ê", "ë", "ì", "í", "î", "ï", "ð", "ñ", "ò", "ó", "ô", "õ", "ö", "÷", "ø", "ù", "ú", "û", "ü", "ý", "þ", "ÿ", "Œ", "œ", "Ŵ", "Ŷ", "ŵ", "ŷ", "‚", "‛", "„", "…", "™", "►", "•", "→", "⇒", "⇔", "♦", "≈", '&clubs;',
);

The positive side is at least that you can now reorder or remove the characters you don't need.
Note: There may be slight differences in how PHP interprets these characters compared to JavaScript, so maybe some of them have to be replaced. I think the character encoding settings Drupal enforces should make all these work, but I can't guarantee it.

TimG1’s picture

Status: Active » Closed (works as designed)

Hi TwoD,

Ah okay. Thanks for the default character map and explanation. Now I know what needs to be done and can move forward. =)

Thanks again,
-Tim

ericovk’s picture

Hi,

I am trying to add Greek characters to the Ckeditor special character map, but it is not working at all.
Did you write your own module to accomplish this? My develop skill are not that advanced.

ericovk’s picture

bump

osman’s picture

Issue summary: View changes

I just had the same problem, needed to add greek characters to the "Special Characters" dialog box. And apparently this issue has the most complete solution for the problem. Even 12 months have passed, I couldn't find anything better.

So, if anyone may need to include greek characters, or any other entities that is not available in the default list could implement it like this:

/**
 * Implements hook_wysiwyg_editor_settings_alter().
 */
function YOURMODULE_wysiwyg_editor_settings_alter(&$settings, $context) {
  if ($context['profile']->editor == 'ckeditor') {
    $settings['entities_latin'] = TRUE;
    $settings['entities_greek'] = TRUE;

    // Default list of the special characters.
    $settings['specialChars'] = array(
      '!','"','#','$','%','&',"'",'(',')','*','+','-','.','/',
      '0','1','2','3','4','5','6','7','8','9',':',';',
      '<','=','>','?','@',
      'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O',
      'P','Q','R','S','T','U','V','W','X','Y','Z',
      '[',']','^','_','`',
      'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p',
      'q','r','s','t','u','v','w','x','y','z',
      '{','|','}','~',
      "€", "‘", "’", "“", "”", "–", "—", "¡", "¢", "£", "¤", "¥", "¦", "§", "¨", "©", "ª", "«", "¬", "®", "¯", "°", "²", "³", "´", "µ", "¶", "·", "¸", "¹", "º", "»", "¼", "½", "¾", "¿", "À", "Á", "Â", "Ã", "Ä", "Å", "Æ", "Ç", "È", "É", "Ê", "Ë", "Ì", "Í", "Î", "Ï", "Ð", "Ñ", "Ò", "Ó", "Ô", "Õ", "Ö", "×", "Ø", "Ù", "Ú", "Û", "Ü", "Ý", "Þ", "ß", "à", "á", "â", "ã", "ä", "å", "æ", "ç", "è", "é", "ê", "ë", "ì", "í", "î", "ï", "ð", "ñ", "ò", "ó", "ô", "õ", "ö", "÷", "ø", "ù", "ú", "û", "ü", "ý", "þ", "ÿ", "Œ", "œ", "Ŵ", "Ŷ", "ŵ", "ŷ", "‚", "‛", "„", "…", "™", "►", "•", "→", "⇒", "⇔", "♦", "≈",
    );
    // Greek characters.
    // @see http://www.w3.org/TR/html4/sgml/entities.html#h-24.3.1
    $settings['specialChars'][] = array('&Alpha;', 'Alpha');
    $settings['specialChars'][] = array('&Beta;', 'Beta');
    $settings['specialChars'][] = array('&Gamma;', 'Gamma');
    $settings['specialChars'][] = array('&Delta;', 'Delta');
    $settings['specialChars'][] = array('&Epsilon;', 'Epsilon');
    $settings['specialChars'][] = array('&Zeta;', 'Zeta');
    $settings['specialChars'][] = array('&Eta;', 'Eta');
    $settings['specialChars'][] = array('&Theta;', 'Theta');
    $settings['specialChars'][] = array('&Iota;', 'Iota');
    $settings['specialChars'][] = array('&Kappa;', 'Kappa');
    $settings['specialChars'][] = array('&Lambda;', 'Lambda');
    $settings['specialChars'][] = array('&Mu;', 'Mu');
    $settings['specialChars'][] = array('&Nu;', 'Nu');
    $settings['specialChars'][] = array('&Xi;', 'Xi');
    $settings['specialChars'][] = array('&Omicron;', 'Omicron');
    $settings['specialChars'][] = array('&Pi;', 'Pi');
    $settings['specialChars'][] = array('&Rho;', 'Rho');
    $settings['specialChars'][] = array('&Sigma;', 'Sigma');
    $settings['specialChars'][] = array('&Tau;', 'Tau');
    $settings['specialChars'][] = array('&Upsilon;', 'Upsilon');
    $settings['specialChars'][] = array('&Phi;', 'Phi');
    $settings['specialChars'][] = array('&Chi;', 'Chi');
    $settings['specialChars'][] = array('&Psi;', 'Psi');
    $settings['specialChars'][] = array('&Omega;', 'Omega');
    $settings['specialChars'][] = array('&alpha;', 'alpha');
    $settings['specialChars'][] = array('&beta;', 'beta');
    $settings['specialChars'][] = array('&gamma;', 'gamma');
    $settings['specialChars'][] = array('&delta;', 'delta');
    $settings['specialChars'][] = array('&epsilon;', 'epsilon');
    $settings['specialChars'][] = array('&zeta;', 'zeta');
    $settings['specialChars'][] = array('&eta;', 'eta');
    $settings['specialChars'][] = array('&theta;', 'theta');
    $settings['specialChars'][] = array('&iota;', 'iota');
    $settings['specialChars'][] = array('&kappa;', 'kappa');
    $settings['specialChars'][] = array('&lambda;', 'lambda');
    $settings['specialChars'][] = array('&mu;', 'mu');
    $settings['specialChars'][] = array('&nu;', 'nu');
    $settings['specialChars'][] = array('&xi;', 'xi');
    $settings['specialChars'][] = array('&omicron;', 'omicron');
    $settings['specialChars'][] = array('&pi;', 'pi');
    $settings['specialChars'][] = array('&rho;', 'rho');
    $settings['specialChars'][] = array('&sigmaf;', 'sigmaf');
    $settings['specialChars'][] = array('&sigma;', 'sigma');
    $settings['specialChars'][] = array('&tau;', 'tau');
    $settings['specialChars'][] = array('&upsilon;', 'upsilon');
    $settings['specialChars'][] = array('&phi;', 'phi');
    $settings['specialChars'][] = array('&chi;', 'chi');
    $settings['specialChars'][] = array('&psi;', 'psi');
    $settings['specialChars'][] = array('&omega;', 'omega');
    $settings['specialChars'][] = array('&thetasym;', 'thetasym');
    $settings['specialChars'][] = array('&upsih;', 'upsih');
    $settings['specialChars'][] = array('&piv;', 'piv');
  }
}

tested and works with Wysiwyg 7.x-2.2+33-dev (2014-Mar-19) module + CKEditor 4.3.4.40ccd20 library.

digitalhorde’s picture

FileSize
218 bytes

Hey Osman,

Thank you, that solution works great, it really helped us out! I wrote it up as a module, do you think it would be worth publishing in some way so other people could find it if they search for this kind of issue? I have uploaded the .info file I used to make it accept module form but the forum won't let me upload the .module file.

Thanks again!

axroth’s picture

This works also for Drupal 8, like that:

function hook_editor_js_settings_alter(array &$settings) {

   // add greek alphabet to specialChars
  $settings['editor']['formats']['restricted_html']['editorSettings']['specialChars'][] = array('Α', 'Alpha');
}
david.chevillet’s picture

Hello,

The solution from axroth doesn't work for me . I tried this :
$settings['editor']['formats']['full_html']['editorSettings']['specialChars'][] = array('&Delta;' , 'Delta');
But all the data from specialChar was delete and replace by Delta only.

Have you an idea why i can't just add my spacial character just after the default data ?
More other i dump $settings['editor']['formats']['full_html']['editorSettings']['specialChars'] just before push my data and the result is null.
My website is on 8.3x.

TwoD’s picture

@axroth, @david.chevillet: This module was only an inspiration for the Editor module in D8 Core, other than that it's completely unrelated. Please check the D8 documentation for its hooks as their usage may differ from Wysiwyg's.

david.chevillet’s picture

Thanks TwoD.
I found this module https://www.drupal.org/project/ckeditor_specialchars, that works for me. But firefox remove my non-breaking space in wysiwyg, but it's an other problem.

Xoruna’s picture

For those like me who wonder how to add special characters without having to create a submodule, you have to edit the file "ckeditor.js" in the ckeditor library folder (I'm using drupal 7 and ckeditor 4.9.2).