The feature request for sorting buttons is #277954: Allow to sort editor buttons.
This issue is about a non-invasive temporary (or completely custom) solution without having to hack the module and it'll be closed once the other issue is tested, reviewed, committed and finally marked fixed.


Original issue description:

I have everything working OK-ish, but there is an issue with the latest CKeditor and its button bar not displaying properly.

So do I have to use the CKeditor wit the Wysiwyg module, or can I use the CKeditor without it?

CommentFileSizeAuthor
#6 ckscreen.jpg51.94 KBiantresman

Comments

Amarjit’s picture

Yes you can use CKEDITOR without the Wyswyg module. There are more options to manipulate when using standalone CKEDITOR.

iantresman’s picture

Sure, but can I use the WYSIWYG image upload with the CKeditor, without the Wysiwyg module, and if so, any pointers on how to do so? I'm not sure how to add the button to the button bar.

Amarjit’s picture

I don't think you could, as WYSIWYG is the central point I believe. But I have used IMCE, which works with CKEditor.

EugenMayer’s picture

Status: Active » Fixed

The WYSIWYG imageupload module does centraly build on WYSIWYG and i will not support the CKEditor module (even if patches are provided).
There is absolutely not a single point in support the CKEeditor module at all, and i have no clue why people spend time on fixing issues there.

You can fix the button bar bug very easy using some CSS. Iam using the CKeditor in a big env. and its very stable using it with WYSIWYG. Be sure you use the wysiwyg settings hook to alter the CKeditor settings and you will get a nice looking editor:

http://www.ubuntu-pics.de/bild/85074/screenshot_238_p9YK0F.png

Thats how my editor looks like

iantresman’s picture

>the wysiwyg settings hook?

Is this by using the Wysiwyg option to specify a new CSS? Can you post the required CSS fix? I've selected all the CKeditor buttons, which just makes the button bar too wide, and it looks like three row superimpose into two rows.

iantresman’s picture

StatusFileSize
new51.94 KB

This is how my screen looks, with the CKeditor overspilling the page area.
http://drupal.org/files/ckscreen.jpg

I've also tried selecting (a) the Editor default CSS (b) Theme CSS (c) Custom CSS.

EugenMayer’s picture

Title: WYSIWYG image upload: CKeditor requires Wysiwyg? » Fixing toolbar for the CKeditor / Using the settings hook
Project: WYSIWYG image upload - Inline images for your WYSIWYG » Wysiwyg
Version: 6.x-2.0-rc4 » 6.x-2.1
Status: Fixed » Active

Moving this to the WYSIWYG queue, as its not related to wyswiyg_imageupload anymore.

Settings hook: please check the documentation of WYSIWYG ( hook_wysiwyg_editor_settings_alter(&$settings,&$context) )

CSS Problems: It look like you have a seriuos problem with your theme. You have a fixed width but having a gazillion CKeditor plugins activated ( be sure you REALLY want this. Because half of them will make your site go 'boom' ). If you stay with all those buttongs, use the settings hook to regroup the buttons an place them on 2 or even 3 lines

$settings['toolbar'] = array (
  array(...line one),
  array(..line two),
  array(..ilne three)
)

Currently the most anoying issue people told me in using CKeditor in favour of WYSIWYG+CKEditor was this toolbar bug, maybe WYSIWYG should implement better defaults for the settings here.

twod’s picture

This CKEditor toolbar issue will be completely fixed when #277954: Allow to sort editor buttons is fixed. Given the complexity of that issue I'll leave this open if anyone has time to work on it.

iantresman’s picture

I know you've said elsewhere that Wysiwyg is not able to group buttons. But is it not possible to specify a specific number of buttons per row, or add a "breaks" to array($settings['toolbar']). At least that will get the editor to display properly, even of the buttons are not grouped logically.

EugenMayer’s picture

it IS possible to define which / how many buttons are shown in a row.
It is possible to make linebreaks.

iantresman’s picture

Ideally then, there should be an option at admin/settings/wysiwyg/
"Buttons and plugins" to specify "Buttons per row".

twod’s picture

That's where #313497: Allow configuration of advanced editor settings comes in, without that, we have no good way of customizing the profile GUI for each editor's needs.

iantresman’s picture

Just so that I can get a workable editor and further test Wysiwyg, can I hack the code directly for now? I'm guessing I can tweak wysiwyg\editors\ckeditor.inc where function wysiwyg_ckeditor_plugins($editor) defines the buttons at 'buttons' => array(...
Is there an array entry I can add to force a button row break?

Or I note some code noting // For now, all buttons are placed into one row. Can I hack this so that the buttons appear over three or four rows?

