verbb / field-manager

Field Manager is a Craft CMS plugin to make it easy to manage your fields and field groups.
MIT License
199 stars 16 forks source link

Craft 5 || Can't clone Matrix fields #102

Closed DynamiteGoesBoom closed 2 months ago

DynamiteGoesBoom commented 3 months ago

Describe the bug

I'm attempting to clone a Matrix field and get the following error:

2024-06-09 11:05:48 [web.ERROR] [yii\base\UnknownPropertyException] yii\base\UnknownPropertyException: Getting unknown property: craft\fields\Matrix::blockTypes in /var/www/html/cms/vendor/yiisoft/yii2/base/Component.php:154

Steps to reproduce

  1. Create field with several block types
  2. Go to Field Manager and attempt to clone

Craft CMS version

5.1.8

Plugin version

4.0

Multi-site?

No response

Additional context

Here's the full stack trace:

Stack trace:
#0 /var/www/html/cms/vendor/verbb/field-manager/src/services/Service.php(124): yii\base\Component->__get('blockTypes')
#1 /var/www/html/cms/vendor/verbb/field-manager/src/services/Service.php(44): verbb\fieldmanager\services\Service->processCloneMatrix(Object(craft\fields\Matrix))
#2 /var/www/html/cms/vendor/verbb/field-manager/src/controllers/BaseController.php(155): verbb\fieldmanager\services\Service->cloneField(Object(craft\fields\Matrix), Object(craft\fields\Matrix))
#3 [internal function]: verbb\fieldmanager\controllers\BaseController->actionCloneField()
#4 /var/www/html/cms/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#5 /var/www/html/cms/vendor/yiisoft/yii2/base/Controller.php(178): yii\base\InlineAction->runWithParams(Array)
#6 /var/www/html/cms/vendor/yiisoft/yii2/base/Module.php(552): yii\base\Controller->runAction('clone-field', Array)
#7 /var/www/html/cms/vendor/craftcms/cms/src/web/Application.php(349): yii\base\Module->runAction('field-manager/b...', Array)
#8 /var/www/html/cms/vendor/craftcms/cms/src/web/Application.php(650): craft\web\Application->runAction('field-manager/b...', Array)
#9 /var/www/html/cms/vendor/craftcms/cms/src/web/Application.php(311): craft\web\Application->_processActionRequest(Object(craft\web\Request))
#10 /var/www/html/cms/vendor/yiisoft/yii2/base/Application.php(384): craft\web\Application->handleRequest(Object(craft\web\Request))
#11 /var/www/html/cms/web/index.php(12): yii\base\Application->run()
#12 {main} {"memory":5442960,"exception":"[object] (yii\\base\\UnknownPropertyException(code: 0): Getting unknown property: craft\\fields\\Matrix::blockTypes at /var/www/html/cms/vendor/yiisoft/yii2/base/Component.php:154)"} 
engram-design commented 3 months ago

I think I can recall why I left this until the end (but actually forgot about it during beta, whoops!).

I was unsure of the desired behaviour. With Matrix now using Entry Types, and existing fields, there's some change in behaviour. Previously all fields belonged to the Block Type, which in turn was specific to a Matrix field.

For cloning, we need to ask whether a new Entry Type should be created, and if the fields associated with those should also be cloned. This gets a little tricky with field instances as well.

DynamiteGoesBoom commented 3 months ago

I totally get that it's a little more complex with the new Entry Type and field setup. I'm just looking to clone over my main Content Builder as I have a slew of Colour Swatch fields that I want to copy over to a Global that will allow me to set each Content Builder block types' default styling within any given block.

But the more I think of it I'm still going to need to replicate the global blocks to not hold any content, but just show the Style data. Cloning might save me a ton of time but I understand the tricky nature of this request.

Thanks as always!

engram-design commented 2 months ago

In your instance, what would you expect? Just the Matrix field itself to be cloned and the Entry Types it uses referring to the current ones? Or you'd also like new Entry Types created as well?

I myself am still coming to terms with the different paradigm shift of using Entry Types, so I'm not sure either 😅

DynamiteGoesBoom commented 2 months ago

I wouldn't worry about this as I already cloned all of the entryTypes and prepended Global to them all, and assigned them to my Global Content Builder. I then attached those Entry Types and I think I'm good for now.

Thanks again!

engram-design commented 2 months ago

No worries, I'll give this some more thought and see if anyone else chimes in!

mightyfineyall commented 2 months ago

@engram-design Just ran into this also - I previously used Architect in Craft 4 and would import/export entry types and sections as needed as well. If Field Manager could duplicate that functionality it would be awesome. I have a "Sales Funnel" matrix (based on Don Miller's StoryBrand) that I use in most projects. Being able to clone over entry types (which would then utilize the individual fields, repeated as needed) would be really helpful. Architect did that, but with the way relations have changed in Craft 5 I'm sure it's tricky.

That said, it's very counterintuitive to download a plugin called Field Manager, attempt to import a matrix field, and immediately get an error. Might be just time to sunset?

engram-design commented 2 months ago

It wasn't my intention to leave this as they were, more keen to hear what feedback there is on the expected behaviour now things are different in Craft 5.

In 4.0.1 there's no longer an error, and there's a change in behaviour. Matrix fields and their entry types are now cloned, but the fields used in the entry types are not cloned, and still reference their original fields.

This decision is more inline with Craft's push towards re-using fields, rather than the old way of every field in a Matrix being solely for that Matrix field.