ResourceResponseTrait needs a setData() method to be consistent with the API

Created on 18 July 2022, about 2 years ago
Updated 16 February 2023, over 1 year ago

Problem/Motivation

Symfony's Response class has a setContent() method. This is equivalent to passing the content of the response in the constructor.

It means you can do things like create a HtmlResponse, call addCacheableDependency() on it in the same part of the code as where entities are being loaded, and then finally do setContent() at the end. This improves readability and maintainability of the code.

ResourceResponse uses ResourceResponseTrait to store the JSON data for the response in the $responseData property. The trait has a getResponseData() method, but no setResponseData().

This doesn't follow the same pattern as the base class and makes it harder to work with.

Steps to reproduce

Proposed resolution

TBD

Remaining tasks

Update issue summary
TBD

User interface changes

API changes

New method on ResourceResponse and ResourceResponseTrait.

Data model changes

Release notes snippet

πŸ› Bug report
Status

Needs work

Version

10.1 ✨

Component
RESTΒ  β†’

Last updated 6 days ago

Created by

πŸ‡¬πŸ‡§United Kingdom joachim

Live updates comments and jobs are added and updated live.
  • Novice

    It would make a good project for someone who is new to the Drupal contribution process. It's preferred over Newbie.

  • Needs issue summary update

    Issue summaries save everyone time if they are kept up-to-date. See Update issue summary task instructions.

  • Needs change record

    A change record needs to be drafted before an issue is committed. Note: Change records used to be called change notifications.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    This issue is being reviewed by the kind folks in Slack, #needs-review-queue-initiative. We are working to keep the size of Needs Review queue [2700+ issues] to around 400 (1 month or less), following Review a patch or merge request β†’ as a guide.

    Think code wise this is good but will need an issue summary update

    Also will need a change record to announce the new trait.

Production build 0.71.5 2024