kirby icon indicating copy to clipboard operation
kirby copied to clipboard

Add failsafe for permalinksToUrls method if uuid does not exist

Open SebastianEberlein-JUNO opened this issue 1 year ago • 2 comments

Description

Example: A text block has an inline link to a page. If the linked page is deleted and the uuid does not exist anymore, the following error is displayed:

Block error: "DOMElement::setAttribute(): Passing null to parameter #2 ($value) of type string is deprecated" in block type: "text"

Because in the permalinksToUrls method, the $url in this line is null: https://github.com/getkirby/kirby/blob/main/config/methods.php#L488

Your setup

Kirby Version
4.0.3

SebastianEberlein-JUNO avatar Jan 17 '24 13:01 SebastianEberlein-JUNO

I just noticed the same issue outside of blocks. In this case the whole website went down because a page was deleted. I'd personally classify this as a bug instead of an enhancement.

To reproduce

  1. Add a writer field to your blueprint and use permalinksToUrls() in the frontend
  2. Link a page
  3. Delete the page

Edit: I just saw the "This method is still experimental" disclaimer in the code, so I can understand where the "enhancement" is coming from. It would be great if this disclaimer could be added to the method docs.

medienbaecker avatar Jan 23 '24 18:01 medienbaecker

I recently discussed this issue with @mrflix and he rightfully suggested it might help to talk about the expected behaviour:

The (link: ) tag deals with this in a very elegant way in my opinion. When debug mode is on, an exception is thrown, otherwise the error page's URL is used. I'd expect the permalinksToUrls() method to work in a similar way.

In the meantime, as mentioned in my previous comment, I think the Kirby community would really appreciate a disclaimer in the docs. Not everyone looks at the source code and the method is there for a reason.

medienbaecker avatar Feb 14 '24 16:02 medienbaecker

I'ld categorize this as a bug as well as it crashes page rendering in unexpected situations.

Is there any update on this?

bvdputte avatar Feb 27 '24 08:02 bvdputte

Sorry that it took so long. This is definitely a bug. I just submitted a PR for it https://github.com/getkirby/kirby/pull/6313

bastianallgeier avatar Feb 29 '24 16:02 bastianallgeier