I have updated the wymeditor.inc file to provide support for the different editor buttons that come with the editor (ie. they can now be turned on and off).

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

sun’s picture

Status: Needs review » Needs work

Thank you! Very nice patch!

+  // Add configured buttons or all available.
+  $buttoninfo = _wysiwyg_wymeditor_button_info();
+  if (!empty($config['buttons'])) {
+    $buttons = array();
+    foreach (array_keys($config['buttons']['default']) as $button) {
+      $settings['toolsItems'][] = $buttoninfo[$button];
+    }
+  }
+  else {
+    $settings['toolsItems'] = array_values($buttoninfo);
+  }
+  

I think we can move $buttoninfo into the condition and remove the else case, because that is the default case with no buttons configured; therefore, the editor should use its own defaults.

+  

Please also ensure that there is no trailing white-space anywhere; also not on blank lines.

+        'Bold' => t('Bold'), 
+        'Italic' => t('Italic'),
+        'Superscript' => t('Superscript'),
+        'Subscript' => t('Subscript'),
+        'InsertOrderedList' => t('Ordered List'),
+        'InsertUnorderedList' => t('Unordered List'),
+        'Indent' => t('Indent'),
+        'Outdent' => t('Outdent'),
+        'Undo' => t('Undo'),
+        'Redo' => t('Redo'),
+        'CreateLink' => t('Create Link'),
+        'Unlink' => t('Unlink'),
+        'InsertImage' => t('Insert Image'),
+        'InsertTable' => t('Insert Table'),
+        'Paste' => t('Paste'),
+        'ToggleHtml' => t('Toggle Html'),
+        'Preview' => t('Preview'),

At this point in time, I would highly appreciate if you could order + align that button list like TinyMCE's default buttons in tinymce.inc. (TinyMCE just being an example, all editor includes try to use the same order, if possible)

+}
+
+
+function _wysiwyg_wymeditor_button_info() {

Duplicate newline here.

+    'Bold' => array('name' => 'Bold', 'title'=> 'Strong', 'css'=> 'wym_tools_strong'), 
+    'Italic' => array('name' => 'Italic', 'title'=> 'Emphasis', 'css'=> 'wym_tools_emphasis'),
+    'Superscript' => array('name' => 'Superscript', 'title'=> 'Superscript', 'css'=> 'wym_tools_superscript'),
+    'Subscript' => array('name' => 'Subscript', 'title'=> 'Subscript', 'css'=> 'wym_tools_subscript'),
+    'InsertOrderedList' => array('name' => 'InsertOrderedList', 'title'=> 'Ordered_List', 'css'=> 'wym_tools_ordered_list'),
+    'InsertUnorderedList' => array('name' => 'InsertUnorderedList', 'title'=> 'Unordered_List', 'css'=> 'wym_tools_unordered_list'),
+    'Indent' => array('name' => 'Indent', 'title'=> 'Indent', 'css'=> 'wym_tools_indent'),
+    'Outdent' => array('name' => 'Outdent', 'title'=> 'Outdent', 'css'=> 'wym_tools_outdent'),
+    'Undo' => array('name' => 'Undo', 'title'=> 'Undo', 'css'=> 'wym_tools_undo'),
+    'Redo' => array('name' => 'Redo', 'title'=> 'Redo', 'css'=> 'wym_tools_redo'),
+    'CreateLink' => array('name' => 'CreateLink', 'title'=> 'Link', 'css'=> 'wym_tools_link'),
+    'Unlink' => array('name' => 'Unlink', 'title'=> 'Unlink', 'css'=> 'wym_tools_unlink'),
+    'InsertImage' => array('name' => 'InsertImage', 'title'=> 'Image', 'css'=> 'wym_tools_image'),
+    'InsertTable' => array('name' => 'InsertTable', 'title'=> 'Table', 'css'=> 'wym_tools_table'),
+    'Paste' => array('name' => 'Paste', 'title'=> 'Paste_From_Word', 'css'=> 'wym_tools_paste'),
+    'ToggleHtml' => array('name' => 'ToggleHtml', 'title'=> 'HTML', 'css'=> 'wym_tools_html'),
+    'Preview' => array('name' => 'Preview', 'title'=> 'Preview', 'css'=> 'wym_tools_preview'),

It looks like we could use the array key for the internal name and process that into 'name' elsewhere?

Richard Blackborder’s picture

FileSize
3.38 KB

Sun I have tried to take care of each point you raised in this revised patch.

I am also looking into trying to integrate a Drupal teaser break button for this editor. I'm having some issues. I'm not asking you to solve them all for me, but any input you could give would be appreciated:

1) WYMeditor is not integrated with the WYSIWYG plugin API. Can I just hardcode a button in to the buttons list for the Drupal Teaser break?

