Perforce Chronicle 2012.2/486814
API Documentation

Content_View_Helper_Editor Class Reference

Dojo editor view helper customized for use with p4cms content. More...

List of all members.

Public Member Functions

 editor ($id, $value=null, $params=array(), $attribs=array())
 Extend default editor generation to include onChange proxying of content to hidden text area (normally it is only proxied onSubmit).

Static Public Member Functions

static clearPluginRegistry ()
 Clears all registered plugins and their related options.
static registerPlugin ($shortName, $options)
 Add a plugin to the registry.

Protected Member Functions

 _createEditorOnSubmit ($hiddenId, $editorId)
 Extend parent to remove dependency on zend.findParentForm; no other functional change.
 _getRequiredModules (array $plugins)
 Generates the list of required modules to include, if any is needed.

Protected Attributes

 $_dijit = 'p4cms.content.Editor'
 $_jsonParams = array('captureEvents', 'events', 'plugins', 'extraPlugins')
 $_module = 'p4cms.content.Editor'
 $_pluginsModules

Static Protected Attributes

static $_pluginRegistry = array()

Detailed Description

Dojo editor view helper customized for use with p4cms content.

  • Registers additional plugin modules.
  • Provides a static 'plugin registry'.
  • Adds support for specifying extra plugins.
  • Enhances onchange to proxy to an arbitrary element.
Copyright:
2011-2012 Perforce Software. All rights reserved
License:
Please see LICENSE.txt in top-level folder of this distribution.
Version:
2012.2/486814

Member Function Documentation

Content_View_Helper_Editor::_createEditorOnSubmit ( hiddenId,
editorId 
) [protected]

Extend parent to remove dependency on zend.findParentForm; no other functional change.

Parameters:
string$hiddenIdThe hidden Dojo form ID
string$editorIdThe editor Dojo form ID
Returns:
void
    {
        $this->dojo->onLoadCaptureStart();
        echo <<<EOJ
function() {
    var form = dojo.byId('$hiddenId');
    while (form.nodeName.toLowerCase() != 'form') {
        form = form.parentNode;
    }

    dojo.connect(form, 'submit', function(e) {
        var value = dijit.byId('$editorId').getValue(false);
        if(dojo.isFF) {
            value = value.replace(/<br _moz_editor_bogus_node="TRUE" \/>/, '');
        }
        dojo.byId('$hiddenId').value = value;
    });
}
EOJ;
        $this->dojo->onLoadCaptureEnd();
    }
Content_View_Helper_Editor::_getRequiredModules ( array $  plugins) [protected]

Generates the list of required modules to include, if any is needed.

Parameters:
array$pluginsplugins to include
Returns:
array
    {
        $modules = array();
        foreach ($plugins as $commandName) {
            if (isset($this->_pluginsModules[$commandName])) {
                $modules[] = $this->_pluginsModules[$commandName];
            } elseif (isset(static::$_pluginRegistry[$commandName])
                      && isset(static::$_pluginRegistry[$commandName]['plugin'])
            ) {
                $modules[] = static::$_pluginRegistry[$commandName]['plugin'];
            } else {
                // do not include short-name plugins if they are not
                // contained in plugins registry/modules lists
                // @todo consider to get rid of this block at all
                // and do nothing in this case (like the parent method)
                if (strpos($commandName, '.') !== false) {
                    $modules[] = $commandName;
                }
            }
        }

        return array_unique($modules);
    }
static Content_View_Helper_Editor::clearPluginRegistry ( ) [static]

Clears all registered plugins and their related options.

    {
        static::$_pluginRegistry = array();
    }
Content_View_Helper_Editor::editor ( id,
value = null,
params = array(),
attribs = array() 
)

Extend default editor generation to include onChange proxying of content to hidden text area (normally it is only proxied onSubmit).

Additionally, will ensure any extraPlugins have been required in to function.

Parameters:
string$idZend provides no documentation for this param.
string$valueZend provides no documentation for this param.
array$paramsZend provides no documentation for this param.
array$attribsZend provides no documentation for this param.
Returns:
string
    {
        // Step 0: add any 'default' plugins if user didn't specify 'plugins' setting
        if (!isset($params['plugins']) || empty($params['plugins'])) {
            // normalize extraPlugins to be present and an array
            if (!isset($params['extraPlugins']) || !is_array($params['extraPlugins'])) {
                $params['extraPlugins'] = array();
            }
            
            // scan all registered plugins and add in non-present 'default' entries
            foreach (static::$_pluginRegistry as $shortName => $options) {
                if (!isset($options['default'])) {
                    continue;
                }

                if (in_array($shortName, $params['extraPlugins'])) {
                    continue;
                }

                // if we have a 'long name' and it is present skip
                if (isset($options['plugin'])
                    && in_array($options['plugin'], $params['extraPlugins'])) {
                    continue;
                }

                $params['extraPlugins'][] = $shortName;
            }
        }

        // Step 1: ensure 'extraPlugins' get required in
        if (isset($params['extraPlugins'])) {
            foreach ($this->_getRequiredModules($params['extraPlugins']) as $module) {
                $this->dojo->requireModule($module);
            }
        }

        // Step 2: adjust onChange handling
        $hiddenName = $id;
        if (array_key_exists('id', $attribs)) {
            $hiddenId = $attribs['id'];
        } else {
            $hiddenId = $hiddenName;
        }
        $hiddenId = $this->_normalizeId($hiddenId);

        $attribs['proxyId'] = $hiddenId;
    
        // return parent with the fallback textarea stripped; it blows up content panes with a dupe ID
        // we use substr in order to avoid the PHP pcre_backtrack_limit constraint on preg_replace
        $html  = parent::editor($id, $value, $params, $attribs);
        $start = strpos($html, '<noscript>');
        while ($start !== false) {
            $end   = strpos($html, '</noscript>', $start);
            
            // exit the loop early if there is not an end tag
            if ($end === false) {
                break;
            }
            
            // remove anything in the tag (including tag names).
            $html  = substr_replace($html, "", $start, $end - $start + 11);
            
            // search for the start of the next tag
            $start = strpos($html, '<noscript>', $start);
        }
        
        return $html;
    }
static Content_View_Helper_Editor::registerPlugin ( shortName,
options 
) [static]

Add a plugin to the registry.

Options expects an array that contains one or more of the below settings: 'plugin' => plugin class name, e.g. 'dijit._editor.plugins.ViewSource' 'default' => true/false the plugin will be enabled by default if true

Parameters:
string$shortNameThe user friendly plugin name, e.g. 'viewsource'
array$optionsThe array of option(s), see above for details
    {
        if (!is_array($options)) {
            throw new InvalidArgumentException('Expected options to be an array');
        }
        if (!is_string($shortName)) {
            throw new InvalidArgumentException('Expected shortName to be a string');
        }

        static::$_pluginRegistry[$shortName] = $options;
    }

Member Data Documentation

Content_View_Helper_Editor::$_dijit = 'p4cms.content.Editor' [protected]
Parameters:
stringDijit type
Content_View_Helper_Editor::$_jsonParams = array('captureEvents', 'events', 'plugins', 'extraPlugins') [protected]
Content_View_Helper_Editor::$_module = 'p4cms.content.Editor' [protected]
Content_View_Helper_Editor::$_pluginRegistry = array() [static, protected]
Content_View_Helper_Editor::$_pluginsModules [protected]

The documentation for this class was generated from the following file: