Use CKEditor on textarea in custom module's controller response I am trying to figure out how to use Drupal 8's CKEditor on &lt;textarea&gt;&lt;/textarea&gt; tags that are part of a controllers markup and not generated from a Drupal form.

Has anyone done this or can Drupal 8's integrated CKEditor only be used with Drupal Forms?

When I try to use ckeditor with the standard way of CKEDITOR.replace('element'); I get the error that config.js and styles.js are missing.  Which should be the case because Drupal has consciously excluded them from their integrated CKEditor. https://www.drupal.org/project/drupal/issues/2604052

After digging around I found the javascript call Drupal.editors.ckeditor.attach(element, format) but I can't figure out what to pass in for the format parameter.  Looking at other javascript code it appears they they use the drupalSettings global variable in javascript to pass it in but it's not there.

Any help on this would be greatly appreciated.

My code is below.

my_module.routing.yml

my_module.myroute:
  path: '/my-route'
  defaults:
    _title: 'Test Module'
    _controller: '\Drupal\my_module\Controller\HomeController::view'
  requirements:
    _access: 'TRUE'


my_module.libraries.yml

scripts:
  js:
    my_script.js: {}
  dependencies:
    - ckeditor/drupal.ckeditor


my_script.js

window.onload = function () {
    let element = jQuery("#testelement");
    let format = "filtered_html";
    Drupal.editors.ckeditor.attach(element, format);
};


HomeController.php

&lt;?php

namespace Drupal\my_module\Controller;

use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Render\Markup;

class HomeController extends ControllerBase
{

    function view()
    {
        return [
            "#attached" =&gt; [
                "library" =&gt; ["my_module/scripts"]
            ],
            "#markup" =&gt; Markup::create("
                &lt;textarea name='testelement' id='testelement'&gt;&lt;/textarea&gt;            
            ")
        ];
    }
}
I'd imagine you just return the same element you'd build into a form, and use a format that's configured to use a WYSIWYG:

return [
  '#attached' =&gt; ...,
  '#type' =&gt; 'text_format',
  '#title' =&gt; 'Foo',
  '#format' =&gt; 'full_html', 
];


See the TextFormat class for more options.