Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[Craft 3.5] Cloning or copy / pasting a set of Matrix blocks fails silently #13

Closed
rob-c-baker opened this issue Oct 5, 2020 · 12 comments

Comments

@rob-c-baker
Copy link

rob-c-baker commented Oct 5, 2020

Steps to reproduce

  1. Select any number of Matrix blocks with the checkmark top left (whether same type or different)
  2. choose either clone or copy then paste from the cog drop down of another Matrix block
  3. Loading GIF momentarily appears then disappears - no errors, no new blocks shown

Additional info

  • Plugin version: 1.1.8
  • Craft version: 3.5.11.1
  • Multi-site: No

Additional context

The POST request to https://hostname/index.php?p=[...]/actions/smith/field/render-matrix-blocks looks like this:

field: tiles
namespace: 
blocks[0][type]: contentBlock
blocks[0][enabled]: 1
blocks[0][fields][tileLabel]: sdfgsdgsdfg
blocks[0][fields][tileImage][]: 901168
blocks[0][fields][tileImageAspectRatio]: 4:3
blocks[0][fields][tileURL]: /sdfgsdfg/sdfgsdfg
blocks[0][fields][tileEntry]: 
blocks[0][fields][active]: 1
blocks[0][fields][additionalClasses]: 
placeholderKey: xmmvfszzng

And the response like this:

{"success":true,"blocks":[]}

Cannot see any logged errors.

@engram-design
Copy link
Member

Are you able to send through a screenshot of your blocks, or field setup? I can't seem to replicate this behaviour. See https://d.pr/v/cVQgFx

@rob-c-baker
Copy link
Author

rob-c-baker commented Oct 13, 2020

https://imgur.com/a/4RLIwA9

In that album, the first 3 screens show what happens.

The last 2 show the field config for the Matrix block in question. Fields are 3 * Drop downs and a 1 * lightswitch.

I should add that if I try to clone or duplicate a Matrix block (from another field) containing only a Redactor field it duplicates fine.

[Edit: It looks like imgur messed with the order of the images, - the above still applies but not necessarily in that order!]

@engram-design
Copy link
Member

Thanks for the image, I still can't replicate it which is frustrating.

I've just added some more logging in 1.1.9 if you feel like giving that a spin. There must be something unique with that field or blocktypes...

@rob-c-baker
Copy link
Author

Hi @engram-design , I updated to 1.1.9 and ran through the above again.

Got the following in ./storage/logs/smith.log...

2020-10-20 08:51:45 [-][1][-][error][smith] Unable to find Block Type for “tileStart” for field “219”.
2020-10-20 08:51:45 [-][1][-][error][smith] {"tile":{"id":"33","fieldId":"219","fieldLayoutId":"54","name":"Tile","handle":"tile","sortOrder":"1","hasFieldErrors":false,"uid":"f03ee682-4d5b-4409-945c-39a346ecaf14"}}

The POST data was:

$_POST = [
    'field' => 'tiles'
    'namespace' => ''
    'blocks' => [
        0 => [
            'type' => 'tileStart'
            'enabled' => '1'
            'fields' => [
                'context' => 'is-parent'
                'direction' => 'is-vertical'
                'columnWidth' => ''
                'active' => '1'
            ]
        ]
    ]
    'placeholderKey' => '••••••••••'
]

Around line 49 in FieldController $blockTypes has a key of 'tile' (which is the Matrix block type handle) but it seems $blockData['type'] is 'tileStart' (which is the handle for the field within the Matrix). $blockType = $blockTypes[$blockData['type']] ?? null; resolves to null and the error is logged.

@engram-design
Copy link
Member

Great, so that's a good start.

So as the error states, it can't find the blocktype you're trying to copy in field ID 219. Can you confirm a blocktype with the handle of title exists in this field? Just trying to figure out which is the correct handle - tileStart or tile.

@rob-c-baker
Copy link
Author

OK, after some digging:

There are 2 different Matrix fields with the handle tiles with different contexts and different block types.

One is this one, exhibiting the issue (with block types: tileStart, contentBlock and tileEnd and a fieldId of 238).

The other exists in another field group used on a different section (has a single block type tile and a fieldId of 219).

Smith seems to be getting the wrong Matrix block type data. In the same controller as above, line 41 it gets the first field with a matching handle then later gets the block types out of it. In my case, I have 2 Matrix fields with the same handle.

I'm not even sure that's a valid situation to be in, in which case there may be a Craft bug at the route of this that allowed 2 Matrix fields with the same handle to be created (although they are only used in different contexts so perhaps it is ok).

@engram-design
Copy link
Member

You mention I have 2 Matrix fields with the same handle that shouldn't be possible right? If they have different contexts, they must be being used in Super Table or Neo fields?

I can investigate further knowing that much though

@rob-c-baker
Copy link
Author

I didn't think it was possible. You are right - field id 219 is set as a child of a Super Table field, the field being found by the code $field = ArrayHelper::firstWhere(Craft::$app->fields->getAllFields(false), 'handle', $fieldHandle, true); on line 41 of the controller... But field id 238 is the correct field.

Field 219 has a context column of superTableBlockType:eea54c8e-1952-45a6-acbc-8f5b64dee01d.

Field 238 (the matrix that sparked this issue) has a context of global.

This is according to the fields databases table.

@engram-design
Copy link
Member

Think I've figured this out, if you're able to try by changing your verbb/smith requirement in composer.json to:

"require": {
  "verbb/smith": "dev-craft-3 as 1.1.9",
  "...": "..."
}

Then run composer update.

@rob-c-baker
Copy link
Author

Done - works great now - many thanks.

@engram-design
Copy link
Member

Great, thanks for your persistence on this. Fixed in 1.1.10

@rob-c-baker
Copy link
Author

No problem - it's going to help a few of our content editors on a couple of sites, so thank you for your work on the plugin.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants