I am creating nodes using the below code.

$node = Node::create([
  // The node entity bundle.
  'type' => 'exercise',
  'langcode' => 'en',
  'created' => $ex->created,
  'changed' => $ex->changed,
  // The user ID.
  'uid' => $ex->uid,
  'title' => $ex->title,
  'field_lesson' => $nid,
  'body' => [
    'summary' => $ex->summary,
    'value' => $ex->body,
    'format' => 'full_html',
  'field_fret_text' => ['value' => $ex->frettxt,
                        'format' => 'full_html'],
  'field_intro' => ['value' => $ex->intro,
                    'format' => 'full_html']


For the most part everything works, but the format column is not being set for my custom fields field_intro and field_fret_text; only the value is being set. I would have thought that specifying the columns as in the case with the body field would work.

How do I set the input format for those fields that are not the node body?

  • Yes, that should definitely work. Based on what do you conclude that it doesn't? – Berdir Oct 12 '15 at 6:20
  • Note: Setting changed is pointless, that will always be overwritten on save and you can also leave out langcode, that will automatically be set to the default langcode (except when your default langcode is not en, of course). – Berdir Oct 12 '15 at 6:21
  • Actually, everything seems to be working. I really don't know what to make of it. I ran my script, refreshed phpmyadmin, took a look, and saw NULLs in the columns. This must be user error! – Brian Huether Oct 12 '15 at 6:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.