Skip to content

fix(resource): Return full resource from resource/create getObject()#16894

Open
Ibochkarev wants to merge 1 commit intomodxcms:3.xfrom
Ibochkarev:fix/resource-create-getobject-13912
Open

fix(resource): Return full resource from resource/create getObject()#16894
Ibochkarev wants to merge 1 commit intomodxcms:3.xfrom
Ibochkarev:fix/resource-create-getobject-13912

Conversation

@Ibochkarev
Copy link
Collaborator

What does it do?

Resource\\Create::cleanup() now returns the full resource object ($this->object) instead of only ['id' => $this->object->get('id')]. The response is still serialized by modError::process() via toArray(), so $response->getObject() returns all resource fields (pagetitle, description, content, etc.).

Why is it needed?

After resource/create, callers using $response->getObject() received only ['id' => N]. Element create processors already return full or selected fields; resource create was inconsistent and broke code that expects the created resource data.

How to test

  1. Run a snippet that calls $modx->runProcessor('resource/create', $fields) and then $response->getObject().
  2. Confirm the returned array contains pagetitle, description, content, and other resource fields, not only id.
  3. Run _build/test/Tests/Processors/Resource/ResourceCreateTest.php to ensure existing resource creation tests still pass.

Related issue(s)/PR(s)

Resolves #13912

…ssor

Resource\Create::cleanup() now returns $this->object instead of only
['id' => ...], so $response->getObject() contains all resource fields
(pagetitle, description, content, etc.) as with element processors.

Resolves modxcms#13912
@Ibochkarev Ibochkarev marked this pull request as ready for review February 25, 2026 02:51
@biz87
Copy link

biz87 commented Feb 25, 2026

Code Review

Summary

One-line change in Resource\Create::cleanup() that returns the full resource object ($this->object) instead of a minimal ['id' => $this->object->get('id')] array. This aligns resource creation with how other element create processors already work, providing all resource fields via $response->getObject().

Assessment

Clean, minimal change. The success() method calls toArray() on xPDO objects, so all resource fields will be serialized in the response. This is consistent with how Element\Chunk\Create, Element\Snippet\Create and similar processors behave.

Worth noting this is a behavioral change — any existing code that relies on $response->getObject() returning only ['id' => N] will now receive the full resource array. This should be a non-breaking improvement since the id field is still present, but callers that use strict equality checks on the response structure could theoretically be affected.

Verdict: Approve — straightforward fix that improves API consistency.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

resource/create processor no long returns fields other than id

2 participants