Problem/Motivation

When creating a new GraphQL server at /admin/config/graphql/servers/create with Core Composable Schema selected, enabling any extension that has entity type dependencies causes a fatal error:

TypeError: Drupal\Core\Form\FormStateDecoratorBase::setError(): Argument #1 ($element) must be of type array, null given, called in CoreComposableSchema.php on line 254 in Drupal\Core\Form\FormStateDecoratorBase->setError() (line 647 of core/lib/Drupal/Core/Form/FormStateDecoratorBase.php).

Steps to reproduce

  1. Navigate to /admin/config/graphql/servers/create
  2. Select "Core Composable Schema" as the schema
  3. Enable any extension that declares entity type dependencies (e.g. Menu, Media, Taxonomy)
  4. Save the form

Proposed resolution

In CoreComposableSchema::validateConfigurationForm() (line 253), the code accesses $form['enabled_entity_types'][$entityId] without checking if the element exists. When an extension declares an entity type dependency via getEntityTypeDependencies(), the form element may not exist in the form array, returning null, which is then passed to $formState->setError() which requires a non-null array.

Add a null check and fall back to $formState->setErrorByName() (which is already used for extension dependencies on line 267):

$element = $form['enabled_entity_types'][$entityId] ?? NULL;
if ($element) {
  $formState->setError($element, ...);
}
else {
  $formState->setErrorByName('enabled_entity_types', ...);
}

Remaining tasks

Review and commit the patch.

User interface changes

None.

API changes

None.

Data model changes

None.

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

ugolek created an issue. See original summary.

aayushpathak made their first commit to this issue’s fork.

aayushpathak’s picture

working.

aayushpathak’s picture

Status: Active » Needs review