PerplexDigital / Perplex.ContentBlocks

Block based content editor for Umbraco
MIT License
31 stars 15 forks source link

Creating a new page with a template using content blocks causes it to have the same GUID #77

Closed BrentEvenhuisIO closed 1 year ago

BrentEvenhuisIO commented 1 year ago

Creating a new page in Umbraco with a premade template that contains Perplex content blocks causes it to have the same key, when disabling cache this issue seems to be solved. The page consists of multiple content blocks but the issue only seems to be relevant on the hero content block, when removing this from the template it works as intended.

This issue is the same as in #64 royberris is a colleague of mine and pointed out it was best to create a ticket since you had some communication before. If any more information is needed, I try my best to supply it.

PerplexDaniel commented 1 year ago

I assume this happens when you create a Content Template of some page that already contains some content blocks and you then create new pages based on those templates, correct? So this:

template

I have not looked into the Umbraco source of this feature but likely they just copy/paste the literal property data from the source page so I can imagine the unique content block ids and keys within the nested content are all the same, which is not good as they should be unique.

As mentioned in #64 there is code in place that handles this when you Copy entire nodes, but there is no code (yet) to handle creating new pages based on Content Templates. They should be handled in the same way basically.

So the main question is whether Umbraco emits some event / notification (for copying this is ContentCopyingNotification in v9+) that we can hook into to detect a new page is being created based on a template, and in that case update the keys just like we do on page copy.

Which version of Umbraco are you running? And since Roy also mentioned templates in #64, is this indeed the exact same issue that was simply never resolved or did you find some workaround there?

I will have a look at this probably this week and if it can be detected a page is created from a template it should be fixable fairly easily, but if we cannot tell if a page was created from a template it will be more difficult.

BrentEvenhuisIO commented 1 year ago

Correct! Templates are created from pages containing the content blocks and when you make a new page based on those templates they share the same key. We are currently running Umbraco version 10.2.0. It's the exact same issue Roy mentioned, we thought it was solved but the client wasn't using templates until recently.

Thank you for taking a look!

PerplexDaniel commented 1 year ago

I can reproduce the ContentBlock ids / NestedContent keys inside are indeed all the same as the ids of the Blueprint. It seems NestedContent / BlockList are suffering from the same bug so even Umbraco isn't handling this correctly.

There does not seem to be any special event/notification for content that is created based on a Blueprint, but client side it can be recognized based on a &blueprintId=... in the querystring when the page is being created.

I have included a fix in 2.1.9 (just uploaded to NuGet, might take a bit to show up for you) which checks for this parameter and in that case will ensure all ids of ContentBlocks are unique. This will fix the issue for any new pages that are created in this new version. Existing pages will not be retroactively modified since there does not seem to be any way to detect which pages are created based on Blueprints.

A workaround for existing pages would be to Copy all blocks (available in the Options sidebar in ContentBlocks), then remove all blocks, then Paste content. No need to save/publish in between, only at the end after pasting blocks. Copy all blocks will also update all keys/ids so this will end up doing the same.

I'll close this issue as it should be fixed. If it somehow turns out not fixed for you please reopen and let me know what happens.

BrentEvenhuisIO commented 1 year ago

Thanks for the fix, just updated the package and it seems to work correctly. Thank you for also supplying a workaround option for the pages still having the contentblock issue!