v2-hub icon indicating copy to clipboard operation
v2-hub copied to clipboard

Live preview button is displayed even if no URL was set for content

Open RomainFrancony opened this issue 6 years ago • 1 comments

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:

  1. Create a collection without associated route
  2. Create a new entry of the previously created collection
  3. Once published the 'Live preview' button is showed when editing the entry
  4. 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.

RomainFrancony avatar Aug 16 '18 19:08 RomainFrancony

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.

peschee avatar Feb 25 '20 07:02 peschee