Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
I'm having a go at setting a default value for a property on creation using this example: https://our.umbraco.com/documentation/reference/events/EditorModel-Events/#usage
However, I need to get the new node's parent name. I can get the ID easily enough e.Model.ParentID but I clearly need to call in some other services as I cannot call IPublishedContent or similar at this point to easily get the node name for that ID.
I'm sure it's relatively simple, but my GoogleFu is failing me.
You can inject the services you need access to in the constructor, e.g.
private readonly IUmbracoContextAccessor _umbracoContextAccessor;
public SubscribeToEditorModelEvents(IUmbracoContextAccessor umbracoContextAccessor)
_umbracoContextAccessor = umbracoContextAccessor;
and then using it like this:
var cache = _umbracoContextAccessor.UmbracoContext.Content;
var parent = cache.GetById(e.Model.ParentId);
I recently updated the documentation with an additional example using SendingMemberModel and injecting `IMemberGroupService.
Thank You! Exactly what I was after
is working on a reply...
Write your reply to:
Image will be uploaded when post is submitted