Ticket #11355 (assigned Bug)

Opened 5 years ago

Last modified 3 years ago

Static text portlet that is set to show only on a default view of a folder produces internal links that are broken.

Reported by: winn Owned by: cguardia
Priority: minor Milestone: 4.x
Component: User Experience and Interface Version: 4.2
Keywords: TuneUp Cc: keul

Description (last modified by WouterVH) (diff)

To duplicate:

  • Create a folder called Folder One on a fresh plone 4 site.
  • Create a page inside that folder.
  • Now go to Manage Viewlets and add a static text portlet that will only display for that page.
  • Create a subfolder called Folder Two under Folder One.
  • Now add an internal link to the static text portlet body text that points to the Folder Two.
  • Finally, make the page the default view of the folder.

Creating the link will product HTML like href="../folder-two" so will point to  http://mysite.com/folder-two instead of  http://mysite.com/folder-one/folder-two.

If the default view is for the root of the site, like "front-page", the link will not be broken since the ../ has no effect when the context is the root of the site.

Actually the link is broken even if you don't make the page the default view for Folder One. But the most common use-case for needing a static text portlet that only shows on one page is where the page is a default view.

Change History

comment:1 Changed 5 years ago by davisagli

  • Keywords TuneUp added

This might already be fixed in Plone 4.1, as plone.outputfilters absolutizes relative links. Can someone check?

comment:2 Changed 5 years ago by WouterVH

  • Description modified (diff)

comment:3 Changed 5 years ago by WouterVH

This issue is still there on plone-coredev-4.1

comment:4 Changed 5 years ago by davisagli

Presumably the static portlet needs to be adjusted to apply the safe html transform with context set to the context of the portlet assignment, rather than the context on which the portlet is appearing.

comment:5 Changed 5 years ago by WouterVH

I think to context is set correct on the rendering of the static portlet.

However, there is something wrong when adding the static portlet

  • Create a folder called Folder2 on a fresh plone 4 site.
  • Now go to "Manage Viewlets" and add a static text portlet that will only display for that Folder2.

Add a link -> you will see that TinyMCE opens in the plone-root, also when clicking on the image-icon.

Adding a link to the news-page will store: <p><a class="internal-link" href="news">news</a></p>

which is wrong, it should be " http://localhost:8080/z3/news"

  • now re-edit the static portlet and add a second link to the same item -> TinyMCE will now show up inside Folder2 "No items in this folder" th html-stored is now: <p><a class="internal-link" href="../news">news2</a></p>

This is correct. This link is rendered as  http://localhost:8080/z3/news

I think this is related to TinyMCE:

comment:6 Changed 5 years ago by WouterVH

confirmed

the first time document_base_url in TinyMCE is  http://localhost:8080/z3 (the plone-root) the second time it's  http://localhost:8080/z3/folder2

so the wrong html get stored in the portlet.

comment:7 Changed 5 years ago by cguardia

  • Owner changed from limi to cguardia

comment:8 Changed 5 years ago by cguardia

  • Status changed from new to assigned

comment:9 Changed 5 years ago by cguardia

This has nothing to do with being the default view. There are actually three problems here: 1) when adding a portlet, the context for the relative links is different from when you edit it, so a link to an object on the same level (or even to the same object) will behave differently depending on if you are adding or editing. 2) When editing, the document_base_url passed to TinyMCE ends in a slash, so it thinks that the page is a container and adds the '../' to the link, which messes up the link when viewing. And 3) which is the worst thing, every time you edit relative links are changed, depending on the level of the linked object, even if the links are not touched at all.

Solving problem 2 is just a matter of truncating the document URL at the index of '/++contextportlets++' instead of '++contextportlets++'. Problem 1 is trickier, because the add portlet drop down uses the :action method for sending the '++contextportlets++...' part, so the URL doesn't have it. It can be fixed by checking the BASE tag and looking for '++contextportlets++', in a manner similar to the current check for that string in document_base_url.

Problem 3 however, seems to not have an easy fix. I have made the changes described above in my sandbox and it works fine when you create and first edit the portlet, but further edition of the portlet, even without touching the links, changes them. For example, '/folder1/folder2' becomes '/folder1/page1/folder2' and if you edit and save again with no changes, it becomes '/folder1/page1/page1/folder1'.

It might be necessary to change the code that converts links right before saving. Any ideas here?

comment:10 Changed 5 years ago by cguardia

One other option would be to avoid URL transforms when saving only portlets.

comment:11 Changed 4 years ago by tkimnguyen

You may want to have a look at this product, by David Hietpas, which examines the creation context of the portlet and regenerates the URLs correctly

 https://svn.it.uwosh.edu/svn/plone/Projects/uwosh.static.fix/

comment:12 Changed 3 years ago by keul

  • Cc keul added
  • Version set to 4.2

Just to warn that this bug is not only related to static text portlet, but also to richwidget inside contents. See #11814

Note: See TracTickets for help on using tickets.