Score:2

Missing bundle for entity type node after upgrading

ph flag

I recently upgraded a local sandbox to Drupal core 9.2.4. While testing things out, I got an error when trying to add a new article content from /node/add/article.

The log shows the following message.

Drupal\Core\Entity\EntityStorageException: Missing bundle for entity type node in Drupal\Core\Entity\ContentEntityStorageBase->doCreate() (line 97 of /var/www/drupal9sandbox/docroot/core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php).

The only change I made prior to this is that in the article.routing.yml file. I had to use _entity_form: 'node.default' in lieu of Drupal\node\Controller\NodeController::add() as that is deprecated in Drupal 9, as reported in NodeController::add() method is deprecated.

This is the complete content of the articles.routing.yml file.

Apart from the small change to _entity_form: 'node.default', I did not touch anything else.

custom_articles.add_content:
  path: '/node/add/article'
  defaults:
    _entity_form: 'node.default'
    _title_callback: '\Drupal\node\Controller\NodeController::addPageTitle'
    node_type: 'article'
  requirements:
    _node_add_access: 'node:article'
  options:
    _node_operation_route: TRUE
    parameters:
      node_type:
        with_config_overrides: TRUE

I am not sure where the bundle type would be defined, but this content type was working well on Drupal 8.9.16.

apaderno avatar
us flag
As side note, if *Article* is a content type defined on the site, you don't need to define a route for it: The Node module will take care of that. In fact, it has a route for */node/add/{node_type}*, which is valid for every content type the site has.
cn flag
Is there a reason you’re redeclaring an existing route? What happens if you delete that custom route and clear cache?
apaderno avatar
us flag
To confirm @Clive comment, the *Standard* installation profile used from Drupal 9 (but also previous Drupal versions) already adds an *Article* content type. If Drupal is installed using a different installation profile, *Article* could not be a predefined content type, but still there isn't any need to add a custom route when the Node module would take care of it.
ph flag
@Clive, the route was already there before. The only change I made was under defaults. Instead of `_entity_form: 'node.default'`, It was using `controller:'Drupal\node\Controller\NodeController::add()'`. However, that has been deprecated in Drupal 9.
cn flag
Unless you have a really good reason for creating a custom route for a path that already exists and is controlled by the system, you should remove that code. Otherwise you'll have to keep maintaining it inline with core updates, for no benefit. Anything you could do in the re-declared route, you can do "properly" via another method
ph flag
@Clive, I just removed it and it worked! According to this [changelog](https://www.drupal.org/node/3084856) The Add() controller was removed from Drupal 9 and is now handled by `_entity_form. It didn't specify what to use instead, so I guess they meant to imply to just remove the Add() controller if you're using it.
cn flag
In case this isn't what you meant, you should remove the whole route declaration IMO. It's unnecessary and could cause you more headaches in the future. Whoever wrote that probably had a great grasp of the Symfony API, but maybe less of a grasp of the Drupal API
ph flag
This was build early on when we migrated to Drupal. So I guess they wrote it based on boilerplate template available to them before. All succeeding content types that were created doesn't have all this. so the solution was to remove that add block in the routing.yml file. How do I accept your answer?
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.