verbb / smith

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

[Craft 3.5.17.1] [Smith 1.1.10] Cloning and copy/pasting fails #14

Closed andypullen closed 3 years ago

andypullen commented 3 years ago

Note: this seems to be very similar to #13 but with a slightly different error.

Steps to reproduce

  1. Optionally select any number of Matrix blocks with the checkmark on the top left
  2. Choose either clone or copy then paste from the cog drop down of one of the matrix blocks
  3. Loading spinner momentarily appears then quickly disappears - no visible errors, and no new blocks shown or saved

Additional info

Additional context

The POST request to ?p=admin/actions/smith/field/render-matrix-blocks is:

field: contentBlocks
namespace
blocks[0][type]: cardLink
blocks[0][enabled]: 1
blocks[0][fields][cardTitle]: Beyond Colorblind
blocks[0][fields][tag]: Resources for Rethinking Race
blocks[0][fields][tagIcon]
blocks[0][fields][backgroundImage][]: 603922
blocks[0][fields][backgroundColor]
blocks[0][fields][cardLink]: /beyond-colorblind
blocks[0][fields][width]: medium
blocks[0][fields][newWindow]
blocks[0][fields][darkText]
blocks[0][blockId]: 667474

and the response is:

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

The error log entry is:

2021-01-11 09:00:56 [-][1][-][error][smith] Unable to find block for 667474.
2021-01-11 09:00:56 [-][1][-][error][smith] {"type":"cardLink","enabled":"1","fields":{"cardTitle":"Beyond Colorblind","tag":"Resources for Rethinking Race","tagIcon":"","backgroundImage":["603922"],"backgroundColor":"","cardLink":"/beyond-colorblind","width":"medium","newWindow":"","darkText":""},"blockId":"667474"}
2021-01-11 09:00:56 [-][1][-][info][application] $_GET = [
    'p' => 'admin/actions/smith/field/render-matrix-blocks'
]

$_POST = [
    'field' => 'contentBlocks'
    'namespace' => ''
    'blocks' => [
        0 => [
            'type' => 'cardLink'
            'enabled' => '1'
            'fields' => [
                'cardTitle' => 'Beyond Colorblind'
                'tag' => 'Resources for Rethinking Race'
                'tagIcon' => ''
                'backgroundImage' => [
                    0 => '603922'
                ]
                'backgroundColor' => ''
                'cardLink' => '/beyond-colorblind'
                'width' => 'medium'
                'newWindow' => ''
                'darkText' => ''
            ]
            'blockId' => '667474'
        ]
    ]
    'placeholderKey' => '••••••••••'
]
engram-design commented 3 years ago

Looks like this was due to cloning or copy/pasting unsaved blocks. There's some serious complications with dealing with Neo/Super Table/Matrix combinations, so we rely on a saved block to resolve these correctly.

However, I've fixed this for solo Matrix fields in 1.1.11