Datatypes\Textrich\CkEditor::getToolbarAsJs PHP Method

getToolbarAsJs() public method

Get toolbar as js to initialize ckeditor
public getToolbarAsJs ( ) : string
return string
    public function getToolbarAsJs()
    {
        $js = '';
        $allToolbarItems = $this->getAllToolbarItems();
        $toolbarItems = $this->getToolbarItems();
        foreach ($allToolbarItems as $group) {
            if (!empty($group['items']) and is_array($group['items'])) {
                $content = array();
                foreach ($group['items'] as $item) {
                    if (!empty($toolbarItems[$item])) {
                        $content[] = $item;
                    }
                }
                if (!empty($content)) {
                    $js .= '[\'' . implode('\', \'', $content) . '\'], ';
                }
            } else {
                if (is_string($group) and strlen($group) > 0) {
                    $js .= '[\'/\'], ';
                }
            }
        }
        return '[' . substr($js, 0, -1) . ']';
    }

Usage Example

Beispiel #1
0
    /**
     * Load textrich editor
     *
     * @return mixed
     */
    public function load()
    {
        $this->getHelper('headscript')->appendFile('/backend/assets/datatypes/textrich/ckeditor.js', 'text/javascript');
        $this->getHelper('headscript')->appendFile('/backend/assets/datatypes/textrich/ckeditor-adapters-jquery.js', 'text/javascript');
        $parameters = $this->getConfig();
        $ckeditor = new CkEditor();
        if (empty($parameters) or !is_array($parameters)) {
            $parameters = array();
        }
        $ckeditor->setParameters($parameters);
        $id = 'textrich' . $this->getProperty()->getId();
        $textrich = new Element\Textarea($this->getName());
        $textrich->setLabel($this->getProperty()->getName());
        $textrich->setAttribute('id', $id);
        $textrich->setAttribute('class', $id);
        $textrich->setValue($this->getProperty()->getValue());
        $script = '<script type="text/javascript">
            $(function () {
                var config = {
                    skin: "moono",
                    toolbar: ' . $ckeditor->getToolbarAsJs() . ',
                    allowedContent: true
                };

                $("#' . $id . '").ckeditor(config)
                .ckeditor(function () {
                    this.addCommand("saveDocument",
                    {
                        exec : function (editor, data) {
                            $("#input-save").click();
                        }
                    });
                    this.keystrokeHandler.keystrokes[CKEDITOR.CTRL + 83 /* S */] =  "saveDocument";
                });
            });
        </script>';
        return array($textrich, $script);
    }