Problem/Motivation

ViewModeAccessCheck, FormModeAccessCheck and FieldReuseAccessCheck call $route_match->getRawParameter($bundle_entity_type). For an entity type with a bundle key but no bundle entity type, $bundle_entity_type is NULL, so this throws:

TypeError: Symfony\Component\HttpFoundation\InputBag::get(): Argument #1 ($key) must be of type string, null given

When the base route path has no {bundle}, Field UI's RouteSubscriber sets the bundle default on those routes to an empty string, so the checks reach that call.

Steps to reproduce

  1. Install the standard profile on 11.4.
  2. composer require drupal/menu_item_fields:1.11.0, enable menu_item_fields and menu_item_fields_ui. This sets field_ui_base_route of menu_link_content to entity.menu.collection.
  3. As admin, visit /admin/structure/menu/display.
  4. Result: 500 with the TypeError above.

These steps work on 11.4.x; menu_item_fields 1.x doesn't install on main, and 2.x sets the bundle default itself. The display overview route these checks run on was added in #3564234.

On main there is no core-only UI reproduction (core entity types without a bundle entity type use {bundle} in their base route). The kernel test in the MR uses entity_test, which has a bundle key but no bundle entity type, and fails on main without the fix.

Proposed resolution

Only read the raw bundle parameter when the entity type has a bundle entity type, in all three access checks. Otherwise fall back to the entity type ID as bundle, as EntityViewDisplayOverviewController and EntityViewDisplayStatusController already do, so enabled non-default view and form modes aren't denied.

Remaining tasks

Review MR !17553.

User interface changes

None.

Introduced terminology

None.

API changes

None.

Data model changes

None.

Release notes snippet

N/A

Generated with the help of an LLM.

Issue fork drupal-3398579

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

jessey created an issue. See original summary.

jessey’s picture

Issue summary: View changes
StatusFileSize
new836 bytes
longwave’s picture

Issue summary: View changes
Issue tags: +Needs steps to reproduce

What did you do to trigger this error message? This feels like an incomplete routing definition somewhere.

cilefen’s picture

Status: Active » Postponed (maintainer needs more info)
gigimaor’s picture

In my case, after updating the core version to 10.2.2
In /admin/config/people/accounts

TypeError: Symfony\Component\HttpFoundation\InputBag::get(): Argument #1 ($key) must be of type string, null given, called in /code/web/core/lib/Drupal/Core/Routing/RouteMatch.php on line 127 in Symfony\Component\HttpFoundation\InputBag->get() (line 29 of /code/vendor/symfony/http-foundation/InputBag.php).
Drupal\Core\Routing\RouteMatch->getRawParameter() (Line: 61)
Drupal\workflow_field_groups\Access\WorkflowFieldGroupsAccessCheck->access()
call_user_func_array() (Line: 160)
Drupal\Core\Access\AccessManager->performCheck() (Line: 136)
Drupal\Core\Access\AccessManager->check() (Line: 93)
...

In my case, it is caused by a module that is not supported anymore but is still in use: workflow_field_groups

On this line web/core/lib/Drupal/Core/Routing/RouteMatch.php on line 127 $parameter_name is NULL

  public function getParameter($parameter_name) {
    return $this->parameters->get($parameter_name);
  }

Preventing this from happening could be done by patching this line
return $this->parameters->get($parameter_name);
to this
return $this->parameters->get($parameter_name ?? '');

longwave’s picture

The fix should be made in workflow_field_groups, why is it calling getRawParameter(NULL)?

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

quietone’s picture

Status: Postponed (maintainer needs more info) » Closed (works as designed)

It has been over a year and there has been no further discussion. In #6 it was stated is not in core. Therefor, I am closing this issue.

jessey’s picture

Version: 11.x-dev » 11.4.x-dev
Status: Closed (works as designed) » Needs review
StatusFileSize
new2.11 KB

On Drupal 11.4, Field UI local tasks fatal with:

TypeError: InputBag::get(): Argument #1 ($key) must be of type string, null given in RouteMatch::getRawParameter().

11.4 stores raw route parameters in Symfony InputBag, which requires a string key. 11.3 used ParameterBag, which accepted null.

ViewModeAccessCheck (also FormModeAccessCheck / FieldReuseAccessCheck) does:

$route_match->getRawParameter($entity_type->getBundleEntityType());
For entity types with a bundle key but no bundle entity type (e.g. menu_link_content with field_ui_base_route set by Menu Item Fields UI), getBundleEntityType() is NULL. Visiting Structure → Menus then crashes.

Fix: $entity_type->getBundleEntityType() ?? '' in those three access checks.

ironnuts’s picture

Re: #9 Good to know but steps to reproduce are still needed. A screenshot(s) or a screencast showing how this is triggered would also help. We need to know if it is a standard profile installation. Any themes that are enabled and being used, any core modules that need to be enabled. Do we need to create a content type and add a field? Any field? Then what?

quietone’s picture

Issue summary: View changes
Status: Needs review » Postponed (maintainer needs more info)
Issue tags: +Needs title update

As stated this needs steps to reproduce to help determine the cause of the problem.

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

bceyssens’s picture

Steps to reproduce on 11.4.11:

  1. Install the standard profile.
  2. composer require drupal/menu_item_fields:1.11.0, then enable menu_item_fields and menu_item_fields_ui. This sets field_ui_base_route of menu_link_content to entity.menu.collection.
  3. As admin, visit /admin/structure/menu/display.

Result: a 500 with TypeError: Symfony\Component\HttpFoundation\InputBag::get(): Argument #1 ($key) must be of type string, null given, from ViewModeAccessCheck::access().

menu_link_content has a bundle key but no bundle entity type. Field UI's RouteSubscriber sets the bundle default of that route to ''. ViewModeAccessCheck then calls getRawParameter(NULL). FormModeAccessCheck and FieldReuseAccessCheck have the same code.

Menu Item Fields 2.1.1 sets the bundle default on the 11.4 overview route, so the error does not show with that version.

MR !17553 only reads the raw parameter when the entity type has a bundle entity type, in all three checks. It adds a kernel test with entity_test, which has a bundle key but no bundle entity type. The test fails without the fix with the same TypeError.

Generated with the help of an LLM.

bceyssens’s picture

Status: Postponed (maintainer needs more info) » Needs review
smustgrave’s picture

Status: Needs review » Needs work

Tags still need to be addressed

Please review https://www.drupal.org/docs/develop/issues/issue-procedures-and-etiquett... if continuing with the AI submissions.

bceyssens’s picture

Title: TypeError: Symfony\Component\HttpFoundation\InputBag::get(): Argument #1 ($key) must be of type string, null given, called in /var/www/html/docroot/core/lib/Drupal/Core/Routing/RouteMatch.php on line 127 in Symfony\Component\HttpFoundation\InputBag->get() » Field UI access checks pass NULL to getRawParameter() for entity types without a bundle entity type
Version: 11.4.x-dev » main
Issue summary: View changes
Status: Needs work » Needs review
Issue tags: -Needs steps to reproduce, -Needs title update