EugenMayer’s picture

@TwoD: Yes we have, simply using the CKeditor configuration in the hook. Plain and very simple.

A short look at the CKeditor API reveals: http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.config.html#.tool...

So just use

$settings['toolbar'] = array ( 
  array ( // thats row one
    'Source','-','Save','NewPage','Preview','-','Templates',
  ),
  array ( // thats row two
    'Bold','Italic','Underline','Strike','-','Subscript','Superscript,
  )
);

Very easy - very effectiv. If you want to now which plugins / buttons are possible, debug "toolbar_full" in the javascript console.

twod’s picture

Eugen, that does not change what the GUI looks like. In fact, it overrides the settings generated by the GUI. ;)

EugenMayer’s picture

What is the "GUI" for you? The way the buttons look like? Or the borders?
Thats what the CKeditor theme are. Just create your them ( i have also done that ) :)

iantresman’s picture

@EugenMayer, you mentioned in #7 above to "use the settings hook to regroup the buttons an place them on 2 or even 3 lines" by redefining $settings['toolbar']. I'm not sure how to go about doing this. Do I add it to my theme's template.php file, in which case, do I not have to replace the entire function function wysiwyg_ckeditor_settings($editor, $config, $theme) in wysiwyg\editors\ckeditor.inc? Or do I just hack the block of code (in the same file):

    // For now, all buttons are placed into one row.
    if (!empty($settings['toolbar'])) {
      $settings['toolbar'] = array($settings['toolbar']);
    }

Is there a neat php function that will split array($settings['toolbar'] into X separate arrays, one for each row?

EugenMayer’s picture

Wait, your getting this wrong. settings['toolbar'] will most probably be empty, as the settings are NOT prepopulated by drupal ( the default settings of CKEditor ). So you have to set it on your own

function yourmodule_wysiwyg_editor_settings_alter(&$settings,&$context) {
 $settings['toolbar'] = array(
      array ( 'Bold', 'Italic', 'Underline','-','JustifyLeft','JustifyCenter','JustifyRight'),
      '/',
      array ('Table','Blockquote','Superscript', 'Subscript', 'PasteFromWord','-','RemoveFormat','Undo','-','Maximize','Source'),
    );
}

try this, i guess with this example you should get a clue. '/' is the line break!! Just read the documentation actually ;-)

iantresman’s picture

I thought the following might do the trick (but it doesn't) in wysiwyg\editors\ckeditor.inc, changing:

    // For now, all buttons are placed into one row.
    if (!empty($settings['toolbar'])) {
      $settings['toolbar'] = array($settings['toolbar']);
    }

to:

    // For now, all buttons are placed into one row.
    if (!empty($settings['toolbar'])) {
      $settings['toolbar'] = array($settings['toolbar']);
      $tmp = array_chunk($settings['toolbar'], 3); // Split array($settings['toolbar']) into three chunks
      $settings['toolbar'] = $tmp;  //Reassign
    }

and also:

// For now, all buttons are placed into one row.
    if (!empty($settings['toolbar'])) {
      $tmp = $settings['toolbar'];
      $chunks = array_chunk($tmp, 3);   // Split $settings['toolbar'] into three chunks
      $settings['toolbar'] = array($chunks);  //Reassign
    }
iantresman’s picture

>Just read the documentation actually ;-)
Thanks for the suggested code and advice. The tricky part for novices is knowing which documentation to read, and where!

>the settings are NOT prepopulated by drupal
I thought that the Buttons and plugins configuration in Wysiwyg is populating the buttons? I had them all checked, because I wanted to add the WYSIWYG image upload button.

But I guess your method by-passes Wysiwyg's settings altogether. I'll keep playing around.

iantresman’s picture

OK, this hack seems to work, splitting the toolbar into three rows. In wysiwyg\editors\ckeditor.inc, change:

    // For now, all buttons are placed into one row.
    if (!empty($settings['toolbar'])) {
      $settings['toolbar'] = array($settings['toolbar']);
    }

to:

    // For now, all buttons are placed into one row.
    if (!empty($settings['toolbar'])) {
      $settings['toolbar'] = array_chunk($settings['toolbar'], 3); //Split array into three
    }

Oddly, it actually creates four rows, which I also get if I change the "3" into a "4", but at least it wraps OK, and I can use the button bar. If I change the "3" to a "5", then I get three rows!

twod’s picture

