Developed with love by KnpLabs Hire us for your project!
176

TrsteelCkeditorBundle

by trsteel88

Symfony2 bundle for easy integration of the CKEditor WYSIWYG

Symfony2 CKEditor Bundle

Build Status

KnpBundles Badge

Installation

  1. Add TrsteelCkeditorBundle to your composer.json
  2. Enable the bundle
  3. Install bundle assets
  4. Configure the bundle (optional)
  5. Add the editor to a form
  6. Configure data transformers

Step 1: Add TrsteelCkeditorBundle to your composer.json

php composer.phar require Trsteel/ckeditor-bundle ~1.6

Step 2: Enable the bundle

<?php
// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...
        new Trsteel\CkeditorBundle\TrsteelCkeditorBundle(),
    );
}

Step 3: Install bundle assets

$ php ./app/console assets:install web --symlink

--symlink is optional

Step 4: Configure the bundle (optional)

For a full configuration dump use:
bash
$ php ./app/console config:dump-reference TrsteelCkeditorBundle

An example configuration:

trsteel_ckeditor:
    class: Trsteel\CkeditorBundle\Form\Type\CkeditorType
    transformers: ['html_purifier']
    toolbar: ['document', 'clipboard', 'editing', '/', 'basicstyles', 'paragraph', 'links', '/', 'insert', 'styles', 'tools']
    toolbar_groups:
        document: ['Source','-','Save','-','Templates']
        clipboard: ['Cut','Copy','Paste','PasteText','PasteFromWord','-','Undo','Redo']
        editing: ['Find','Replace','-','SelectAll']
        basicstyles: ['Bold','Italic','Underline','Strike','Subscript','Superscript','-','RemoveFormat']
        paragraph: ['NumberedList','BulletedList','-','Outdent','Indent','-','JustifyLeft', 'JustifyCenter','JustifyRight','JustifyBlock']
        links: ['Link','Unlink','Anchor']
        insert: ['Image','Flash','Table','HorizontalRule']
        styles: ['Styles','Format']
        tools: ['Maximize', 'ShowBlocks']
    ui_color: '#000000'
    startup_outline_blocks: true
    width: 800 #Integer or %
    height: 300 #Integer or %
    language: 'en-au'
    filebrowser_upload_url:
        url: relative-url.php?type=file
    filebrowser_image_browse_url:
        route: route_name
        route_parameters:
            type: image

Or even overwrite the 'document' toolbar group in your application completely.

trsteel_ckeditor:
    class: Trsteel\CkeditorBundle\Form\Type\CkeditorType
    toolbar: ['document', 'clipboard', 'editing', '/', 'basicstyles', 'paragraph', 'links', '/', 'insert', 'styles', 'tools']
    toolbar_groups:
        document: ['Source']

You can create additional toolbar groups. Just create the group and specify the items. As you can see in the above config the 'document' toolbar group has been overwritten and only shows the 'Source' icon.

Step 5: Add the editor to a form

Example form:

<?php

$form = $this->createFormBuilder($post)
            ->add('title', 'text')
            ->add('content', 'ckeditor', array(
                'transformers'                 => array('html_purifier'),
                'toolbar'                      => array('document','basicstyles'),
                'toolbar_groups'               => array(
                    'document' => array('Source')
                ),
                'ui_color'                     => '#fff',
                'startup_outline_blocks'       => false,
                'width'                        => '100%',
                'height'                       => '320',
                'language'                     => 'en-au',
                'filebrowser_image_browse_url' => array(
                    'url' => 'relative-url.php?type=file',
                ),
                'filebrowser_image_browse_url' => array(
                    'route'            => 'route_name',
                    'route_parameters' => array(
                        'type' => 'image',
                    ),
                ),
            ))
            ->getForm()
;

Note: All parameters from config.yml can be overwritten in a form (excluding 'class').

Step 6: Configure data transformers

Data transformers will automatically update the html content when the form is processed.

The bundle comes with a html purifier transformer thanks to https://github.com/ezyang/htmlpurifier

If you do not want any transformers enabled you should disable them by:

  1. Disable globally in the config:
trsteel_ckeditor:
    transformers: []
  1. Disable them on a particular form:
<?php

$form = $this->createFormBuilder($post)
            ->add('title', 'text')
            ->add('content', 'ckeditor', array(
                'transformers' => array(),
            ))
            ->getForm()
;

Next Steps

trsteel_ckeditor:
class: Trsteel\CkeditorBundle\Form\Type\CkeditorType
html_purifier:

# The default html purifer config. See http://htmlpurifier.org/live/configdoc/plain.html for more information.
config: Array

# Default data transformers for the submitted html.
transformers: Array

# The default toolbar displayed on the editor.
toolbar: Array

# Groups of icons in the editor.
toolbar_groups: Array

# Whether to automaticaly enable the "show block" command when the editor loads.
startup_outline_blocks: true

# The base user interface color to be used by the editor. Must be a hex.
ui_color: ~ # Example: #AADC6E

