Please Disable Your Browser Adblock Extension for our site and Refresh This Page!

our ads are user friendly, we do not serve popup ads. We serve responsible ads!

Refresh Page
Skip to main content
On . By CodimTh

Code snippet that can be used to change field text format programmatically in Drupal 8.

Example field in node:

$node = \Drupal::entityTypeManager()->getStorage('node')->load($nid);
$node->body->value = 'body';
$node->body->format = 'full_html';

Example field in form:

$form['description']['widget'][0]['#format'] = "basic_html";





Submitted by C.E.A (not verified) on Wed, 05/20/2020 - 09:43 Permalink

Can you show us please how to set the format of a multi-value text field to 'full_html' ? $Links = array (1, 2, 3, 4, 5); $node->field_article_links[] = $Links; $node->field_article_links->format = 'full_html'; $node->save(); And $Links = array (1, 2, 3, 4, 5); foreach ($Links as $Link) { $node->set('field_article_links', $Link); $node->field_article_links->format = 'full_html'; } $node->save(); did not worked for me and they are setting the first value only to 'full_html' and the other remain unchanged
Add new comment

Restricted HTML

Riadh Rahmi

Senior Web Developer (Drupal & Laravel)

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

Web Posts


Page Facebook