Programmatically set the format for each value of a multi-value text field I am trying to programmatically set the format of a multi value text field to 'full_html'.

I have tried:

$Links = array (1, 2, 3, 4, 5);

$node-&gt;field_article_links[] = $Links;
$node-&gt;field_article_links-&gt;format = 'full_html';
$node-&gt;save();


and

$Links = array (1, 2, 3, 4, 5);

foreach ($Links as $Link) {
$node-&gt;set('field_article_links', $Link);
$node-&gt;field_article_links-&gt;format = 'full_html';
}
$node-&gt;save();


But the results are always the same, only the format of the first value of the field is set to 'full_html' and the others remain unchanged.



What am i doing wrong ?
Please, do not start with capital letter when naming variables, every time you do that a puppy dies.

As 'field_article_links' can have more than one value (probably is a unlimited field), you should treat its value as an array and not as single entity, where each element has its value and format.

To do that, you have to build an array with the field data, then put this array into the field.

The following code is working as you expect:

$links = array (1, 2, 3, 4, 5);    
$field_data = [];
foreach ($links as $link) {
    $element = [];
    $element['value'] = $link;
    if($link === 3) {
        $element['format'] = 'full_html';
    } else {
        $element['format'] = 'dasdas';
    }
    $field_data[] = $element;
}
$node-&gt;field_article_links = $field_data;
$node-&gt;save();