hyper icon indicating copy to clipboard operation
hyper copied to clipboard

Set the empty value to matrix linkValue filed programmatically, the changes doesn't apply

Open mikolamin opened this issue 8 months ago • 8 comments

Describe the bug

I encountered with issue after this changes.

When I set the empty value to matrix linkValue filed programmatically, the changes doesn't apply

Steps to reproduce

$element->setFieldValues([
        'bulletpoints' => [
            'new1' => 
                'type' => 'bulletpointsBlock',
                'fields' => [
                    'urlLinkBulletpoint' => [
                        'links' => [
                            'type' => 'verbb\\hyper\\links\\Url',
                            'handle' => 'default-verbb-hyper-links-url',
                            'newWindow' => false,
                            'linkValue' => '',
                            'linkText' => 'Link lable',
                        ],
                    ],
                ],
            ]; 
        ],
    ]);

Craft::$app->elements->saveElement($element);

Craft CMS version

5.6.11

Plugin version

2.2.4

Multi-site?

No response

Additional context

No response

mikolamin avatar Mar 23 '25 03:03 mikolamin

No issue on my end with Craft 5.6.13 I'm afraid.

Side note, that should be a plain array of links, not links as an array.

$element->setFieldValues([
    'bulletpoints' => [
        'new1' => [
            'type' => 'bulletpointsBlock',
            'fields' => [
                'urlLinkBulletpoint' => [
                    [
                        'type' => 'verbb\\hyper\\links\\Url',
                        'handle' => 'default-verbb-hyper-links-url',
                        'newWindow' => false,
                        'linkValue' => '',
                        'linkText' => 'Link lable',
                    ],
                ],
            ],
        ],
    ],
]);

Although no issue with using links on my end though.

engram-design avatar Mar 23 '25 10:03 engram-design

@engram-design do you mean links array should be like this?

$element->setFieldValues([
    'bulletpoints' => [
            'type' => 'bulletpointsBlock',
            'fields' => [
                'urlLinkBulletpoint' => [
                    [
                        'type' => 'verbb\\hyper\\links\\Url',
                        'handle' => 'default-verbb-hyper-links-url',
                        'newWindow' => false,
                        'linkValue' => '',
                        'linkText' => 'Link lable',
                    ],
                ],
        ],
    ],
]);

With this changes the same problem

mikolamin avatar Mar 23 '25 15:03 mikolamin

Can you confirm what you see? just no Matrix block at all? Or, what does the Hyper field look like?

engram-design avatar Mar 23 '25 19:03 engram-design

The block appears but the inputs "Link" and "Link Text" are empty.

This problem appeared after the fix: https://github.com/craftcms/cms/pull/16818/files

mikolamin avatar Mar 23 '25 19:03 mikolamin

Is this in the context of a multi-site? As in, the primary entry working correctly, but the specific sites don't? Judging from that commit, it seems to be for when an entry is "new for a site". But again, strangely both scenarios are working for me...

engram-design avatar Mar 23 '25 19:03 engram-design

Yes, for a multi-site. For all site doesn't work, just create the empty one link.

Image

If the value set up not empty like 'linkValue' => 'https://test.com' it works properly and

mikolamin avatar Mar 23 '25 19:03 mikolamin

Sorry if I'm not following, that seems correct behaviour to me? That's an empty Hyper field with no link value?

In addition, what are the translation/propagation settings for your Matrix and Hyper fields?

engram-design avatar Mar 23 '25 20:03 engram-design

That's an empty Hyper field with no link value? If I set only the Link Text field and Link field leaves empty then there is created block with all fields empty, it is expected that Link Text field fills out due to it possible to do in the Control Panel

Translation Method Hyper fields "Not translatable" Propagation Method Matrix fields "Save entries to all sites the owner element is saved in"

mikolamin avatar Mar 24 '25 12:03 mikolamin