In a Drupal 8 project I've a controller which returns a form that contains a text_format field.
CKeditor is working perfectly in my administration theme (Stable), but it does not on the default theme.
I've tried to attach ckeditor core module libraries to the controller returned response with no results.
The role which I test with has permissions "Use simple HTML text format", "Use full HTML text format", also the role is checked on /admin/config/content/formats/manage/basic_html
also on /admin/config/content/formats/manage/full_html
.
my_module/src/Controller/MyController.php :
<?php
namespace Drupal\my_module\Controller;
use Drupal\Core\Controller\ControllerBase;
use Drupal\user\Entity\User;
/**
* Provide user form.
*/
class MyController extends ControllerBase {
/**
* Return page content.
*/
public function content() {
// Load user edit form.
$entity = User::load(\Drupal::currentUser()->id());
$formObject = \Drupal::entityTypeManager()
->getFormObject('user', 'default')
->setEntity($entity);
$form = \Drupal::formBuilder()->getForm($formObject);
$render = \Drupal::service('renderer');
$render_form = $render->renderPlain($form);
return [
'#theme' => 'customize_user_form',
'#form' => $render_form,
'#attached' => [
// Attach ckeditor core module libraries.
'library' => [
'ckeditor/drupal.ckeditor',
'ckeditor/drupal.ckeditor.stylescombo.admin',
'ckeditor/drupal.ckeditor.admin',
'ckeditor/drupal.ckeditor.plugins.drupalimagecaption',
],
],
];
}
}
Results:
Any suggestions?
Many thanks.