[MGNLUI-1947] RichTextFieldFactory should support adding CK editor plugins Created: 22/Aug/13  Updated: 03/Feb/16  Resolved: 13/Aug/14

Status: Closed
Project: Magnolia UI
Component/s: None
Affects Version/s: 5.0.3
Fix Version/s: None

Type: Bug Priority: Neutral
Reporter: Ricardo Ulate Assignee: Mikaël Geljić
Resolution: Outdated Votes: 0
Labels: ckeditor, support
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: Text File AbbrRTFFactory.java     Text File AbbrRTFFactoryFailedAttempt.java    
Issue Links:
Relates
relates to MGNLUI-3052 CKEditor can be loaded before registe... Closed
relation
Template:
Patch included:
Yes
Acceptance criteria:
Empty
Task DoD:
[ ]* Doc/release notes changes? Comment present?
[ ]* Downstream builds green?
[ ]* Solution information and context easily available?
[ ]* Tests
[ ]* FixVersion filled and not yet released
[ ]  Architecture Decision Record (ADR)
Bug DoR:
[ ]* Steps to reproduce, expected, and actual results filled
[ ]* Affected version filled
Date of First Response:

 Description   

I contacted Magnolia a few days back and got help with some code on how to add a plugin into the CKEditor within Magnolia.
I’ve successfully been able to do so, but I had several difficulties, which I’ll outline here:

1) I was unable to extend RichTextFieldFactory

My intention to add additional functionality to the RichTextFieldFactory by extending it failed because the method createFieldComponent.
I wanted to do something like:

        String path = VaadinService.getCurrentRequest().getContextPath();
        config.addPlugin(ABBR_PLUGIN_NAME,path+ ABBR_PLUGIN_PATH);
        richTextEditor = (MagnoliaRichTextField) super.createFieldComponent();
        richTextEditor.setConfig(config);

but it seems that the plugins must be configured during the attach phase of the MagnoliaRichTextField, not sure why, this is the code from RichTextFieldFactory#createFieldComponent :

        richTextEditor = new MagnoliaRichTextField(config) {
            @Override
            public void attach() {
                super.attach();
                String path = VaadinService.getCurrentRequest().getContextPath();
                config.addPlugin(PLUGIN_NAME_MAGNOLIALINK, path + PLUGIN_PATH_MAGNOLIALINK);

                WebBrowser browser = getSession().getBrowser();
                if (browser.isTouchDevice()) {
                    // MGNLUI-1528: Workaround.
                    richTextEditor.setEnabled(false);
                    richTextEditor.setReadOnly(true);
                    richTextEditor.addStyleName("richtextfield-disabled");
                }

            }
        };

When adding the plugin there it worked fine, but it means I can’t extend RichTextFieldFactory because I must recreate the private variable richTextEditor.

2) The plugin file must be in /VAADIN/js/abbr

It was difficult to understand why the field was failing, my only guess was that the file was in the wrong location. It worked when I put it there (/abbr is because of the plugin name). It was not clear that it is necessary for the file to be in that location.

Sometimes, not consistently I would get this error, which is what hinted that the file wasn’t being found:

INFO: Requested resource [/VAADIN/widgetsets/info.magnolia.ui.vaadin.gwt.MagnoliaWidgetSet/ckeditor/plugins/abbr/plugin.js] not found from filesystem or through class loader. Add widgetset and/or theme JAR to your classpath or add files to WebContent/VAADIN folder.

Attachments:
I’ll attach two classes, one is my original – failed - attempt and the successful attempt. Hopefully these are useful.

Regards,

Ricardo



 Comments   
Comment by Christian Ringele [ 29/Oct/13 ]

The relation/link to SUPPORT-2848 is that the customer had to add the additional plugins as he described within the ticket.

Comment by Jan Haderka [ 10/Mar/14 ]

Since Magnolia 5.2.2 there is already support for adding custom plugins, the same way as it was available in older versions of Magnolia via customisation of config.js file of CK Editor. Please read following documentation for more details and comment here (with more details) should you find such solution insufficient.
Thank you.

General concept
5.2.2 changes
Rich Text Field documentation

Comment by Mikaël Geljić [ 15/Jul/14 ]

Hi Ricardo,

Would you mind also letting us know whether this one is still relevant?

1. The RichTextFieldFactory is pretty much extensible for some time, as far as I know, see my comment on SUPPORT-2848
2. The loading problem should be gone as of Magnolia 5.3.1 and 5.2.6 (linked MGNLUI-3052).

Kind regards,

Mika

Comment by Mikaël Geljić [ 13/Aug/14 ]

... therefore assuming this issue is no longer up-to-date and needs to be closed. Please do reopen/rephrase in case this is still an issue.

Generated at Mon Feb 12 08:51:41 CET 2024 using Jira 9.4.2#940002-sha1:46d1a51de284217efdcb32434eab47a99af2938b.