Problem/Motivation

Drupal core made the class \Drupal\jsonapi\ResourceResponse not implement CacheableResponseInterface anymore. This introduces issues for the module in 9.1. The new class Drupal\jsonapi\CacheableResourceResponse can be used on Drupal >= 9.1.

Proposed resolution

Use the new class Drupal\jsonapi\CacheableResourceResponse if it exists but use \Drupal\jsonapi\ResourceResponse as a fallback to not force everyone to update to Drupal 9.1 immediately.

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:

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

auth created an issue. See original summary.

auth’s picture

Attached patch implementing proposed resolution

marthinal’s picture

I found the same problem. I'm trying to understand if we need to refactor this. There is a Functional test testAddCommentResource() that executes a POST.

$response = $this->request('POST', $url, $request_options);

If I go to AddComment::process

$this->processEntityCreation($request, $document);

We execute processEntityCreation() . If I go to that method I see this $response

$response = $this->createJsonapiResponse($data, $request, 201);

I'm using commerce_api and we have different resources to update or add items and we always return createJsonapiResponse().

I think we can return CacheableResourceResponse if the method is cacheable

    /**
     * Checks whether the method is cacheable or not.
     *
     * @see https://tools.ietf.org/html/rfc7231#section-4.2.3
     *
     * @return bool True for GET and HEAD, false otherwise
     */
    public function isMethodCacheable()
    {
        return \in_array($this->getMethod(), ['GET', 'HEAD']);
    }

otherwise we can return ResourceResponse.

larowlan’s picture

Adding the error message here for folks using duckduckgo etc

The website encountered an unexpected error. Please try again later.
Error: Call to undefined method Drupal\jsonapi\ResourceResponse::addCacheableDependency() in Drupal\jsonapi_resources\Unstable\ResourceResponseFactory->create() (line 81 of modules/contrib/jsonapi_resources/src/Unstable/ResourceResponseFactory.php). 
larowlan’s picture

FileSize
1.92 KB
1.54 KB

Fixing coding standards

mglaman’s picture

Assigned: auth » API-First Initiative

I want to get #3189198: Allow installation with Drupal 9 in quick, so we can test against 9.1

mglaman’s picture

Assigned: API-First Initiative » Unassigned
mglaman’s picture

🤦🏼‍♂️sorry, this module is OK not the module I was trying.

mglaman’s picture

Fixing D9 phpcs failures here: #3189204: Fix PHPCS, then re-running and merging.

mglaman’s picture

Status: Needs review » Reviewed & tested by the community

Committed the PHPCS fix and re-queued the test. Comitting once passed and tagging a release.

mglaman’s picture

FileSize
2.03 KB

Fixing deprecation. I don't know why 9.2 breaks, but 9.1 is good with this.

  • mglaman committed ff13de1 on 8.x-1.x authored by auth
    Issue #3187549 by larowlan, mglaman, auth, marthinal: Become compatible...
mglaman’s picture

Status: Reviewed & tested by the community » Fixed

Thank you all! Tagging a release.

larowlan’s picture

🙏 merci beaucoup

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.