verbb / smith

A Craft CMS plugin to add copy, paste and clone functionality to Matrix blocks.
MIT License
25 stars 9 forks source link

Copy/Paste/Clone not working on non primary site. #40

Closed belkin closed 2 months ago

belkin commented 2 months ago

Describe the bug

The copy, paste, and clone functionalities in Smith are not working properly in a multi-site setup when editing entries on non-primary sites. These functions work fine on the primary site, but when attempting to use them on the additional sites, the following errors appear in the console:

POST https://SITE-URL.COM/index.php?p=admin%2Factions%2Fsmith%2Ffield%2Frender-matrix-blocks&site=ADDITIONAL-NON-PRIMARY-SITE&v=1719216246654 400 (Bad Request)

{ "message": "Request failed with status code 400", "name": "AxiosError", "stack": "AxiosError: Request failed with status code 400\n at https://SITE-URL.com/cpresources/e19e8d53/axios.js?v=1719215294:1:23147\n at XMLHttpRequest.S (https://SITE-URL.com/cpresources/e19e8d53/axios.js?v=1719215294:1:23292)", "config": { "transitional": { "silentJSONParsing": true, "forcedJSONParsing": true, "clarifyTimeoutError": false }, "adapter": [ "xhr", "http" ], "transformRequest": [ null ], "transformResponse": [ null ], "timeout": 0, "xsrfCookieName": "XSRF-TOKEN", "xsrfHeaderName": "X-XSRF-TOKEN", "maxContentLength": -1, "maxBodyLength": -1, "env": {}, "headers": { "Accept": "application/json, text/plain, */*", "Content-Type": "application/json", "X-Requested-With": "XMLHttpRequest", "X-Registered-Asset-Bundles": "584dc2fd,22e517a2,aee7f8dc,e505ffd6,6b4d7555,e5e48399,bb2f10a0,815d39ea,fc0bc163,1ccab40d,1e21896b,54698ee0,b842675b,1c3c9add,4b1fd285,d8d08e47,8f00ce04,8768f48b,cf3018d6,4c2bac09,7ca18ed1,92d8701,7b7669ac,e7c1329,74b9465b,529c7e4d,841995d6,eccadbb,70b858ad,8f765205,5772f570,b71c5538,15a36a51,9f64c09b", "X-Registered-Js-Files": "", "X-CSRF-Token": "fF952B69C5HemJ3HcwRTJfK3QS9HY52JzBm2ZQxTEBCTqQveYFSYIkTlOQjoVSIIfitf5GxPK1PgsueRK9JJc5p9RYCxij_GDJ9UhOWFJGRvnt3zxIKgChYCGI-vI0GAfmwUSj8pqAsck3rKv_PvjtOc6epCRiJLhu6_7hRFx4AXDDb5iD8U29cIs-1f9pD_WG5wOGcjnXTvQ-Hr_tKkPkIJVbiGbGAFPOfcuSHfEXZhJUH_7Vu_DzjKdzjSCm7abEQ-SEpt0VUtEmHQ096mHuErEfwbdeGC6w7yOKY1tdO0FAJd--rHpbeYbiA3Ib7JEnaxT1QjeAtNn21-10KQ-pm9xqOpj6UhC2QR9qSOw1sHmPpCeQ6Q_EUm7oZk970-mfytDRJF" }, "data": "{\"fieldId\":\"fields-content_blocks\",\"blocks\":[{\"id\":3764,\"uid\":\"b2f2567d-d9f4-414f-9b0b-4b0ff83d060e\",\"fieldId\":127,\"entryTypeId\":68,\"ownerId\":3763,\"ownerElementType\":\"craft\\\\elements\\\\Entry\",\"siteId\":3,\"namespace\":\"fields\"}]}", "method": "post", "url": "https://SITE-URL.com/index.php?p=admin%2Factions%2Fsmith%2Ffield%2Frender-matrix-blocks&site=ADDITIONAL-NON-PRIMARY-SITE", "params": { "v": 1719216246654 } }, "code": "ERR_BAD_REQUEST", "status": 400 }

Steps to reproduce

  1. Craft CMS with multi-site setup.
  2. Edit entry in the additional non primary site.
  3. Copy / Paste or Clone matrix block

Craft CMS version

5.2.3

Plugin version

3.0.0

Multi-site?

Yes

Additional context

No response

engram-design commented 2 months ago

That should be what https://github.com/verbb/smith/commit/a992c28d198fe52c023f13f4abf6a747c3d9dfa4 fixes, and non-default site copy/paste or clone is working for me it seems...

What's the Matrix field propagation settings?

belkin commented 2 months ago

Propagation method is set to: Only save entries to the site they were created in.

image

Copy/Paste works fine if I copy from default site and then paste in non-default one. But copy/paste or cloine in non-default one doesn't work.

I'm getting the same errors on different multi-site setup with same Craft and Smith versions.

engram-design commented 2 months ago

Yep that’s what I was testing with too. I’ve also tested between default and non-default sites and a combination of them. I’ll keep investigating reproducing this one…

belkin commented 2 months ago

@engram-design It seems that the siteId is missing from the Entry query: https://github.com/verbb/smith/commit/a992c28d198fe52c023f13f4abf6a747c3d9dfa4

We don't know if it's required but in the past we had problems without it.

So we changed it to $currentEntry = Entry::find()->siteId('*')->uid($uid)->status(null)->one(); and now it seems to be working fine across non-default sites.

cc @ThomasDeMarez

engram-design commented 2 months ago

That's what I figured as well, but can't for the life of my figure out why it's not working for me. Anyway, fixed for the next release. To get this early, run composer require verbb/smith:"dev-craft-5 as 3.0.0".

belkin commented 2 months ago

Thanks, i've updated it and it works now!