ckeditor in Drupal 8 custom module

Max

I am currently developing a custom module for Drupal 8. While adding a backend form to get some data from users I tried to get the ckeditor configured to replace my textareas... and failed >.<

here is the form definition:

    $form['text'] = array(
        '#type' => 'textarea',
        '#title' => t('Text'),
        '#required' => TRUE,
        '#attributes' => array(
            'id' => 'text',
            'style' => 'max-width: 650px'
        ),
        '#default_value' => $data['text']
    );

where do I need to load the ckeditor to replace my textarea?

things I already tried:

$build['#attached'] = array(
        'js' => array(
          drupal_get_path('module', 'ckeditor') . '/js/ckeditor.js'
drupal_render($build);

and

drupal_load_library("ckeditor", "ckeditor");

but I can't load all the dependencies

baikho

Refer to the Drupal 8 form API which has a text_format form type. A check on your #default_value is also recommended.

Navigate to Configuration > Content authoring > Text formats and editors giving you an overview of the current available text formats. The ones listed here can be used in the #format proprty of your form field. (Default fallback currently is basic_html)

Try to change your code to:

$form['text'] = array(
    '#type' => 'text_format',
    '#title' => t('Text'),
    '#required' => TRUE,
    '#default_value' => isset($data['text']) ? $data['text'] : '',
    '#format' => 'full_html',
);

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Drupal 8 Custom Module Libraries

From Dev

Drupal 8 custom module add php classes

From Dev

Drupal 8 custom block (module) create twig template file

From Dev

Custom module in drupal 8, tab not created in admin section

From Dev

Drupal 8 Creating a module

From Dev

How to use Drupal CKEditor Module for nested numbering

From Dev

Drupal Search function in custom module

From Dev

Drupal 8 Module Development Dependencies

From Dev

Drupal 8 - Block module as a webservice

From Dev

Drupal 8 custom registration form

From Dev

Drupal 8 Custom form with popup

From Dev

How to set permission in custom drupal module in Drupal7

From Dev

Drupal disable button after clicking 3 times in drupal custom module

From Dev

How to resize uploaded inline images with ckeditor in drupal 8

From Dev

Static HTML page in custom Drupal Module

From Dev

Static HTML page in custom Drupal Module

From Dev

Drupal 6 securing files in custom module folder

From Dev

Drupal multiple ajax calls to a custom module

From Dev

Drupal 7: custom module: display custom contentTypy in custom block

From Dev

"Hierarchical Select" alternate module for Drupal 8

From Dev

Deleting Content On Module Uninstall in Drupal 8

From Dev

How to get custom block content in drupal 8

From Dev

Custom 404 template file in Drupal 8

From Dev

Drupal 8 Custom Field // Primitive error

From Dev

Drupal 8 custom menu item different URI

From Dev

Drupal : Create variable from custom .module to custom .tpl.php

From Dev

What is the Drupal 8 equivalent of Drupal 7's "drupal_add_html_head" within a module?

From Dev

Drupal 7 module custom JavaScript AJAX function calls

From Dev

Dynamically creating a link to a custom made page with Drupal Module

Related Related

  1. 1

    Drupal 8 Custom Module Libraries

  2. 2

    Drupal 8 custom module add php classes

  3. 3

    Drupal 8 custom block (module) create twig template file

  4. 4

    Custom module in drupal 8, tab not created in admin section

  5. 5

    Drupal 8 Creating a module

  6. 6

    How to use Drupal CKEditor Module for nested numbering

  7. 7

    Drupal Search function in custom module

  8. 8

    Drupal 8 Module Development Dependencies

  9. 9

    Drupal 8 - Block module as a webservice

  10. 10

    Drupal 8 custom registration form

  11. 11

    Drupal 8 Custom form with popup

  12. 12

    How to set permission in custom drupal module in Drupal7

  13. 13

    Drupal disable button after clicking 3 times in drupal custom module

  14. 14

    How to resize uploaded inline images with ckeditor in drupal 8

  15. 15

    Static HTML page in custom Drupal Module

  16. 16

    Static HTML page in custom Drupal Module

  17. 17

    Drupal 6 securing files in custom module folder

  18. 18

    Drupal multiple ajax calls to a custom module

  19. 19

    Drupal 7: custom module: display custom contentTypy in custom block

  20. 20

    "Hierarchical Select" alternate module for Drupal 8

  21. 21

    Deleting Content On Module Uninstall in Drupal 8

  22. 22

    How to get custom block content in drupal 8

  23. 23

    Custom 404 template file in Drupal 8

  24. 24

    Drupal 8 Custom Field // Primitive error

  25. 25

    Drupal 8 custom menu item different URI

  26. 26

    Drupal : Create variable from custom .module to custom .tpl.php

  27. 27

    What is the Drupal 8 equivalent of Drupal 7's "drupal_add_html_head" within a module?

  28. 28

    Drupal 7 module custom JavaScript AJAX function calls

  29. 29

    Dynamically creating a link to a custom made page with Drupal Module

HotTag

Archive