2) WYMeditor doesn't seem to allow comments, so I'm having trouble inserting the <!--break--> marker (ref this post). I wondered if you might have any cunning workarounds I have not thought of?

Thanks

sun’s picture

Setting proper status.

1) Adding Drupal plugin support for WYMeditor should be deferred to a separate issue.

2) Not sure what the actual issue is, but most probably, it is rather related to 1), though we also seem to have 1-2 other related issues in the queue already.

Mostly looks good.

+  // Add configured buttons or all available.
+  if (!empty($config['buttons'])) {
+    $buttoninfo = _wysiwyg_wymeditor_button_info();
+    $buttons = array();
+    foreach (array_keys($config['buttons']['default']) as $button) {
+      $settings['toolsItems'][] = array_merge($buttoninfo[$button],array('name' => $button));
+    }
+  }

a) I think that the leading comment is outdated. (re: or all available)

b) $buttons doesn't seem to be used anywhere.

c) The foreach only allows to add internal, native buttons of the editor itself, so no other module can add further native buttons - we mostly want to replace the foreach with the plugin/button processing that can be found in tinymce.inc or fckeditor.inc (the latter might be easier to use as template).

Richard Blackborder’s picture

I've done the first points, but I find integrating a plugin system with only a different implementation of it to work off pretty awkward. Documentation would be a massive help. I've had a go, but I'm feeling my way in the dark a bit here.

That said, I want WYMeditor to have the best integration possible. I may need some support, though.

This code works for defaults:

  // Add configured buttons
  if (!empty($config['buttons'])) {
    $buttoninfo = _wysiwyg_wymeditor_button_info();
    $plugins = wysiwyg_get_plugins($editor['name']);
    foreach ($config['buttons'] as $plugin => $buttons) {
      foreach ($buttons as $button => $enabled) {
        // Iterate separately over buttons and extensions properties.
        foreach (array('buttons', 'extensions') as $type) {
          // Skip unavailable plugins.
          if (!isset($plugins[$plugin][$type][$button])) {
            continue;
          }
          // Add buttons.
          if ($type == 'buttons') {
            if ($plugin == 'default') {
              $settings['toolsItems'][] = array_merge($buttoninfo[$button],array('name' => $button));
            }
            else {
              $settings['toolsItems'][] = $plugins[$plugin][$type][$button];
            }
          }
        }
      }
    }
  }

From what I can tell, fckeditor.inc and tinymce.inc seem to add buttons by adding a string to the $settings['buttons'] array, but WYMeditor needs to add a whole array of data to $settings['toolsItems'] to add a button.

Now, for the defaults, I'm getting this array data from my internal helper subroutine _wysiwyg_wymeditor_button_info(), but I don't know where I would get the equivalent information for a plugin.

I'm sure that $plugins[$plugin][$type][$button] is wrong, but looking at wysiwyg_get_plugins(), it is not clear to me where I would find this array. Can you help?

Richard Blackborder’s picture

Status: Needs work » Needs review

Status.. oops

sun’s picture

Status: Needs review » Needs work

I think you forgot to attach your new patch since #3. ;)

Richard Blackborder’s picture

Status: Needs work » Needs review
FileSize
3.98 KB

You're quite right.. what a nuisance.

sun’s picture

Status: Needs review » Fixed
FileSize
7.88 KB

Thanks for reporting, reviewing, and testing! Committed attached patch to all branches.

A new development snapshot will be available within the next 12 hours. This improvement will be available in the next official release.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.