FieldCollection Ckeditor

Component ID

2689671

Component name

FieldCollection Ckeditor

Component type

module

Maintenance status

Development status

Component security advisory coverage

not-covered

Component created

Component changed

Component body

This is my solution to render the ckeditor into textarea that is in FieldCollection.

First all, I dont know if there is a better solution... so, I hope that my soluction can help someone :)

The idea is, add the class "field_collection_textarea" into FieldCollection, that is fieldcollection_ckeditor.module:

function fieldcollection_ckeditor_field_widget_form_alter(&$element, &$form_state, $context) {
    if (!isset($element["#field_name"]) || $element["#field_name"] != "field_fc_detalhes") {
        return;
    }
    $element["field_detalhe_conteudo"]['#attributes']['class'][] = "field_collection_textarea";
}

Then, using hook_form_alter, add the js:

function fieldcollection_ckeditor_form_alter(&$form, &$form_state, $form_id) {
    drupal_add_js(drupal_get_path("module", "fieldcollection_ckeditor") . '/field_collection.js');
}

And finally, here the js file field_collection.js:

window.setInterval(function(){
    add_ckeditor();
}, 1000);

function add_ckeditor() {
    jQuery(".field_collection_textarea textarea").each(function(e){
        var id = jQuery(this).attr("id");
        var editor = CKEDITOR.instances[id];
        if (!editor) {
            CKEDITOR.replace(id);
        }
    });
}

Looking carefully, what the js do is: for each 1 second, the javascript find for textarea with 'field_collection_textarea' and apply the Ckeditor.