I am very new to Drupal and is still learning. Please excuse if I have done my coding wrong.

Problem: I wanted to add two buttons to my Content type.

  • 1st button for Save Form - save the form and not publish it.
  • 2nd button to Submit Form - save the form and submit it.

My Save Form button works right and it uses the default submit handler.

My Submit Form button is calling a custom submit handler and here is the code:

  function submit_Form(array $form, FormStateInterface $form_state) {
  $values = $form_state->getValues();
  $node = entity_create('node',$values);

  drupal_set_message('Your form has been submitted. It will be reviewed by the team.');
  $redirect_path = "/user";
  $url = url::fromUserInput($redirect_path);


I am getting this error:

Drupal\Core\Entity\EntityStorageException: Missing bundle for entity type node in Drupal\Core\Entity\ContentEntityStorageBase->doCreate() (line 83 of /var/www/clients/client1/web2/web/core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php).

Thank you for looking at this.

  • FYI entity_create is deprecrated and will be removed before Drupal 9.0.0 You should use entityManager as shown here
    – No Sssweat
    Commented May 19, 2017 at 10:27
  • @NoSssweat deprecrated ... lots of rrrrrrrrrrrr .... PS: would be nice if you could prrrrredicrrrrt the rrrrrrrrrrrelease date of 9.0.0 ??? Commented May 19, 2017 at 10:41
  • @Pierre.Vriens mb, I knew it looked a lil funny, deprecated. It says before 9.0.0 which means could be at any time in D8 life. I rather not predict any D9 release date, look what happened with D8, lol.
    – No Sssweat
    Commented May 19, 2017 at 10:47
  • @NoSssweat I think it is already no longer (?!?!) included in D7 ... Commented May 19, 2017 at 11:14
  • 1
    @Pierre.Vriens I think you need the contrib entity module in order for entity_create to work in D7. Which explains why there isn't any official docs for it in D7.
    – No Sssweat
    Commented May 19, 2017 at 11:25

1 Answer 1


When you create an entity node a value type for the content type is required. If your form doesn't provide one, you can add it to the values before creating the node:

  $values = $form_state->getValues();
  $values[] = ['type' => 'article'];
  $node = \Drupal\node\Entity\Node::create($values);
  • I tried to add the type but it is still giving me the error. I also tried NoSsweat suggestion to install entity module. But it also did not solve the error. By the way I am using D8. Thank you for helping me out.
    – ernzkee
    Commented May 22, 2017 at 2:55
  • @ernzkeem, this is the "Missing bundle for entity type node" from the error message, but I don't know what else is in $values.
    – 4uk4
    Commented May 22, 2017 at 6:17
  • I created a Content Type with all the fields on it in the Dashboard. I am hoping that the $values gets all the values in the fields of my Content Type once the Submit Form button is clicked. I am hoping to save all that is in my node edit form. Do you know any other way to do that?
    – ernzkee
    Commented May 22, 2017 at 7:08
  • I don't think that replacing the submit is so easy. Content moderation and Workflows is now in core, did you try this?
    – 4uk4
    Commented May 22, 2017 at 7:23
  • I tried to enable the Content Moderation and my site /admin/modules page breaks. What can I do to revert it?
    – ernzkee
    Commented May 22, 2017 at 8:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.