Quicktags developers reference

Quicktags allows any developer to add more icon, or to override the old ones.

The syntax to insert more tags, cannot be simpler! And do not be afraid, all you need is a callback hook, so quicktags can pick it up. It means that you do not depend on quicktags, only that it adds additional shazam for those who have quicktags enabled.

insert

Let us try to add a button that will insert [Foo] [:bar] around the selected text (not that I know why one would want to put that in his or her text, but anyway). For that we have or module foobar.module. In that we declare a hook, called foobarquicktagsinsert() which returns an array:

function foobar_quicktags_insert() {
  $path = drupal_get_path('module','foobar') .'/';
  //we need the path because of the icons.

  $items = array(
    'ed_foobar' => array( //ed_foobar is the ID, it is required
      'name' => 'Foo Bar',
      'prefix' => '[Foo]',
      'suffix' => '[:bar]',
      'weight' => 10, //integer
      'accesskey' => 'f',
      'icon' => $path .'ed_foo_bar.png',
    ),
  );
  return $items;
}

That is all there is to it!

alter

A similar function is available to alter (but not yet remove) items.

function foobar_quicktags_alter($items) {
  $path = drupal_get_path('module','quicktags') .'/';
  $items['ed_break'] = array(
      'name' => 'teaser break',
      'prefix' => 'W000T',
      'weight' => 90,
      'accesskey' => 't',
      'close' => FALSE,
      'icon' => $path .'ed_break.png',
    );
  return $items;
}

Will return the default break button into a button that adds W000T istead of the default <!—break—>.

The full syntax is:

  • name The human readable name.
  • prefix The code that is inserted before the selected text. Can be left blank
  • suffix The code that is inserted after the selected text. Can be left blank
  • weight An integer resembling the weight of the icons. Used to order the icons: lower weight comes first, higher wieghts come last.
  • accesskey The optional accesskey
  • icon required, a patch to an icon (yes, its a todo to make this optional)
  • close defaults to TRUE. Set to FALSE if you dont want this button to be closed, e.g. for a <br/>
  • location a Javascript functionname that is called instead of the default quicktags stuff. IF you want to pop open new windows, or want to evaluate some stuff.