Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save edit-olah/e246331873831ea5acf8 to your computer and use it in GitHub Desktop.
Save edit-olah/e246331873831ea5acf8 to your computer and use it in GitHub Desktop.
Custom WYSIWYG plugin for Drupal 7 - blockquote

Mentor:

Chris Maiden - https://github.com/matason

Author:

Edit Olah - https://github.com/edit-olah

Custom WYSIWYG plugin for inserting a section with block quotes

Aim: Users can click a button in the WYSIWYG editor’s toolbar and inject specific markup with clickable areas where they can input content.

Folder structure:

  • d --| sites
  • d ------| all
  • d ----------| modules
  • d --------------| custom
  • d ------------------| custom_wysiwyg
  • d ----------------------| plugins
  • d ---------------------------| blockquote
  • d --------------------------------| icons
  • -------------------------------------| blockquote.png
  • --------------------------------| plugin.js
  • ---------------------------| blockquote.inc
  • ----------------------| custom_wysiwyg.info
  • ----------------------| custom_wysiwyg.module
<?php
/**
* Implements hook_INCLUDE_plugin().
*/
function custom_wysiwyg_blockquote_plugin() {
$plugins['blockquote'] = array(
'title' => t('Blockquote'),
'icon path' => drupal_get_path('module', 'custom_wysiwyg') . '/plugins/blockquote/icons',
'icon file' => 'blockquote.png',
'icon title' => t('Insert Blockquote'),
'js path' => drupal_get_path('module', 'custom_wysiwyg') . '/plugins/blockquote',
'js file' => 'plugin.js',
'settings' => array(),
);
return $plugins;
}
name = CUSTOM WYSIWYG
description = Customisation of the WYSIWYG editor.
core = 7.x
package = My Custom modules
<?php
/**
* @file
* Drupal hook implementations.
*/
/**
* Implements hook_wysiwyg_include_directory().
*/
function custom_wysiwyg_wysiwyg_include_directory($type) {
return $type;
}
Drupal.wysiwyg.plugins.blockquote = {
invoke: function (data, settings, instanceId) {
if (data.format == 'html') {
if (data.content) {
var content = '<blockquote><p>' + data.content + '</p></blockquote>';
}
else {
var content = '<blockquote><p></p></blockquote>';
}
}
if (typeof content != 'undefined') {
Drupal.wysiwyg.instances[instanceId].insert(content);
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment