By peterk900 on
I have code which creates an artice from JSON.
$article = $node_storage->create([
'type' => 'article',
'title' => $json['title'],
'field_int100' => $json['int100'],
'field_text100' => $json['text100'],
'body' => $json['body'],
]);
$article->save();By default, the text format is Plain Text. Modifying the code which specifies the value of the body field will import the text with HTML formatting.
'body' => [
'value' => $json['body'],
'format' => 'full_html'
],I got this code from an AI query. How can I find the property statements for other properties? E.g IsPublished, Author details. I guess this information comes from a class somewhere in Drupal core but so far I can't find the file. Can anyone help? Thanks.
Comments
The "properties" are field
The "properties" are field names on the entity type. The code you showed is creating an entity of type node, with a bundle type of article. There are three types of fields on an entity:
field_, egfield_user_picture, although sometimes they will not be, for examplebody.Contact me to contract me for D7 -> D10/11 migrations.
Thanks.
The link \Drupal\node\Entity\Node::baseFieldDefinitions was useful.
I managed to find two code snippets which give me the machine names for the properties I'm after, including entity and field level.
I still can't find the core code which specifies these keys ( published, status, sticky etc.). But I think I have all the values which apply for nodes.