Problem/Motivation

Since Drupal 11.3, core no longer adds a body field to new content types (node_add_body_field() is deprecated, see the change record). When Gutenberg is enabled on such a content type, the node add form crashes:

InvalidArgumentException: Field is unknown. in Drupal\Core\Entity\ContentEntityBase->getTranslatedField()
...
gutenberg_form_node_form_alter()

UtilsController::getEntityTextFields() returns no field, and gutenberg_form_node_form_alter() calls $node->get($text_fields[0]). The same thing happens if the text field of a Gutenberg content type is deleted.

Steps to reproduce

  1. On Drupal 11.3 or later, add a content type with "Enable Gutenberg experience" checked.
  2. Go to node/add/<type>.

Proposed resolution

  • Treat a content type without a formatted text field as not Gutenberg enabled (_gutenberg_is_gutenberg_enabled(), with a new GutenbergContentTypeManager::hasTextField()), so its node form falls back to the default form.
  • Show a warning on the Manage Gutenberg tab while Gutenberg is enabled and the content type has no formatted text field, linking to Manage fields. Show it too after adding a content type with Gutenberg enabled.

Remaining tasks

  • Review the MR.

User interface changes

A warning on the Manage Gutenberg tab (and after adding a content type) when the content type has no formatted text field.

Issue fork gutenberg-3629888

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

marcofernandes created an issue. See original summary.

  • marcofernandes committed c9cd2a14 on 4.0.x
    Issue #3629888: Node form crashes when a Gutenberg content type has no...
marcofernandes’s picture

Status: Active » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.