Problem/Motivation
If you return a \Drupal\rest\ResourceResponse from a custom route, you get a crash:
> TypeError: Symfony\Component\Serializer\Encoder\ChainEncoder::getEncoder(): Argument #1 ($format) must be of type string, null given, called in /var/www/vendor/symfony/serializer/Encoder/ChainEncoder.php on line 49 in Symfony\Component\Serializer\Encoder\ChainEncoder->getEncoder() (line 80 of /var/www/vendor/symfony/serializer/Encoder/ChainEncoder.php).
This is because ResourceResponseSubscriber::getResponseFormat() looks at the route definition for the _format requirement. If that is missing, then a NULL is incorrectly passed as a parameter.
Steps to reproduce
Proposed resolution
Add documentation to \Drupal\rest\ResourceResponse to say the route needs this requirement to be set.
Remaining tasks
User interface changes
API changes
Data model changes
Release notes snippet
Issue fork drupal-3277148
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 #2
larowlanComment #3
Jingting commentedI am a novice at Drupalcon working on this issue in a mentor contribution group for the next hour.
Comment #4
farnoosh commentedI am mentoring @Athrylith and @Jingting on this issue at Drupalcon Portland Mentored contribution. We will be working on this issue during the mentored contribution session on Wednesday, Apr 27th
Comment #5
athrylith commentedI am working on this issue at Portland DrupalCon
Comment #6
farnoosh commentedThis solution was posted on the "contribute" channel on Drupal Slack by @Jingting:
Comment #10
rpayanmComment #11
joachim commentedComment #13
andregp commentedAddressing @joachim comment.
Comment #14
joachim commentedLooks great, thanks!
Comment #17
catchCommitted/pushed to 10.0.x, cherry-picked to 9.5.x and 9.4.x, thanks!