The attached patch (against DRUPAL-6--2) adds a new example module which demonstrates how to build a WYSIWYG plugin.

The patch file references 2 image files which are also attached and should be added to the directory examples/wysiwyg_upload_example/plugins/foo/images/.

Comments

twod’s picture

Status: Needs review » Closed (won't fix)

Thanks for the effort, but don't you think the documentation in wysiwyg.api.php and wysiwyg.api.js along with the bundled Teaser Break plugin already achieves this?
As far as I can see, the code is pretty much identical to the Teaser Break plugin and the comments don't add much new information.

Here are a few pointers to your patch anyway.

+++ examples/wysiwyg_plugin_example/plugins/foo/foo.js	2010-12-21 17:45:10.265049511 +0000
@@ -0,0 +1,65 @@
+   * Return whether the passed node belongs to this plugin (note that "node" in this context is a JQuery node, not a Drupal node).

Please wrap comments at 80 characters.

+++ examples/wysiwyg_plugin_example/plugins/foo/foo.js	2010-12-21 17:45:10.265049511 +0000
@@ -0,0 +1,65 @@
+    res = $(node).is('img.wysiwyg_plugin_example-foo');
+    return ($(node).is('img.wysiwyg_plugin_example-foo'));

Duplicate code, res is never used.

+++ examples/wysiwyg_plugin_example/plugins/foo/foo.js	2010-12-21 17:45:10.265049511 +0000
@@ -0,0 +1,65 @@
+    return $content.html();

This call actually break XHTML compatibility as well as any source code formatting added by the editor. We have the same problem with the Teaser Break plugin.

We need a better way to recreate the XHTML from a DOM, see #510552: Invalid XHTML: missing trailing slashes, absolute urls and uppercase tags.

+++ examples/wysiwyg_plugin_example/plugins/foo/langs/en.js	2010-12-21 17:45:10.265049511 +0000
@@ -0,0 +1,7 @@
+// $Id$
+
+tinyMCE.addToLang('foo', {
+  title: 'Insert example comment',
+  desc: 'Insert a comment from the example wysiwyg plugin'
+});

Unused?

+++ examples/wysiwyg_plugin_example/plugins/foo.inc	2010-12-21 17:45:10.265049511 +0000
@@ -0,0 +1,23 @@
+ * Specially named implementation of hook_wysiwyg_plugin().

Incorrect, this is an implementation of hook_INCLUDE_plugin().

hook_wysiwyg_plugin() is for metadata about native (editor-specific) plugins.

+++ examples/wysiwyg_plugin_example/wysiwyg_plugin_example.module	2010-12-21 17:45:10.265049511 +0000
@@ -0,0 +1,27 @@
+ * - plugin: for toolbar buttons such as bold, add-image, strike-through, etc.
+++ examples/wysiwyg_plugin_example/wysiwyg_plugin_example.module	2010-12-21 17:45:10.265049511 +0000
@@ -0,0 +1,27 @@
+ * simply the plugin-type: e.g. "plugin" or "editor".

This string should be "plugins".

I'll mark this as "won't fix" for now since I feel that two almost identical examples might not be so interesting for other developers.

Powered by Dreditor.

sun’s picture

Status: Closed (won't fix) » Needs work

@manarth mentioned in IRC that he had troubles to figure out how to write a plugin, so he considered to write an example module, and I've asked him to post here.

Perhaps we can clarify the existing .api.* files and/or the break plugin instead?

twod’s picture

Ah, I see. I'm not against adding more info to those files, it's just the identical examples (code-wise) part I don't like.

manarth’s picture

@TwoD - Thanks for the review, I'll get those fixed.

Before creating this example, I found the thought of WYSIWYG integration daunting, and this is something I've heard from many other experienced developers. Emfield, geshi filter, and flickr are just a few contrib modules which would be natural contenders for using wysiwyg plugins, but don't have support at the moment.

The benefit of an example module is that it strips the code down to the bare essentials. Naturally it's extremely similar to the break plugin, but the break module is an intrinsic part of wysiwyg, so there's a lot of code that is irrelevant to developing a plugin, and that developers need to mentally ignore when trying to understand what they need to do. However, for a developer who hasn't developed the wysiwyg code, that's a lot of code that needs to be read and understood before being sure that it can be safely ignored.

An example module is a good way to reach out to developers and help them learn what they need to do to integrate against your module. Ctools is a good example of this - despite the ctools module implementing a number of very similar plugins, there's also an example module which breaks it down to the simplest code necessary.

The Wysiwyg module is a great tool and I'd love to see more developers integrating against it.

sun’s picture

Hm. Technically, the break plugin shouldn't really contain additional or unnecessary code that wouldn't be required for other plugins.

The argument I can get behind is that the .api.* files contain plenty of comments explaining the code, so there is no plain template one could copy from.

However, I wonder whether we can improve the break plugin code, so it can act as template, too?

Otherwise, I'd opt for adding a hidden wysiwyg_test.module that registers 1) a Drupal plugin, and 2) a native plugin for one of the editors. (We would then also use that testing module for running unit tests.)

sun’s picture

Version: 6.x-2.x-dev » 7.x-2.x-dev
Component: Miscellaneous » Code
victor@gamedev.by’s picture

Perhaps it is useful as examples: