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
- Navigate to
/admin/config/graphql/servers/create - Select "Core Composable Schema" as the schema
- Enable any extension that declares entity type dependencies (e.g. Menu, Media, Taxonomy)
- 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.
| Comment | File | Size | Author |
|---|---|---|---|
| graphql_core_schema-validate-form-element-null-check.patch | 1.43 KB | ugolek |
Issue fork graphql_core_schema-3582412
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
Comment #3
aayushpathak commentedworking.
Comment #5
aayushpathak commented