v2-hub
v2-hub copied to clipboard
Live preview button is displayed even if no URL was set for content
Describe the bug
When having a content (collection or taxonomy) without a route set, the url of all items (entry or term) is /
.
Therefore the 'Live preview' button appears when editing the entry but leads to the homepage (which is not related to the entry).
To Reproduce Steps to reproduce the behavior:
- Create a collection without associated route
- Create a new entry of the previously created collection
- Once published the 'Live preview' button is showed when editing the entry
- Click on it and see the homepage (which is not related to the entry)
Expected behavior The 'Live preview' button should not be displayed when no route is associated to a collection/taxonomy
Environment details (please complete the following information):
- Statamic Version: 2.10.3
- Fresh Install
- OS: Windows 10 version 1803
- Web Server: Apache
- PHP Version: 7.2.2
- Addons installed: none
Additional context
Possible fix : the default value of a entry/term's url should be null
instead of /
.
Statamic\Data\Content
public function url()
{
$url = URL::makeRelative($this->absoluteUrl());
return $url == '/' ? null : $url;
}
I checked quickly and it solve the problem but it may cause some effects on other content type like pages.
If a collection has no route set, the live preview does not work. The following error is thrown:
Call to a member function in() on null
This is expected, but could fail more gracefully since collections can also be used in listings and not have a detail page (route) of their own.