-
-
Notifications
You must be signed in to change notification settings - Fork 15
Description
Describe the bug
An issue was raised in the cms repo which affects the Hyper plugin. The issue is that custom attributes (e.g., classes, link text, link title, etc.) are lost in some cases. I dug into it, and it looks like those values are lost when the Hyper field is considered empty.
This is the cms code that prevents empty values from being stored for elements that are new for the site: https://github.com/craftcms/cms/blob/5.8.22/src/services/Elements.php#L3984-L3988.
And this is why the link to entry with no entry selected is considered an emtpy field: Link::isEmpty() > ElementLink::count() > ElementLink::getElement().
Proposed changes:
It might be worth considering a similar approach as the native Link field uses - don’t store any additional values (link text, classes, etc) unless the link has a value in the first place - that way, there’s no confusion around those values not persisting in some cases.
It might also be a good idea to treat a link to an element as not empty when the selected element is disabled.
Steps to reproduce
- clean 5.8.22 installation with the Hyper plugin installed (I used version 2.2.11)
- create a Hyper field, with all the default settings and a “Default Link Type” set to “Entry”
- create a section with an entry type containing that Hyper field
- create an entry in that section, fill out the title and for the Hyper field, add a Link Text and nothing else; fully save that entry
- edit the entry from the previous step; the link text is still present; now edit the title of the entry; wait for the autosave to complete - a provisional draft has now been created
- if you reload the page or fully save that entry, the Link Text is gone
Craft CMS version
5.8.22
Plugin version
2.2.11
Multi-site?
no
Additional context
No response