direction ? 'rtl' : 'ltr'; // Create lists of active and disabled buttons. $editor = $variables['editor']; $plugins = $variables['plugins']; $buttons = array(); $variables['multiple_buttons'] = array(); foreach ($plugins as $plugin => $plugin_buttons) { foreach ($plugin_buttons as $button_name => $button) { $button['name'] = $button_name; if (!empty($button['multiple'])) { $variables['multiple_buttons'][$button_name] = $button; } $buttons[$button_name] = $button; } } $variables['active_buttons'] = array(); foreach ($editor->settings['toolbar']['buttons'] as $row_number => $row) { foreach ($row as $button_name) { if (isset($buttons[$button_name])) { $variables['active_buttons'][$row_number][] = $buttons[$button_name]; if (empty($buttons[$button_name]['multiple'])) { unset($buttons[$button_name]); } } } } $variables['disabled_buttons'] = array_diff_key($buttons, $variables['multiple_buttons']); } /** * Displays the toolbar configuration for CKEditor. */ function theme_ckeditor_settings_toolbar($variables) { $editor = $variables['editor']; $plugins = $variables['plugins']; $rtl = $variables['language_direction'] === 'rtl' ? '_rtl' : ''; $build_button_item = function($button, $rtl) { // Value of the button item. if (isset($button['image_alternative'])) { $value = $button['image_alternative' . $rtl]; } elseif (isset($button['image'])) { $value = theme('image', array('uri' => $button['image' . $rtl], 'title' => $button['label'])); } else { $value = '?'; } // Set additional attribute on the button if it can occur multiple times. if (!empty($button['multiple'])) { $button['attributes']['class'][] = 'ckeditor-multiple-button'; } // Build the button item. $button_item = array( 'value' => $value, 'data-button-name' => $button['name'], ); if (!empty($button['attributes'])) { $button_item = array_merge($button_item, $button['attributes']); } return $button_item; }; // Assemble items to be added to active button rows. $active_buttons = array(); foreach ($variables['active_buttons'] as $row_number => $row_buttons) { foreach ($row_buttons as $button) { $active_buttons[$row_number][] = $build_button_item($button, $rtl); } } // Assemble list of disabled buttons (which are always a single row). $disabled_buttons = array(); foreach ($variables['disabled_buttons'] as $button) { $disabled_buttons[] = $build_button_item($button, $rtl); } // Assemble list of multiple buttons that may be added multiple times. $multiple_buttons = array(); foreach ($variables['multiple_buttons'] as $button_name => $button) { $multiple_buttons[] = $build_button_item($button, $rtl); } $print_buttons = function($buttons) { $output = ''; foreach ($buttons as $button) { $value = $button['value']; unset($button['value']); $attributes = (string) new Attribute($button); $output .= '' . $value . ''; } return $output; }; // We don't use theme_item_list() below in case there are no buttons in the // active or disabled list, as theme_item_list() will not print an empty UL. $output = ''; $output .= '
'; $output .= '' . t('Toolbar configuration') . ''; $output .= '
'; // aria-live region for outputing aural information about the state of the // configuration. $output .= '
'; $output .= '
' . t('Move a button into the Active toolbar to enable it, or into the list of Available buttons to disable it. Use dividers to create button groups. Buttons may be moved with the mouse or keyboard arrow keys.') . '
'; $output .= '
'; $output .= '
'; $output .= ''; $output .= '
    '; $output .= $print_buttons($multiple_buttons); $output .= '
'; $output .= '
'; $output .= ''; $output .= '
    '; $output .= $print_buttons($disabled_buttons); $output .= '
'; $output .= '
'; $output .= ''; $output .= '
'; foreach ($active_buttons as $button_row) { $output .= '
    '; $output .= $print_buttons($button_row); $output .= '
'; } if (empty($active_buttons)) { $output .= '
    '; $output .= '
'; } $output .= '
'; $output .= '-'; $output .= '+'; $output .= '
'; $output .= '
'; $output .= '
'; $output .= '
'; return $output; }