2

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.

8
  • 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.
    – apaderno
    Commented Aug 25, 2021 at 11:59
  • Is there a reason you’re redeclaring an existing route? What happens if you delete that custom route and clear cache?
    – Clive
    Commented Aug 25, 2021 at 11:59
  • 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.
    – apaderno
    Commented Aug 25, 2021 at 12:02
  • 1
    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
    – Clive
    Commented Aug 25, 2021 at 16:05
  • 1
    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
    – Clive
    Commented Aug 25, 2021 at 16:30

0

Your Answer

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

Browse other questions tagged or ask your own question.