verbb / smith

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

Clone function not compatible with MatrixMate tabs #18

Closed Joorren closed 3 years ago

Joorren commented 3 years ago

Description When you clone an existing matrix block, the matrix block gets cloned, but the fields inside the newly created matrix block won't get divided into their associated tabs (MatrixMate feature). This makes the matrix block messy and cluttered, and that's why we installed the MatrixMate plugin.

https://user-images.githubusercontent.com/22602428/119998552-179a7280-bfd1-11eb-9648-97205acdc3e7.mov

According to the MatrixMate developer, the problem most likely happens because Smith doesn't emit the same events as the native create function.

I think this is something that should be fixed in Smith, not in MatrixMate.

Most likely, the Smith plugin just needs to make sure that when it clones a block, the Matrix field's Craft.MatrixInput instance emits the same JavaScript event(s) that are emitted when blocks are added natively – specifically, the blockAdded event, which MatrixMate listens to in order to instantiate new blocks.

Steps to reproduce

  1. Create a matrix block and save it
  2. Duplicate the matrix block with Smith

Additional info

Additional context The bug report on the MatrixMate repository: https://github.com/vaersaagod/matrixmate/issues/32

engram-design commented 3 years ago

Hmmm, so Smith actually calls matrixField.addBlock()

https://github.com/craftcms/cms/blob/d754d673f2ee8dd2b914f3d1cb4db462fd0da0e3/src/web/assets/matrix/src/MatrixInput.js#L200

Which itself contains the call to the blockAdded event.

https://github.com/craftcms/cms/blob/d754d673f2ee8dd2b914f3d1cb4db462fd0da0e3/src/web/assets/matrix/src/MatrixInput.js#L276-L278

But looks like this was actually due to an underlying issue with rendering blocks, that hadn't been updated properly with Craft 3.5+ field layout changes.

Should be fixed in 1.1.14