Skip to content

Instantly share code, notes, and snippets.

@brandonkelly
Created July 31, 2012 13:30
Show Gist options
  • Save brandonkelly/3217046 to your computer and use it in GitHub Desktop.
Save brandonkelly/3217046 to your computer and use it in GitHub Desktop.
Wygwam extension for adding custom toolbar buttons
<?php if (! defined('BASEPATH')) exit('No direct script access allowed');
require_once PATH_THIRD.'matrix/config.php';
/**
* Wygwam Custom Toolbar Button
*
* This is a sample extension that would add a plugin to Wygwam’s extraPlugins setting,
* and add its toolbar button.
*/
class Wygwam_custom_toolbar_button_ext {
var $name = 'Wygwam Custom Toolbar Button';
var $version = '1.0';
var $settings_exist = 'n';
var $docs_url = 'http://pixelandtonic.com/wygwam/docs/wygwam_config';
/**
* Constructor
*/
function __construct()
{
$this->EE =& get_instance();
}
// --------------------------------------------------------------------
/**
* Activates the extension
*/
function activate_extension()
{
$this->EE->db->insert('extensions', array(
'class' => get_class($this),
'method' => 'wygwam_config',
'hook' => 'wygwam_config',
'settings' => '',
'priority' => 10,
'version' => $this->version,
'enabled' => 'y'
));
}
/**
* Updates the version number in exp_extension,
* and any other DB changes we might need to make between versions
*/
function update_extension($current = FALSE)
{
if (! $current || $current == $this->version)
{
return FALSE;
}
$this->EE->db->where('class', get_class($this))
->update('extensions', array('version' => $this->version));
}
/**
* Disables the extension
*/
function disable_extension()
{
$this->EE->db->where('class', get_class($this))
->delete('extensions');
}
/**
* Adds our plugin to Wygwam’s extraPlugins setting
* and adds our custom toolbar button
*/
function wygwam_config($config, $settings)
{
// Get the latest $config if we're
// sharing the extension with another hook
if ($this->EE->extensions->last_call !== FALSE)
{
$config = $this->EE->extensions->last_call;
}
// Add our plugin to the extraPlugins setting
if (!empty($config['extraPlugins']))
$config['extraPlugins'] .= ',';
$config['extraPlugins'] .= 'MyPluginName';
// Add our toolbar button(s) here
$config['toolbar'][] = array('MyFirstButton', 'MySecondButton');
return $config;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment