Problem/Motivation

After upgrading rest_menu_items from 3.0.6 to 3.0.7, requests to the REST menu endpoint fail with a PHP fatal error.

Error:

Error: Typed property
Drupal\rest_menu_items\Plugin\rest\resource\RestMenuItemsResource::$cacheableUrlMetadata
must not be accessed before initialization in
Drupal\rest_menu_items\Plugin\rest\resource\RestMenuItemsResource->captureGeneratedUrl()
(line 516 of modules/contrib/rest_menu_items/src/Plugin/rest/resource/RestMenuItemsResource.php).

The issue did not occur in version 3.0.6 and started immediately after updating to 3.0.7.

Steps to reproduce

1. Install rest_menu_items 3.0.6.
2. Configure and verify that the REST menu endpoint is working.
3. Update the module to version 3.0.7.
4. Clear caches.
5. Request a menu endpoint.
6. Observe the fatal error.

Proposed resolution

Investigate initialization of the cacheableUrlMetadata property. It appears that captureGeneratedUrl() can access the property before it has been initialized.

Ensure cacheableUrlMetadata is instantiated before use, or add a null/initialization check before accessing it.

Remaining tasks

- Reproduce issue on a clean installation.
- Identify the code path that skips initialization.
- Create and test a patch.
- Add automated test coverage.

User interface changes

None.

API changes

None expected

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

thampiajit created an issue. See original summary.

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

batigolix’s picture

Status: Active » Needs review
Issue tags: -D10 cacheability +finalist-sprint

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

fabianderijk’s picture

Status: Needs review » Reviewed & tested by the community

I've updated the MR and added a unit test. Marking this as RTBC and merging it as well. In the pipeline there are still some phpstan errors. I will create a new issue to fix that.

fabianderijk’s picture

Status: Reviewed & tested by the community » 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.