PDA

View Full Version : Change order of toolbar buttons


mathforum
02-25-2013, 09:56 AM
I have read everything possible on this topic before it seems as if this has been asked and answered. There are a couple of proposed methods to add/delete buttons but nothing confirmed about moving their positions that has been explicitly defined each step of the way and confirmed by someone, at least not that I found after 2-3 hours. :(

I'm adding custom BB code and these buttons all end up on the last row, bottom-right. Some of these are directly related to other groups of buttons and should be there. Let's say for example I make a custom BB code for center-justified formatting. I fill out everything correctly, upload the image and it's working fine except for its location.

How can I move it to another area of the toolbar?

kh99
02-25-2013, 02:32 PM
You need a plugin to do that. In file vb/ckeditor.php there's a function called setToolbar() that builds an array describing the buttons on the toolbar. At hook location editor_toolbar_set, the array is in $this->config['toolbar'] and you can change it however you want.

Since you asked for instructions every step of the way I went ahead and wrote somehting to move a button. To use this you create a new plugin using hook editor_toolbar_set and this code:

$insert_after = 'JustifyLeft'; // change this if you want it somewhere other than after JustifyRight
$move_button = 'justify'; // change this to 'title' of your bbcode

foreach ($this->config['toolbar'] AS &$row)
{
if (!is_array($row))
continue;
if (in_array($insert_after, $row))
$insert_row = &$row;
if (in_array($move_button, $row))
$remove_row = &$row;
}
if ($insert_row AND $remove_row)
{
$offset = 0;
foreach($insert_row AS $val)
{
$offset++;
if ($val == $insert_after)
break;
}
array_splice($insert_row, $offset, 0, $move_button);

if (($k = array_search($move_button, $remove_row)) !== FALSE)
{
unset($remove_row[$k]);
if (($last = array_pop($remove_row)) !== '-')
array_push($remove_row, $last);
}
}


and as mentioned in the comments, you would want to change $move_button to the title of your bbocde (unless it happens to be 'justify'), and also change $insert_after to the name of the button you want it to be after (the justify buttons are JustifyLeft, JustifyCenter, and JustifyRight. If you want it somewhere else you can look in the ckeditor.php file I mentioned and you can probably figure out the name for each of the buttons).