Saving a field of type 'text_format' as a theme settings variable I try to add a text area with wysiwyg editor in the theme setting.

If i use '#type' =&gt; 'textfield', it works :



If I use '#type' =&gt; 'text_format', the text is saved but i don’t see it as default value :



If I revert back to '#type' =&gt; 'textfield', i can see this :



I guess it is related to the text_format form which is stored as an array ?

How can I use text_format in theme settings ?

Full code in mytheme.theme

function MYTHEME_form_system_theme_settings_alter(&amp;$form, \Drupal\Core\Form\FormStateInterface &amp;$form_state, $form_id = NULL) {

  $form['mytheme_texte_presentation'] = array(
    '#type'          =&gt; 'text_format',
    '#title'         =&gt; t('Test theme settings'),
    '#default_value' =&gt; theme_get_setting('mytheme_texte_presentation'),
    '#description'   =&gt; t("lorem ipsum"),
  );
}
Text format fields are considered to be a compound field (meaning that multiple values are stored for the one field -- the value and the format).

If you inspect the value of mytheme_texte_presentation, you'll find an array that looks something like this array =&gt; ['value' =&gt; '&lt;val&gt;', 'format' =&gt; 'html_restreint']. 

If you look at the docs for text_format, you'll see that there is a #format attribute.

Your code should look something like this: 

$texte_presentation = theme_get_setting('mytheme_texte_presentation');
$form['mytheme_texte_presentation'] = array(
    '#type'          =&gt; 'text_format',
    '#title'         =&gt; t('Test theme settings'),
    '#default_value' =&gt; $texte_presentation['value'],
    '#format'        =&gt; $texte_presentation['format'],
    '#description'   =&gt; t("lorem ipsum"),
  );


Note: This is untested code. You may need to tweak this a bit to make it functional.