Skip to main content
Category:

Code snippet that can use to add input format to textarea in drupal 8.

$form['description'] = [
  '#type' => 'text_format',
  '#format' => 'full_html',
  '#title' => $this->t('Description'),
  '#default_value' => $config->get('description') ? $config->get('description') : '',
];

the result is like this:

textformat field

also there are others Properties:

  • #base_type: The form element #type to use for the 'value' element. 'textarea' by default.
  • #format: (optional) The text format ID to preselect. If omitted, the default format for the current user will be used.
  • #allowed_formats: (optional) An array of text format IDs that are available for this element. If omitted, all text formats that the current user has access to will be allowed.

 

Riadh Rahmi

Senior Web Developer PHP/Drupal & Laravel

I am a senior web developer, I have experience in planning and developing large scale dynamic web solutions especially in Drupal & Laravel.

Web Posts

Search

Page Facebook