Re #16. The profile GUI I was referring to in #12/#15 is the one at admin/settings/wysiwyg/profile/1/edit. In this case, the "Buttons and Plugins" section is the relevant part. Simply implementing hook_wysiwyg_editor_settings_alter and overriding the toolbar settings will make that section useless. A better approach may be to filter the "layout" you place in $settings['toolbar'] with regards to what's already in $settings['toolbar']. (Maybe with the exception of when it's completely empty, as you noted in #18.) That way, enabling and disabling buttons via "Buttons and Plugins" still works.

EugenMayer’s picture

Twod: sounds good. We have to prepopulate it then i guess, then we can combine it. Or just say, you can use on of those approaches.

tevih’s picture

iantresman - THANKS! That worked for me. It appears that the number you define (3 or 5, in your example) doesn't define the number of rows, but rather the number of items to place in 1 group. In my situation, I set it to 19, which made 3 rows of icons.

hedley’s picture

Didn't find that hack to work for me, I created a small custom module which seemed to work (I also changed the skin to 'kama')

wysiwyg_custom.module


<?php

function wysiwyg_custom_wysiwyg_editor_settings_alter(&$settings, $context) {
  
  //CKEditor
  
  if ($context['editor']['name'] = 'ckeditor' || isset($settings['toolbar'][0])) {
  
  $settings[skin] = 'kama';
  
  $settings['toolbar'] = array_chunk($settings['toolbar'][0], 4);
  
  
  }
  
}
jerry’s picture

subscribing

twod’s picture

