You are here

function theme_tinymce_settings_toolbar in TinyMCE 7

Displays the toolbar configuration for TinyMCE.

1 theme call to theme_tinymce_settings_toolbar()
tinymce_settings_form in ./tinymce.module
Editor settings callback; Provide options for TinyMCE module.

File

./tinymce.module, line 381

Code

function theme_tinymce_settings_toolbar($variables) {
  $editor = $variables['editor'];
  $plugins = $variables['plugins'];
  $rtl = $variables['language_direction'] === 'rtl' ? '_rtl' : '';

  // Assemble items to be added to active button rows.
  foreach ($variables['active_buttons'] as $row_number => $row_buttons) {
    foreach ($row_buttons as $button) {
      $button_name = $button['name'];
      if (isset($button['image_alternative'])) {
        $data = $button['image_alternative'];
      }
      elseif (isset($button['image'])) {
        $data = theme('image', array(
          'path' => $button['image' . $rtl],
          'title' => $button['label'],
        ));
      }
      else {
        $data = '?';
      }
      $button_item = array(
        'data' => $data,
        'data-button-name' => $button_name,
      );
      if (!empty($button['multiple'])) {
        $button['attributes']['class'][] = 'tinymce-multiple-button';
      }
      if (!empty($button['attributes'])) {
        $button_item = array_merge($button_item, $button['attributes']);
      }
      $active_buttons[$row_number][] = $button_item;
    }
  }

  // Assemble list of disabled buttons (which are always a single row).
  foreach ($variables['disabled_buttons'] as $button_name => $button) {
    if (isset($button['image_alternative'])) {
      $data = $button['image_alternative'];
    }
    elseif (isset($button['image'])) {
      $data = theme('image', array(
        'path' => $button['image' . $rtl],
        'title' => $button['label'],
      ));
    }
    else {
      $data = '?';
    }
    $button_item = array(
      'data' => $data,
      'data-button-name' => $button_name,
    );
    if (isset($button['attributes'])) {
      $button_item = array_merge($button_item, $button['attributes']);
    }
    $disabled_buttons[] = $button_item;
  }

  // Assemble list of multiple buttons that may be added multiple times.
  foreach ($variables['multiple_buttons'] as $button_name => $button) {
    if (isset($button['image_alternative'])) {
      $data = $button['image_alternative'];
    }
    elseif (isset($button['image'])) {
      $data = theme('image', array(
        'path' => $button['image' . $rtl],
        'title' => $button['label'],
      ));
    }
    else {
      $data = '?';
    }
    $button_item = array(
      'data' => $data,
      'data-button-name' => $button_name,
    );
    $button['attributes']['class'][] = 'tinymce-multiple-button';
    if (isset($button['attributes'])) {
      $button_item = array_merge($button_item, $button['attributes']);
    }
    $multiple_buttons[] = $button_item;
  }

  // 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 .= '<strong>' . t('Active toolbar') . '</strong>';
  $output .= '<div class="tinymce-toolbar-active clearfix">';
  foreach ($active_buttons as $button_row) {
    $output .= '<ul class="tinymce-buttons">';
    foreach ($button_row as $button) {
      $contents = $button['data'];
      unset($button['data']);
      $attributes = drupal_attributes($button);
      $output .= '<li' . $attributes . '>' . $contents . '</li>';
    }
    $output .= '</ul>';
  }
  if (empty($active_buttons)) {
    $output .= '<ul class="tinymce-buttons">';
    $output .= '</ul>';
  }
  $output .= '<div class="tinymce-row-controls">';
  $output .= '<a href="#" class="tinymce-row-remove" title="' . t('Remove row') . '">-</a>';
  $output .= '<a href="#" class="tinymce-row-add" title="' . t('Add row') . '">+</a>';
  $output .= '</div>';
  $output .= '</div>';
  $output .= '<strong>' . t('Available buttons') . '</strong>';
  $output .= '<div class="tinymce-toolbar-disabled clearfix">';
  $output .= '<ul class="tinymce-buttons">';
  foreach ($disabled_buttons as $button) {
    $contents = $button['data'];
    unset($button['data']);
    $attributes = drupal_attributes($button);
    $output .= '<li' . $attributes . '>' . $contents . '</li>';
  }
  $output .= '</ul>';
  $output .= '<strong class="tinymce-multiple-label">' . t('Dividers') . ': </strong>';
  $output .= '<ul class="tinymce-multiple-buttons">';
  foreach ($multiple_buttons as $button) {
    $contents = $button['data'];
    unset($button['data']);
    $attributes = drupal_attributes($button);
    $output .= '<li' . $attributes . '>' . $contents . '</li>';
  }
  $output .= '</ul>';
  $output .= '</div>';
  return $output;
}