ContentSavingNotification - Cannot change name of node before save
Hi Folks,
I am trying to hook into the ContentSavingNotification and change the name of a node being saved based on some conditions.
It appears that you cannot change the name of a node.
public void Handle(ContentSavingNotification notification)
{
foreach (IContent node in notification.SavedEntities)
{
if(SOME CONDITION IS MET)
{
node.Name = "New Name";
}
}
}
If you inspect notification.SavedEntities the correct node's name is indeed changed however when the node appears in the backoffice it has the original name.
This approach in Umbraco 8 using ContentService.Saving event worked however its not working in Umbraco 9 with the new approach.
Anyone any ideas if this is an issue with Umbraco or I am doing something wrong?
ContentSavingNotification - Cannot change name of node before save
Hi Folks,
I am trying to hook into the ContentSavingNotification and change the name of a node being saved based on some conditions.
It appears that you cannot change the name of a node.
If you inspect notification.SavedEntities the correct node's name is indeed changed however when the node appears in the backoffice it has the original name.
This approach in Umbraco 8 using ContentService.Saving event worked however its not working in Umbraco 9 with the new approach.
Anyone any ideas if this is an issue with Umbraco or I am doing something wrong?
Cheers,
Marc
Hi Marc
I seem to recall someone telling me to use this before:
Give that a try.
Here is a link to it being used in a test in the Umbraco repo. https://github.com/umbraco/Umbraco-CMS/blob/0134199035cf4caf0deddc24648be5cdeb27d2f9/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentServiceTests.cs#L1235
Paul
Hi Paul,
Injected contentService into the constructor and not getting "CommitDocumentChanges" as an available method.
Any ideas?
Cheers,
Marc
Just checked and unfortunately CommitDocumentChanges is an internal method so cant access it. :(
Hi,
you need to use SetCultureName for ex :
Merci gamin :-)
is working on a reply...