@geenee, you have a typo in that snippet. The comparison should use "==" not "=", and I'm not sure why you'd need the OR-expression.
I'd suggest using this as a template for your hook implementation:

  function MYMODULE_wysiwyg_editor_settings_alter(&$settings, &$context) {
    if ($context['profile']->editor == 'ckeditor') {
       $settings['toolbar'] = $my_new_toolbar;
    }
imclean’s picture

iantresman #21 and tevih #24, the proposed workaround only groups buttons for me, it doesn't have a line break. To add a line beak ( / ) at the end of each group, I used the following code:

      $settings['toolbar'] = array_chunk($settings['toolbar'], 25);  // 25 buttons per line
      foreach($settings['toolbar'] as $toolbar_row) {
        $newtoolbar[] = $toolbar_row;;
        // Add line break
        $newtoolbar[] = '/';
      }
      $settings['toolbar'] = $newtoolbar;
sun’s picture

Component: Code » Editor - CKEditor
bleen’s picture

re #22 ... how about we prepopulate the settings['toolbar'] variable with those buttons selected in GUI instead. This way those admin options still work and you can just alter them in the hook?

scarvajal’s picture

With this code you preserve the UI setting for buttons, and can group them in groups that make sense.

<?php
function ckeditor_custom_wysiwyg_editor_settings_alter(&$settings, $context) {
  //Adding CSS styles to the editor
  if ($context['profile']->editor == 'ckeditor') {

    $settings['customConfig'] = base_path() . drupal_get_path('module', 'ckeditor_custom') . '/ckeditor.config.js';

    $settings['stylesCombo_stylesSet'] = 'my_styles:' . base_path() . drupal_get_path('module', 'ckeditor_custom').'/ckeditor_styles.js';

    $newtoolbar[0] = array('Source');
    $newtoolbar[1] = array('Bold', 'Italic', 'Underline', 'Strike');
    $newtoolbar[2] = array('JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock');
    $newtoolbar[3] = array('BulletedList', 'NumberedList', 'Outdent', 'Indent');
    $newtoolbar[4] = array('Undo', 'Redo');
    $newtoolbar[5] = array('Link', 'Unlink', 'Anchor', '-'); 
    $newtoolbar[6] = array('Image', 'TextColor', 'BGColor');
    $newtoolbar[7] = array('Superscript', 'Subscript', 'Blockquote');
    $newtoolbar[8] = array('HorizontalRule', 'break');
    $newtoolbar[9] = array('Cut', 'Copy', 'Paste', 'PasteText', 'PasteFromWord');
    $newtoolbar[10] = array('ShowBlocks', 'RemoveFormat', 'SpecialChar', '/');
    $newtoolbar[11] = array('Format', 'Font', 'FontSize', 'Styles', 'Table');
    $newtoolbar[12] = array('SelectAll', 'Find', 'Replace');
    $newtoolbar[13] = array('Flash', 'Smiley');
    $newtoolbar[14] = array('CreateDiv', 'Maximize', 'SpellChecker', 'Scayt');

    foreach($newtoolbar as $button){
      $tempresult = array_intersect($button, $settings['toolbar'][0]);  
      If(!empty($tempresult)) $resulttoolbar[] = $tempresult;
    }
    $settings['toolbar'] = $resulttoolbar;
  }
}
?>
bleen’s picture

RE #31: I havent had a chance to test this yet, but as I recall $settings['toolbar'] is empty in hook_wysiwyg_editor_settings_alter ... so I do not believe this actually preserves the settings from the GUI. Hmmm ... Ill have to play

Edit: yes, see comment #18 above. The $settings['toolbar'] is empty

... also, on a slightly related note, while it doesn't "fix" anything, this patch #973444: Add message to profile configuration if module implements hook_wysiwyg_editor_settings_alter will help remove a bit of the WTF aspect of customizing the buttons in hook_wysiwyg_editor_settings_alter()

scarvajal’s picture

It's not empty. I have verified that code on #31 works as intended on my install.

$settings['toolbar'][0] is the array that contains all the buttons.

EugenMayer’s picture

In the current WYSIWYG stable release all settings are empty, they are not prefilled at all. the only reasons settings can be not empty are, that other hooks of the same type have set anything there

scarvajal’s picture

Maybe are empty if you have no button selected in UI settings of WYSIWYG profiles. (yes.... its explained in #22)
Once you have checked buttons on each profile (/admin/settings/wysiwyg/profile/%/edit) this code groups the selected buttons using the array of the example.

So its needed to check is the array is empty:

<?php
function ckeditor_custom_wysiwyg_editor_settings_alter(&$settings, $context) {
  //Adding CSS styles to the editor
  if ($context['profile']->editor == 'ckeditor') {

    $settings['customConfig'] = base_path() . drupal_get_path('module', 'ckeditor_custom') . '/ckeditor.config.js';

    $settings['stylesCombo_stylesSet'] = 'my_styles:' . base_path() . drupal_get_path('module', 'ckeditor_custom').'/ckeditor_styles.js';
    if (!empty($settings['toolbar'])) {
      $newtoolbar[0] = array('Source');
      $newtoolbar[1] = array('Bold', 'Italic', 'Underline', 'Strike');
      $newtoolbar[2] = array('JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock');
      $newtoolbar[3] = array('BulletedList', 'NumberedList', 'Outdent', 'Indent');
      $newtoolbar[4] = array('Undo', 'Redo');
      $newtoolbar[5] = array('Link', 'Unlink', 'Anchor', '-'); 
      $newtoolbar[6] = array('Image', 'TextColor', 'BGColor');
      $newtoolbar[7] = array('Superscript', 'Subscript', 'Blockquote');
      $newtoolbar[8] = array('HorizontalRule', 'break');
      $newtoolbar[9] = array('Cut', 'Copy', 'Paste', 'PasteText', 'PasteFromWord');
      $newtoolbar[10] = array('ShowBlocks', 'RemoveFormat', 'SpecialChar', '/');
      $newtoolbar[11] = array('Format', 'Font', 'FontSize', 'Styles', 'Table');
      $newtoolbar[12] = array('SelectAll', 'Find', 'Replace');
      $newtoolbar[13] = array('Flash', 'Smiley');
      $newtoolbar[14] = array('CreateDiv', 'Maximize', 'SpellChecker', 'Scayt');
  
      foreach($newtoolbar as $button){
        $tempresult = array_intersect($button, $settings['toolbar'][0]);  
        If(!empty($tempresult)) $resulttoolbar[] = $tempresult;
      }
      $settings['toolbar'] = $resulttoolbar;
    }
  }
}

?>
bleen’s picture

scarvajal: can you post exactly what version of WYSIWYG you are using ... and also

$modules = module_implements('wysiwyg_editor_settings_alter');
print_r($modules);
scarvajal’s picture

OUTPUT:
Array ( [0] => ckeditor_custom )
(This is the module containing the shown code)

6.x-2.1

This is not working for you guys?

If I find some time I will try this with a new Drupal install and reports results here.

bleen’s picture

OK ... I'm pretty sure I'm losing my mind here. I just outputted $settings['toolbar'][0] and sure enough the buttons were listed just as scarvajal said. I would swear on my copy of Pro Drupal Development that this var was empty last week...

I dont understand

scarvajal’s picture

I just try this code on a fresh drupal install with wysiwyg and CKEditor 3.4.2 and I confirm it works.
One minor fix to the previous code, array_merge is needed to remove blank spaces in the array. And I edited the arrays to look as the default buttons configuration of CKEditor.

So the complete hook is this:

<?php
function ckeditor_custom_wysiwyg_editor_settings_alter(&$settings, $context) {
  //Adding CSS styles to the editor
  if ($context['profile']->editor == 'ckeditor') {
    
    //this is to load a custom config from a path that its not overwriten if the library is upgraded
    $settings['customConfig'] = base_path() . drupal_get_path('module', 'ckeditor_custom') . '/ckeditor.config.js';
    //this is to load custom CSS styles on the editor
    $settings['stylesCombo_stylesSet'] = 'my_styles:' . base_path() . drupal_get_path('module', 'ckeditor_custom').'/ckeditor_styles.js';

    $newtoolbar = array();
    $tempresult = array();
    $resulttoolbar = array();
    
    if (!empty($settings['toolbar'])) {
      $newtoolbar[0] = array('Source', 'Save', 'Newpage', 'Preview', 'Templates');
      $newtoolbar[1] = array('Cut', 'Copy', 'Paste', 'PasteText', 'PasteFromWord', 'Print', 'SpellChecker', 'Scayt');
      $newtoolbar[2] = array('Undo', 'Redo', 'Find', 'Replace', 'SelectAll', 'RemoveFormat');
      $newtoolbar[3] = array('Form', 'Checkbox', 'Radio', 'TextField', 'Textarea', 'Select', 'Button', 'ImageButton', 'HiddenField');
      $newtoolbar[4] = array('Bold', 'Italic', 'Underline', 'Strike', 'Subscript', 'Superscript');
      $newtoolbar[5] = array('NumberedList', 'BulletedList', 'Outdent', 'Indent', 'Blockquote', 'CreateDiv');
      $newtoolbar[6] = array('JustifyLeft', 'Justifycenter', 'JustifyRight', 'JustifyBock');
      $newtoolbar[7] = array('BidiLtr', 'BidiRtl');
      $newtoolbar[8] = array('Link', 'Unlink', 'Anchor');
      $newtoolbar[9] = array('Image', 'Flash', 'Table', 'HorizontalRule', 'Smiley', 'SpecialChar', 'PageBrake');
      $newtoolbar[10] = array('Styles', 'Format', 'Font', 'FontSize');
      $newtoolbar[11] = array('TextColor', 'BGColor');
      $newtoolbar[12] = array('Maximize', 'Showblocks', 'Break', 'About');

      foreach($newtoolbar as $button){
        $tempresult = array_intersect($button, $settings['toolbar'][0]);  
        If(!empty($tempresult)) $resulttoolbar[] = array_merge($tempresult);          
      }
      $settings['toolbar'] = $resulttoolbar;
    }
  } 
}
?>
brian.flaherty’s picture

Hi, thanks for this, it works great! I'd like to add a line break on some of these tool groups. Is there a way to do that here? Nothing I've tried works.

bleen’s picture

line breaks can be added like this:

...
$newtoolbar[5] = array('NumberedList', 'BulletedList', 'Outdent', 'Indent', 'Blockquote', 'CreateDiv');
$newtoolbar[6] = '/';
$newtoolbar[7] = array('BidiLtr', 'BidiRtl');
...
iantresman’s picture

Now we just need a drag and drop custom button bar creator, and it would be perfect!

scarvajal’s picture

Note that there is a typo in Justifycenter in my last post. It should be JustifyCenter.

scarvajal’s picture

@bleen18 take into account that you will lose your line break when array_intersect is executed if you not add code to not run that when "/" is the item to check.

ericbroder’s picture

I added this to my custom module. It breaks down the toolbar buttons into smaller groups so the layout is more flexible:

/**
 * Implementation of hook_wysiwyg_editor_settings_alter().
 */
function mycustommodule_wysiwyg_editor_settings_alter(&$settings, $context) {

  // Break down rich-text toolbar buttons into smaller groups.
  // http://drupal.org/node/829266
  $settings['toolbar'] = array_chunk($settings['toolbar'][0], 4);

}
// */
SchwebDesign’s picture

I also found a great solution for this here: http://drupal.org/node/751196#comment-3689150 It's a simple additional module install.

twod’s picture

Here's some code I recently used on a site.
It's tailored for CKEditor and so assumes all buttons in the original toolbar definition (created by Wysiwyg) are placed in one group on one row. They will then be reordered and grouped according to the layout in the $toolbar variable.

function hook_wysiwyg_editor_settings_alter(&$settings, $context) {
  if ($context['profile']->editor == 'ckeditor') {
    // The layout we'd want to use if all buttons were enabled.
    // This example uses all buttons on one row, but separate them into groups that will wrap as one.
    // Multiple 
    $toolbar = array(
      array(
        array('Bold', 'Italic', 'Underline', 'Strike',),
        array('JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock',),
        array('BulletedList', 'NumberedList',),
        array('Outdent', 'Indent',),
        array('Undo', 'Redo',),
        array('Link', 'Unlink', 'Anchor',),
        array('Superscript', 'Subscript',),
        array('Blockquote', 'Source', 'HorizontalRule',),
        array('Cut', 'Copy', 'Paste',),
        array('PasteText', 'PasteFromWord',),
        array('TextColor', 'BGColor', 'RemoveFormat',),
        array('Format', 'Font', 'FontSize', 'Styles',),
        array('ShowBlocks', 'SpecialChar',),
        array('SelectAll', 'Find', 'Replace',),
        array('Image', 'Flash', 'Smiley', 'Table', 'CreateDiv',),
        array('Maximize', 'SpellChecker', 'Scayt',),
      ),
    // To force buttons to use more than one row even when not auto-wrapping, just keep repeating the pattern above.
/*    array( // Row
         array('Button A', 'Button B'), // Group
      ),
*/
    );

    // Use the original toobar definition as a lookup list.
    $original_toolbar = $settings['toolbar'][0];

    // Loop through rows.
    $r_key = 0;
    while ($r_key < count($toolbar)) {
      $row = &$toolbar[$r_key];

      // Loop through groups.
      $g_key = 0;
      while ($g_key < count($row)) {
        $group = &$row[$g_key];
        if (is_array($group)) { // This check isn't really needed for CKEditor.

          // Loop through buttons.
          $i_key = 0;
          while ($i_key < count($group)) {
            $item = &$group[$i_key];
            // Check if button was enabled.
            if (($found_key = array_search($item, $original_toolbar)) !== FALSE) {
              // Unset enabled button from original layout. Those left were possibly added by 3rd party plugins after our layout was created and need to be appended to the final toolbar so they won't just disappear.
              unset($original_toolbar[$found_key]);
            }
            else {
              //  Cut out disabled button from our custom toolbar layout.
              $cut =array_splice($toolbar[$r_key][$g_key], $i_key, 1);
              // Loop through the same button index again since the array was reindexed.
              $i_key -= 1;
            }
            $i_key += 1;
          }
          // Remove empty groups.
          if (count($group) == 0) {
            array_splice($toolbar[$r_key], $g_key, 1);
            // Loop through the same group index again since the array was reindexed.
            $g_key -= 1;
          }
        }
        $g_key += 1; 
      }
      $r_key += 1;
    }

    // Any buttons left in the original toolbar were not in our custom layout, append them in a new group in the last row.
    if (count($original_toolbar) > 0) {
      $last_row = count($toolbar) -1;
      $extra_group = array();
      foreach ($original_toolbar as $item) {
        $extra_group[] = $item;
      }
      array_push($toolbar[$last_row], $extra_group);
    }

    // Add groups to a single array and delimit rows with slashes.
    $joined_toolbar = array();
    foreach ($toolbar as $row) {
      foreach ($row as $group) {
        $joined_toolbar[] = $group;
      }
      $joined_toolbar[] = '/';
    }
    // Remove the last empty row.
    array_pop($joined_toolbar);
    // Replace the old toolbar with our new shiny one.
    $settings['toolbar'] = $joined_toolbar;
}
boftx’s picture

subscribe

lpalgarvio’s picture

+1

krisis’s picture

@TwoD. Since I ran into a little error with the grouping in the CKEditor I had setup I did some debugging. It was truly puzzling until I resorted to the foreach reference on the php.net website. Short conclusion: by using the $group variable twice, the last foreach will not index $row properly. Here is the new code.

<?php

function hook_wysiwyg_editor_settings_alter(&$settings, $context) {

  if ($context['profile']->editor == 'ckeditor') {

    // The layout we'd want to use if all buttons were enabled.
    // This example uses all buttons on one row, but separate them into groups that will wrap as one.
    // Multiple
    $toolbar = array(
      array( // Row
        array('Bold', 'Italic', 'Underline', 'Strike',), // Group
        array('JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock',),
        array('BulletedList', 'NumberedList',),
        array('Outdent', 'Indent',),
        array('Undo', 'Redo',),
        array('Link', 'Unlink', 'Anchor',),
        array('Superscript', 'Subscript',),
        array('Blockquote', 'Source', 'HorizontalRule',),
        array('Cut', 'Copy', 'Paste',),
        array('PasteText', 'PasteFromWord',),
        array('TextColor', 'BGColor', 'RemoveFormat',),
        array('Format', 'Font', 'FontSize', 'Styles',),
        array('ShowBlocks', 'SpecialChar',),
        array('SelectAll', 'Find', 'Replace',),
        array('Image', 'Flash', 'Smiley', 'Table', 'CreateDiv',),
        array('Maximize', 'SpellChecker', 'Scayt',),
      ),
    ); 

    // Use the original toobar definition as a lookup list.
    $original_toolbar = $settings['toolbar'][0];

    // Loop through rows.
    $r_key = 0;
    while ($r_key < count($toolbar)) {
      $row = &$toolbar[$r_key];

      // Loop through groups.
      $g_key = 0;
      while ($g_key < count($row)) {
        $group = &$row[$g_key];
        if (is_array($group)) { // This check isn't really needed for CKEditor.

          // Loop through buttons.
          $i_key = 0;
          while ($i_key < count($group)) {
            $item = &$group[$i_key];
            
            // Check if button was enabled.
            if (($found_key = array_search($item, $original_toolbar)) !== FALSE) {
            
              // Unset enabled button from original layout. Those left were possibly added by 3rd party plugins after our layout was created and need to be appended to the final toolbar so they won't just disappear.
              unset($original_toolbar[$found_key]);
            }
            else {
            
              //  Cut out disabled button from our custom toolbar layout.
              $cut =array_splice($toolbar[$r_key][$g_key], $i_key, 1);
            
              // Loop through the same button index again since the array was reindexed.
              $i_key -= 1;
            }
            $i_key += 1;
          }
        
          // Remove empty groups.
          if (count($group) == 0) {
            array_splice($toolbar[$r_key], $g_key, 1);
        
            // Loop through the same group index again since the array was reindexed.
            $g_key -= 1;
          }
        }
        $g_key += 1;
      }
      $r_key += 1;
    }
    
    // Any buttons left in the original toolbar were not in our custom layout, append them in a new group in the last row.
    if (count($original_toolbar) > 0) {
      $last_row = count($toolbar) -1;
      $extra_group = array();
      foreach ($original_toolbar as $item) {
        $extra_group[] = $item;
      }
      array_push($toolbar[$last_row], $extra_group);
    }

    // Add groups to a single array and delimit rows with slashes.
    $joined_toolbar = array();
    foreach ($toolbar as $row) {
      foreach($row as $grp){
        $joined_toolbar[] = $grp;
      }
      $joined_toolbar[] = '/';
    }

    // Remove the last empty row.
    array_pop($joined_toolbar);
    
    // Replace the old toolbar with our new shiny one.
    $settings['toolbar'] = $joined_toolbar;
  }
}
?>

Furthermore, this code was used and debugged in a new Drupal 7 installation.

ailgm’s picture

What file / folder should that code be put in?

twod’s picture

Create sites/default/modules/MYMODULE/MYMODULE.info: (I use sites/default/modules or sites/sitename/modules for all custom modules that are specific to a certain site, but sites/all/modules works just as well.)

name = MYMODULE
description = My tweaks.
core = 6.x

Then create sites/default/modules/MYMODULE/MYMODULE.module:

function MYMODULE_wysiwyg_editor_settings_alter(&$settings, $context) {
....
}

Replace MYMODULE with a custom name, enable it and... bingo! ;)

ailgm’s picture

Brilliant. Thank you very much. That fixed it for me.

Renegadez’s picture

ok after I upload
Folder > wysiwyg_tool_tweak with wysiwyg_tool_tweak.module file inside of it

File Path
/sites/all/modules/wysiwyg_tool_tweak/wysiwyg_tool_tweak.module

Do I have to enable this some how its not in my modules list is it read automatically?

Thanks

twod’s picture

@Renegadez, you also need /sites/all/modules/wysiwyg_tool_tweak/wysiwyg_tool_tweak.info for Drupal to recognize it as a module.

Renegadez’s picture

Thank You!!

Ok this fixed the issue in large view areas such as blog entry but not in wysiwyg smaller areas like a private message reply

bryancasler’s picture

Is this workaround compatible with D7?

twod’s picture

Yes, the same hook and settings array are available in both D6 and D7. Just remember to change the .info file so core = 6.x reads core = 7.x instead or Drupal will say the module is not compatible.

For really small textareas one might have to re-arrange the buttons in the $toolbar array at the top.

Renegadez’s picture

How might I rearrange the buttons? Again thanks for all your help it looks so much cleaner with the buttons corrected!

fabianx’s picture

A fully made workaround module for D6 and D7 doing essentially the same as the one from TwoD can be found here:

http://drupal.org/node/751196#comment-3091682

Cleaned up D6 + D7 modules:

http://drupal.org/node/751196#comment-3689150

Best Wishes,

Fabian

twod’s picture

@Renegadez, if you're using the code from #47 or #50, you can rearrange the toolbar by moving around the button names in the first $toolbar variable. The variable is an array of toolbar rows, each row being represented by an array of button groups on that row, and each group is in turn an array of button names. I think there can be any number of rows and groups, or number of buttons in a group, at least in CKEditor.

Renegadez’s picture

@TwoD Thank You!
@Fabianx also thanks ill give a look!

euchrid9’s picture

For anyone still getting stuck with this, I posted a css solution for a similar problem that worked for me here:
http://drupal.org/node/751196#comment-4538018

CFW’s picture

@krisis
Does your code, from # 50 work with drupal 7.4 and CKeditor 3.6.1?

Edit:
Yes, it works perfect!

CFW’s picture

I would like two rows of buttons. Can I modify the code as follows:

$toolbar = array(
      array( // Row
        array('Bold', 'Italic', 'Underline', 'Strike',), // Group
        array('JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock',),
        array('BulletedList', 'NumberedList',),
        array('Outdent', 'Indent',),
        array('Undo', 'Redo',),
      ),
      array( // Row
        array('Link', 'Unlink', 'Anchor',),
        array('Superscript', 'Subscript',),
        array('Blockquote', 'Source', 'HorizontalRule',),
        array('Cut', 'Copy', 'Paste',),
        array('PasteText', 'PasteFromWord',),
        array('TextColor', 'BGColor', 'RemoveFormat',),
        array('Format', 'Font', 'FontSize', 'Styles',),
        array('ShowBlocks', 'SpecialChar',),
        array('SelectAll', 'Find', 'Replace',),
        array('Image', 'Flash', 'Smiley', 'Table', 'CreateDiv',),
        array('Maximize', 'SpellChecker', 'Scayt',),
      ),
    );
krisis’s picture

It should and it did :D thx for trying out.

krisis’s picture

@#66
Did this work as well? I guess it should, since one array represents one row.

CFW’s picture

@#68
Yes, it does.

fabianx’s picture

WYSIWYG CkEditor Nice:

Now also as sandbox release:

http://drupal.org/sandbox/Fabianx/1273794

charlesjc’s picture

Hi,

What is the status of this issue?

I am a fairly clueless outsider, so may misunderstand the situation. It seems that this issue is well understood but nothing is happening to integrate and release?

regards,
Charles

charlesjc’s picture

Hi,

I just worked out that I had a totally different issue, now resolved.

regards,
Charles

twod’s picture

Please note that this issue is not a feature request or bug report, and it's not intended to be either of them, so it's likely no code posted here will go into the module.
This issue is here to present a non-invasive alternative to patching every release of Wysiwyg until we can do this from the Wysiwyg GUI.

The actual work to bring proper toolbar group/row/sorting support into Wysiwyg [for all editors] happens in #277954: Allow to sort editor buttons.
We're a bit short on time and resources to keep these big patches moving forward without the help of the community at this point.
If you're interested in helping out with testing/reviewing/patching toolbar-related code, please join that issue.

pstonier’s picture

Why can't you do it the first way?

twod’s picture

@pstonier, I'm not sure which "first way" you are referring to.

I recently synced the sort_buttons branch used for #277954: Allow to sort editor buttons so it's now much closer to the current state of the 7.x-2.x branch and I've committed some pretty big changes to it as well.

I need people to test those changes (there's a patch for 7.x-2.x if you don't want to check out the sort_buttons branch from git) and provide feedback so we can finally roll the new toolbar designer into the dev snapshots.

kenorb’s picture

Category: support » feature
twod’s picture

Category: feature » support

The feature request for sorting buttons is #277954: Allow to sort editor buttons.
This issue is about a non-invasive temporary (or completely custom) solution without having to hack the module and it'll be closed once the other issue is tested, reviewed, committed and finally marked fixed.

jbova’s picture

In your ckeditor skin's css file, editor.css, you can always just specify white-space:normal;.
For example:

.cke_toolbar{white-space:normal;}
.cke_toolgroup{white-space:normal;}

This takes care of the hidden buttons that have overflowed beyond the boundaries of ckeditor.

jbova’s picture

Issue summary: View changes

Updated issue summary, pointing to http://drupal.org/node/277954.

sri@re’s picture

Issue summary: View changes

without wysiwyg module how to alter the ckeditor settings alter ?is there any hook available to modify ckeditor settings without wysiwyg module ?.please clarify.

twod’s picture

@sri@re, unless you are using another module which integrates the CKEditor library for you, no. This would be the wrong issue queue to discuss that anyway.