craftcms / redactor

Edit rich text content in Craft CMS using Redactor by Imperavi.
https://plugins.craftcms.com/redactor
MIT License
100 stars 48 forks source link

Unable to Link To Elements With Missing refHandle() #375

Closed jsegars closed 2 years ago

jsegars commented 2 years ago

Description

We are creating URL-based links within Redactor fields that point to Solspace calendar events. Upon saving, the links to any calendar events are broken in the frontend, appearing like

<a href="{:59995@1:url||https://site/test/events/my-event}">Test</a>

Entries work fine, as do non-Craft external URLs.

After investigating, we see that Redactor 2.9 added a feature where all URLs are parsed on save and checked to see if they correspond to an existing element (see https://github.com/craftcms/redactor/commit/a6772463a332a5c8a535e31d4d27a9cbea09ed12)

This feature expects that elements implement the refHandle() method. Without it, content gets saved with an invalid reference tag. At rendering, this invalid reference tag prevents the fallback URL from being used. Solspace Calendar does not implement the refHandle() method inside its Event element.

I've opened an issue with Solspace about adding the missing refHandle method, but this seems like it may have been an unexpected breaking change. Should Redactor just be skipping the reference tag creation when there is no refHandle rather than generating an invalid one?

Additional info

andris-sevcenko commented 2 years ago

I've added the check for an existing ref handle to the html-field package (craftcms/html-field@fd3d400643fccbe27583102f581640f465987a06)

If you run composer update you should be able to pull that right it.