verbb / vizy

A flexible visual editor for Craft CMS
Other
43 stars 8 forks source link

In 1.0.10, Nested Vizy Fields are stored as strings instead of an array #110

Closed mattbloomfield closed 2 years ago

mattbloomfield commented 2 years ago

Description

I noticed this after upgrading to 1.0.10 and it goes away if I jump back to 1.0.9.

Basically we have times where we have a vizy field nested in a vizy. In those cases, when you save those entries they are stored as strings instead of arrays.

E.g. (look at the simpleVizy field)

1.0.9:

[
    'id' => 'vizy-block-cdPkFfIMic'
    'enabled' => true
    'collapsed' => false
    'values' => [
        'type' => 'type-rMyFDTJh3K'
        'content' => [
            'fields' => [
                'simpleVizy' => [
                    0 => [
                        'type' => 'paragraph'
                        'attrs' => [
                            'textAlign' => 'start'
                        ]
                        'content' => [
                            0 => [
                                'type' => 'text'
                                'text' => 'The Small Business Policy team manages the Small Business Council, the U.S. Chamber’s principal policy committee and action group representing the issues of concern to small business. In addition to formulating small business policy, the council assists in creating strategies on legislative, regulatory and international initiatives. The group is able to bring to the Chamber’s Board of Directors attention issues they regard as important or comment on the small business impact of policy being formulated by other Chamber standing policy committees.'
                            ]
                        ]
                    ]
                ]
                'shortTitle' => 'Explore more'
                'featureEnabled_DefaultOn' => false
                'linkMatrix' => [
                    'new1' => [
                        'type' => 'linkMatrix'
                        'enabled' => true
                        'collapsed' => false
                        'fields' => [
                            'linkUrl' => [
                                'ariaLabel' => null
                                'customQuery' => null
                                'customText' => null
                                'target' => '_blank'
                                'title' => null
                                'type' => 'url'
                                'value' => '/co/'
                            ]
                            'linkLabel' => 'Grow with CO –'
                        ]
                    ]
                    'new2' => [
                        'type' => 'linkMatrix'
                        'enabled' => true
                        'collapsed' => false
                        'fields' => [
                            'linkUrl' => [
                                'ariaLabel' => null
                                'customQuery' => null
                                'customText' => null
                                'target' => ''
                                'title' => null
                                'type' => 'entry'
                                'value' => '116492'
                            ]
                            'linkLabel' => 'Small Business Council Baby'
                        ]
                    ]
                    'new3' => [
                        'type' => 'linkMatrix'
                        'enabled' => true
                        'collapsed' => false
                        'fields' => [
                            'linkUrl' => [
                                'ariaLabel' => null
                                'customQuery' => null
                                'customText' => null
                                'target' => ''
                                'title' => null
                                'type' => 'url'
                                'value' => '/save-small-business'
                            ]
                            'linkLabel' => 'Save Small Business'
                        ]
                    ]
                    'new4' => [
                        'type' => 'linkMatrix'
                        'enabled' => true
                        'collapsed' => false
                        'fields' => [
                            'linkUrl' => [
                                'ariaLabel' => null
                                'customQuery' => null
                                'customText' => null
                                'target' => ''
                                'title' => null
                                'type' => 'entry'
                                'value' => '14796'
                            ]
                            'linkLabel' => 'Dream Big Awards'
                        ]
                    ]
                ]
            ]
        ]
        'typeEnabled' => true
    ]
]

1.0.10:

[
    'id' => 'vizy-block-cdPkFfIMic'
    'enabled' => true
    'collapsed' => false
    'values' => [
        'type' => 'type-rMyFDTJh3K'
        'content' => [
            'fields' => [
                'simpleVizy' => '[{\"type\":\"paragraph\",\"attrs\":{\"textAlign\":\"start\"},\"content\":[{\"type\":\"text\",\"text\":\"The Small Business Policy team manages the Small Business Council, the U.S. Chamber’s principal policy committee and action group representing the issues of concern to small business. In addition to formulating small business policy, the council assists in creating strategies on legislative, regulatory and international initiatives. The group is able to bring to the Chamber’s Board of Directors attention issues they regard as important or comment on the small business impact of policy being formulated by other Chamber standing policy committees.\"}]}]'
                'shortTitle' => 'Explore more'
                'featureEnabled_DefaultOn' => ''
                'linkMatrix' => [
                    'sortOrder' => [
                        0 => 'new1'
                        1 => 'new2'
                        2 => 'new3'
                        3 => 'new4'
                    ]
                    'blocks' => [
                        'new1' => [
                            'type' => 'linkMatrix'
                            'enabled' => '1'
                            'fields' => [
                                'linkUrl' => [
                                    'type' => 'url'
                                    'url' => '/co/'
                                    'category' => [
                                        'value' => ''
                                    ]
                                    'entry' => [
                                        'value' => ''
                                    ]
                                    'target' => '_blank'
                                    'isCpFormData' => 'true'
                                ]
                                'linkLabel' => 'Grow with CO –'
                            ]
                        ]
                        'new2' => [
                            'type' => 'linkMatrix'
                            'enabled' => '1'
                            'fields' => [
                                'linkUrl' => [
                                    'type' => 'entry'
                                    'url' => ''
                                    'category' => [
                                        'value' => ''
                                    ]
                                    'entry' => [
                                        'value' => [...]
                                    ]
                                    'target' => ''
                                    'isCpFormData' => 'true'
                                ]
                                'linkLabel' => 'Small Business Council Baby'
                            ]
                        ]
                        'new3' => [
                            'type' => 'linkMatrix'
                            'enabled' => '1'
                            'fields' => [
                                'linkUrl' => [
                                    'type' => 'url'
                                    'url' => '/save-small-business'
                                    'category' => [
                                        'value' => ''
                                    ]
                                    'entry' => [
                                        'value' => ''
                                    ]
                                    'target' => ''
                                    'isCpFormData' => 'true'
                                ]
                                'linkLabel' => 'Save Small Business'
                            ]
                        ]
                        'new4' => [
                            'type' => 'linkMatrix'
                            'enabled' => '1'
                            'fields' => [
                                'linkUrl' => [
                                    'type' => 'entry'
                                    'url' => ''
                                    'category' => [
                                        'value' => ''
                                    ]
                                    'entry' => [
                                        'value' => [...]
                                    ]
                                    'target' => ''
                                    'isCpFormData' => 'true'
                                ]
                                'linkLabel' => 'Dream Big Awards'
                            ]
                        ]
                    ]
                ]
            ]
        ]
        'typeEnabled' => true
    ]
]

Steps to reproduce

  1. Create two vizy fields, Field 1 & Field 2
  2. Add a block to a vizy Field 1.
  3. Add Vizy Field 2 to that block
  4. Add Vizy Field 1 to the schema for a category group (might happen everywhere, I was on a category)
  5. Create a new category in the group, add the block to the vizy field
  6. Craft:dd the output of Vizy Field 1 and see that it's saved the Vizy Field 2 contents as a string.

Additional info

Additional context

engram-design commented 2 years ago

It shouldn't matter too much if they're strings or arrays, other than how the content is stored. When normalised (read from the database), they're sorted into nested Node Collections, which can be queried freely.

Fixed for the next release. To get the fix early, change your verbb/vizy requirement in composer.json to:

"require": {
  "verbb/vizy": "dev-craft-3 as 1.0.10",
  "...": "..."
}

Then run composer update.

mattbloomfield commented 2 years ago

I agree it shouldn't matter, but this was not normalizing them the way it did previously. Thanks for the fix!

engram-design commented 2 years ago

Fixed in 1.0.11