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
Issue fork rest_menu_items-3615481
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 #4
batigolixComment #6
fabianderijkI'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.
Comment #7
fabianderijk