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);
$node->save();
drupal_set_message('Your form has been submitted. It will be reviewed by the team.');
$redirect_path = "/user";
$url = url::fromUserInput($redirect_path);
$form_state->setRedirectUrl($url);
}
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.
entity_create
is deprecrated and will be removed before Drupal 9.0.0 You should useentityManager
as shown heredeprecated
. 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.entity_create
to work in D7. Which explains why there isn't any official docs for it in D7.