Page 1 of 1

cms_selflink for nonexistent alias points to root url

Posted: Mon Mar 25, 2019 2:08 pm
by Charles Butcher
When used with an alias that no longer exists, {cms_selflink} points to the root URL instead of my 404 page, as I'd expect.

Is this a problem with my setup, or does it always work like this? And if the latter, is there a workaround?

Re: cms_selflink for nonexistent alias points to root url

Posted: Wed Mar 27, 2019 10:49 pm
by velden
The plugin will not output an url for a non-existing page alias. This results in <a href="">...</a> which leads to the homepage (usually). You can check this by looking at the page source.

This is indeed default behavior of the plugin as it is now. The CMSMS dev team recognizes it may be better to output something different and we may implement it in a future version of CMS Made Simple (but not in a minor update).

Assuming you're using the functionality of Microtiny/TinyMCE to add internal links with the wysiwyg editor:

There is not an easy workaround, though, if you know how to read and write a few lines of php code and are using CMSMS 2.x, you can override the default behavior of the plugin.
Move the cms_selflink plugin file to the /assets/plugins folder and make your changes there.

A few important notes:
- we will not support such changes and don't allow 'hacks' to be posted in this forum
- don't forget about this overriding; future upgrades will NOT touch 'your' plugin, so changes in the core plugin will not be working in your site, which will lead to unexpected behavior and/or a broken frontend/backend.
- future upgrades may re-install the plugin on the original location which can lead to a conflict (again risk of breaking frontend/backend)
- clear cache after making changes to your plugin

If you're using the plugin in templates it would be easy to check for the output first and if it's empty generate an url yourself.

Code: Select all

{cms_selflink href='non-existing-alias' assign=foo}
<a href="{$foo|default:"{root_url}/pagenotfound"}">link text</a>

Re: cms_selflink for nonexistent alias points to root url

Posted: Thu Mar 28, 2019 3:39 pm
by Charles Butcher
@velden, many thanks for such a helpful reply. My PHP and Smarty skills aren't up to the fix you hinted at, though I did have a go.

And the workaround on the page itself isn't really useful unless I rewrite the existing plugin for TinyMCE, since I have users who rely on the toolbar button.

This isn't a big issue, but I am pleased to hear that at some point you might consider changing it to point to the "not found" page. To me that's the expected behaviour.

I'd also welcome a way to reference pages that would allow their aliases as well as their paths to be changed without breaking links. It's nice to be able to move a page without having to worry about updating the path, but in practice I quite often want to change the alias as well, for the sake of pretty URLs. I expect that would be a lot more complex to implement.