Answers:
您可以尝试此代码
<?php
use Drupal\node\Entity\Node;
$node = Node::load($nid);
//set value for field
$node->body->value = 'body';
$node->body->format = 'full_html';
//field tag
$node->field_tags = [1];
//field image
$field_image = array(
'target_id' => $fileID,
'alt' => "My 'alt'",
'title' => "My 'title'",
);
$node->field_image = $field_image;
//save to update node
$node->save();
在Drupal 8.x中不推荐使用node_load,它将在Drupal 9.0之前删除。使用\ Drupal \ node \ Entity \ Node :: load()。
引用https://api.drupal.org/api/drupal/core%21modules%21node%21node.module/function/node_load/8.3.x
旧方法也对我有效:
$node=node_load($nid);
print_r($node->body->format);
$node->body->format='full_html';
print_r($node->body->format);
$node->save();