# The editor UI outer width. Must be an integer or percentage.
width: ~ # Example: 850

# The height of the editing area (that includes the editor content).
height: ~ # Example: 600

# Force paste content as plain text.
force_paste_as_plaintext: ~

# The user interface language localization to use.
language: ~ # Example: en-au

# The location of an external file browser that should be launched when the Browse Server button is pressed.
filebrowser_browse_url:
url: ~
route: ~
route_parameters: Array

# The location of the script that handles file uploads.
filebrowser_upload_url:
url: ~
route: ~
route_parameters: Array

# The location of an external file browser that should be launched when the Browse Server button is pressed in the Image dialog window.
filebrowser_image_browse_url:
url: ~
route: ~
route_parameters: Array

# The location of the script that handles file uploads in the Image dialog window.
filebrowser_image_upload_url:
url: ~
route: ~
route_parameters: Array

# The location of an external file browser that should be launched when the Browse Server button is pressed in the Flash dialog window.
filebrowser_flash_browse_url:
url: ~
route: ~
route_parameters: Array

# The location of the script that handles file uploads in the Flash dialog window.
filebrowser_flash_upload_url:
url: ~
route: ~
route_parameters: Array

# The skin to load. It may be the name of the skin folder inside the editor installation path, or the name and the path separated by a comma.
skin: ~

# An array of style names (by default tags) representing the style definition for each entry to be displayed in the Format combo in the toolbar.
format_tags: Array # Example: ['p','h2','h3','pre']

# The base URL path used to load ckeditor files from.
base_path: /bundles/trsteelckeditor/

# The base href URL used to resolve relative and absolute URLs in the editor content.
base_href: ~

# Sets the class attribute to be used on the body element of the editing area.
body_class: ~

# The CSS file(s) to be used to apply style to editor contents.
contents_css: []

# Whether to escape basic HTML entities in the document.
basic_entities: ~

# Whether to use HTML entities in the output.
entities: ~

# Whether to convert some Latin characters (Latin alphabet No. 1, ISO 8859-1) to HTML entities.
entities_latin: ~

# The mode to load at the editor startup. It depends on the plugins loaded. By default, the `wysiwyg` and `source` modes are available.
startup_mode: ~

# Sets the behavior of the Enter key. By default the `ENTER_P`, `ENTER_BR` and `ENTER_DIV` modes available.
enter_mode: ~

# The path of the custom config.js to use for the editor setup.
custom_config: ~
external_plugins:

# Prototype
1:
path: ~ # Required
file: plugin.js

# The list of templates definition files to load.
templates_files: Array

# This option makes it possible to set additional allowed content rules for CKEDITOR.editor.filter.
extra_allowed_content: ~
  • allow null values
    By Trent Steel, 2 years ago
  • add support for 1.6
    By Trent Steel, 2 years ago
  • merge with global config. closes #67 and #81
    By Trent Steel, 2 years ago
  • use symfony cache directory - closes #84
    By Trent Steel, 2 years ago
  • update ckeditor to 4.4.5
    By Trent Steel, 2 years ago
  • Bump version
    By trsteel88, 2 years ago
  • Update branch alias
    By trsteel88, 2 years ago
  • update CKEditor to 4.4.3. Closes #77
    By trsteel88, 2 years ago
  • Merge pull request #79 from Nyholm/patch-1
    By trsteel88, 2 years ago
  • Added PHP 5.6 and HHVM to travis.yml
    By Nyholm, 2 years ago
  • allow Symfony 2.5
    By Trent Steel, 2 years ago
  • Upgrade CKEditor to 4.3.3
    By Trent Steel, 3 years ago
  • add html purifier config
    By Trent Steel, 3 years ago
  • clean up config
    By Trent Steel, 3 years ago
  • Merge pull request #69 from phpinfo/master
    By trsteel88, 3 years ago
  • FIX Fixed extra_allowed_content option mistype in template
    By , 3 years ago
  • always show a baseHref
    By Trent Steel, 3 years ago
  • improve test coverage and reshuffle tests so properties are grouped
    By Trent Steel, 3 years ago
  • fix casing
    By Trent Steel, 3 years ago
  • run php-cs-fixer
    By Trent Steel, 3 years ago
  • add template_files and extra_allowed_content options to CkeditorType. Closes #63
    By Trent Steel, 3 years ago
  • fixed login in widget view to remove extra ,
    By Scott, 3 years ago
  • Update composer.json
    By , 3 years ago
  • Merge pull request #65 from toooni/enter_mode
    By trsteel88, 3 years ago
  • implemented enter_mode option
    By toooni, 3 years ago
  • Bump version
    By trsteel88, 3 years ago
  • bump dev version
    By trsteel88, 3 years ago
  • disable transformers in tests
    By trsteel88, 3 years ago
  • remove dependancies
    By trsteel88, 3 years ago
  • run php-cs-fixer
    By trsteel88, 3 years ago