Skip to main content

Drupal 8: embed entity wysiwyg custom form and then render the value in another form.

Updated by Tim Rabbetts on
technology, keyboard, computing

Its possible to easily embed entites into the Drupal 8 wysiwyg editor, however, I have a custom form and when I rendered it in another form it didnt render correctly.  The reason was I used markup not processed_text field type.

So the original settings form where I add my markup and entity ref is built like this:

$form['intro_text'] = [
  '#type' => 'text_format',
  '#format' => \Drupal::state()->get('myid')['format'],
  '#title' => t('Intro text'),
  '#default_value' => \Drupal::state()->get('myid')['value'],
];

Then in another form to show this text I do this:

$form['output_markup'] = [
  '#type' => 'processed_text',
  '#text' => \Drupal::state()->get('myid')['value'],
  '#format' => \Drupal::state()->get('myid')['format'],
];

 

Add new comment