MonTea
MonTea

Reputation: 1300

How to add CKEditor RTE to typo3 Backend Module with the API?

This question is similar to that one: RTE in own backend module based on Extbase and Fluid but not the same, so i created a new question.


I create a comment-extension for typo3 Version 8.7.7

I have added a RTE Editor (CKEditor) to a textarea field in my BackendModule.

Therefore i have the following TCA in my comment-model:

'text' => [
    'exclude' => true,
    'label' => 'LLL:EXT:rmcomment/Resources/Private/Language/locallang_db.xlf:tx_rmcomment_domain_model_comment.text',
    'config' => [
        'type' => 'text',
        'enableRichtext' => true,
        'richtextConfiguration' => 'minimal',
        'fieldControl' => [
            'fullScreenRichtext' => [
                'disabled' => false,
            ],
        ],
        'cols' => 40,
        'rows' => 15,
        'eval' => 'trim,required',
    ],
],

The backend template looks like this:

<f:form action="create" name="newComment" object="{newComment}" arguments="{author:beuser.username, email:beuser.email}">

    <strong>Eingeloggt als: {beuser.realname} (Username: {beuser.username}) (Email: {beuser.email})</strong><br>

    <label for="commentEmailCheckbox">Öffentliche E-Mail:</label>
        <f:form.checkbox id="commentEmailCheckbox" property="mailPublic" value="1" />
    <br><br>

    <label for="commentText" class="text{rm:hasError(property:'text',then:' text-danger')}">
        <f:translate key="tx_rmcomment_domain_model_comment.text" />
        <span class="small">( <f:translate key="tx_rmcomment_domain_model_comment.required" /> )</span>
    </label><br>
        <f:form.textarea id="commentText" property="text" cols="120" rows="6" /><br>

    <f:form.submit value="{f:translate(key:'tx_rmcomment_domain_model_comment.saveComment')}" class="btn btn-default" />
</f:form>

Is there a better way to make that RTE working for my Backend-Module without "dirty javascript" (**my answer) inside my fluid-template?**

EDIT

I think this is the only solution, so i move the working part to an answer now.

Upvotes: 0

Views: 1316

Answers (1)

MonTea
MonTea

Reputation: 1300

Under the new form i add this javascript:

<script src="https://cdn.ckeditor.com/4.7.3/standard/ckeditor.js" type="text/javascript"></script>
<script src="/typo3conf/ext/rmcomment/Resources/Public/Backend/RTE/ckcomment.js" type="text/javascript"></script>

My ckcomment.js looks like this:

// Configure New Comment CKEditor-Form
CKEDITOR.config.customConfig = '/typo3conf/ext/rmcomment/Resources/Public/Backend/RTE/backendRTEconfig.js';
CKEDITOR.replace( 'commentText' );
$('.text').click(function(){
    CKEDITOR.instances.commentText.focus();
});

And the backendRTEconfig.js has this content:

CKEDITOR.editorConfig = function( config ) {
    config.toolbar = [
        { name: 'basicstyles', items: [ 'Bold', 'Italic' ] },
        { name: 'paragraph', items: [ 'NumberedList', 'BulletedList', '-', 'Blockquote', ] },
        { name: 'document', items: [ 'Source' ] },
    ];
};

Now i got a CKEditor for my Backend Module with customized editor-buttons. Until now it's the only way i found.

In another extension my custom content elements don't have to load the ckeditor "library" nor my configuration-javascript. There I only had to add the TCA: 'richtextConfiguration' => 'minimal'

If someone know how to activate ckeditor without the javascirpt "loader" in my template, let me know.

Upvotes: 2

Related Questions