Accueil / Blog / Métier / Archives / How to patch ckeditor in Plone

How to patch ckeditor in Plone

Par Jean-Michel François — publié 12/06/2012

Sometimes there are changes you can't upstream because they are project specific and also because they can't be override in a simple way. I take a current use case I have: change the default values of table plugin from collective.ckeditor.

By default the table add form of ckeditor is 500 pixels wide. A customer want to change that default behavior for good reason: He always use 100% instead and this is boring to have bad default values.

So first as developer you can checkout the current collective.ckeditor:

git clone git://github.com/collective/collective.ckeditor.git

Try to find which files you have to change. In our case

  • collective/ckeditor/browser/ckeditor/_source/plugins/table/dialogs/table.js
  • collective/ckeditor/browser/ckeditor/plugins/table/dialogs/table.js

Do the modification and then call the command from the project folder:

git diff --no-prefix > table-default.diff

Do not forget the --no-prefix option or your patch will not usable. Now you have your patch. You need to deploy it on your project. Because we use buildout to deploy our project here is a simple example ckeditor-patch.cfg:

[buildout]
extends=http://dist.plone.org/release/4.1-latest/versions.cfg
parts =
    instance
    patch-ckeditor

[instance]
recipe = plone.recipe.zope2instance
user = admin:admin
eggs=
    Plone
    collective.ckeditor
zcml =
    collective.ckeditor

[patch-ckeditor]
recipe = collective.recipe.patch
egg = collective.ckeditor
patches = table-default.diff

This buildout will install Plone with collective.ckeditor and apply the our patch on it. Here is the console output:

$ bin/buildout -c test-patch.cfg
Installing instance.
Getting distribution for 'collective.ckeditor'.
warning: no previously-included files matching '*pyc' found anywhere in distribution
Got collective.ckeditor 3.6.2.
Generated script '/Users/toutpt/myproject/bin/copy_ckeditor_code'.
Installing patch-ckeditor.
patch: reading patch /Users/toutpt/myproject/table-default.diff
patch: total files: 2  total hunks: 2
patch: in /Users/toutpt/.buildout/installed_eggs/collective.ckeditor-3.6.2-py2.6.egg...
patch: processing 1/2:      /Users/toutpt/.buildout/installed_eggs/collective.ckeditor-3.6.2-py2.6.egg/collective/ckeditor/browser/ckeditor/_source/plugins/table/dialogs/table.js
patch: successfully patched /Users/toutpt/.buildout/installed_eggs/collective.ckeditor-3.6.2-py2.6.egg/collective/ckeditor/browser/ckeditor/_source/plugins/table/dialogs/table.js
patch: processing 2/2:      /Users/toutpt/.buildout/installed_eggs/collective.ckeditor-3.6.2-py2.6.egg/collective/ckeditor/browser/ckeditor/plugins/table/dialogs/table.js
patch: successfully patched /Users/toutpt/.buildout/installed_eggs/collective.ckeditor-3.6.2-py2.6.egg/collective/ckeditor/browser/ckeditor/plugins/table/dialogs/table.js

And if you launch again the buildout:

$ bin/buildout -c ckeditor-patch.cfg
Installing instance.
Installing patch-ckeditor.
patch: reading patch /Users/toutpt/myproject/table-default.diff
patch: total files: 2  total hunks: 2
patch: in /Users/toutpt/.buildout/installed_eggs/collective.ckeditor-3.6.2-py2.6.egg...
patch: processing 1/2:   /Users/toutpt/.buildout/installed_eggs/collective.ckeditor-3.6.2-py2.6.egg/collective/ckeditor/browser/ckeditor/_source/plugins/table/dialogs/table.js
patch: already patched   /Users/toutpt/.buildout/installed_eggs/collective.ckeditor-3.6.2-py2.6.egg/collective/ckeditor/browser/ckeditor/_source/plugins/table/dialogs/table.js
patch: processing 2/2:   /Users/toutpt/.buildout/installed_eggs/collective.ckeditor-3.6.2-py2.6.egg/collective/ckeditor/browser/ckeditor/plugins/table/dialogs/table.js
patch: already patched   /Users/toutpt/.buildout/installed_eggs/collective.ckeditor-3.6.2-py2.6.egg/collective/ckeditor/browser/ckeditor/plugins/table/dialogs/table.js

So now you have a working Zope instance with Plone and a patched CKEditor. Every one should be happy!

Warning 1: Like as you can see if you are using shared eggs repository, your patch will be applied for all projects using this egg.

Warning 2: Plugins are fetched on demand (ajax) and there is 24 hours of browser cache. So it means you have to empty your browser cache when you are making changes to javascripts or wait 24 hours. Headers of the table.js response which show this browser cache:

Cache-Control:public,max-age=86400
Content-Length:8733
Content-Type:application/javascript
Date:Tue, 12 Jun 2012 09:07:18 GMT
Expires:Wed, 13 Jun 2012 09:07:18 GMT
Last-Modified:Tue, 12 Jun 2012 08:47:06 GMT
ABONNEZ-VOUS À LA NEWSLETTER !
Voir aussi
PloneConf 2017 à Barcelone PloneConf 2017 à Barcelone 27/10/2017

Retours sur la PloneConf 2017 à Barcelone.

PloneConf 2016, un vent nouveau sur Plone PloneConf 2016, un vent nouveau sur Plone 02/11/2016

Résumé de la conférence annuelle sur Plone qui s'est tenue à Boston.

Turning hackability into a use case 27/01/2015

When a CMS does not allow happy hacking anymore, it loses a very valid use case.

collective.z3cform.norobots: a captcha based on questions and answers 15/01/2010

I have released a new captcha widget/field for z3c.form in Plone. Unlike other captcha fields that ...

Plone Unified Installer and ZcxOracleDA 02/12/2010

Trying to setup cx_Oracle and ZcxOracleDA on a Plone/Zope Zeo setup using the Unified Installer ...