I don't know if there is a built-in way to hide a property in edit-mode, you might have to write your own renderer for that.
If it doesn't have to be hidden the editable attribute works fine and it will get stored automatically when you save.
[Editable(false)]
You can use ScaffoldColumn to hide the property in edit-mode.
[ScaffoldColumn(false)]
I have tried both the ways suggested above. It does hides the propety from the admin panel but when in my Page created event I try to store the value programmatically it throws error
The property Creator is read-only
I am trying this
[ScaffoldColumn(false)] [Display(GroupName = SystemTabNames.Content, Name = "Creator")] public virtual string Creator { get; set; }
articlePage.Creator = "my value";
First or all, which error does it throw? Dare I guess about the content is read only?
Secondly, mind the difference between the events PublishingContent and PublishedContent.
Publishing is triggered BEFORE the changes are published and saved to the database. You have time to make some final adjustments before the content is published.
Published is triggered after the content has been saved and published. You will need to create a writable clone and publish the content again.
Thanks for the response. Now I am trying this,
private void EventPublishing(object sender, ContentEventArgs e) { var repo = ServiceLocator.Current.GetInstance<IContentRepository>(); if (repo == null) return; var articlePage = e.Content as ArticlePage; if (articlePage == null) return; if (RystadIdentity.Current == null) return; articlePage.Creator = RystadIdentity.Current.AuthenticatedUser.UserInfo.id; repo.Save(articlePage.CreateWritableClone()); }
But the property Creator is null when I check it. Am I doing something wrong here?
Hi,
You say that this page is created programmatically?
Could it be that the user has not been authenticated yet at the time you're creating the page?
Depending on how you handle your authentication just because you have performed the "authenticate" logic, it doesn't mean that the Identity.Current is updated with the current user information until your second request. Doesn't mean that it's the problem you have now but a guess.
Hi,
No the page is created in the admin mode but I just a property to the page programmatically in the publishing content event. And just to be sure I have added a break point and I do have the value there but it is not stored for some reason.
Now the issue is that because I am in the publishing event and when I save it gets into an infinite loop.
private void EventPublishing(object sender, ContentEventArgs e) { var repo = ServiceLocator.Current.GetInstance<IContentRepository>(); if (repo == null) return; var articlePage = e.Content as ArticlePage; if (articlePage == null) return; if (RystadIdentity.Current == null) return; var clone = articlePage.CreateWritableClone() as ArticlePage; clone.Creator = RystadIdentity.Current.AuthenticatedUser.UserInfo.id; repo.Save(clone, SaveAction.Publish); }
When I save it again comes into the publishing event and the same cycle continues..
So to solve the loop I had to user
repo.Save(clone, SaveAction.Patch);
And the reason why the property was not being updated was that I was using
[Ignore]
as an attribute, I removed it and used
[ScaffoldColumn(false)]
to hide it from the edit view. It works. :)
When you are in a publishing event then you should not call repo.Save(). When you edit a attribute in a *ing event then the value will get saved. Also, you don't need to create a writeableclone as the Object allready is in a writeable state.
private void EventPublishing(object sender, ContentEventArgs e) { var articlePage = e.Content as ArticlePage; if (articlePage == null) return; if (RystadIdentity.Current == null) return; articlePage.Creator = RystadIdentity.Current.AuthenticatedUser.UserInfo.id; }
That should work if I don't remember totaly wrong :)
So I am letting users authenticate from an external api. When these users create a page I just have CreatedBy in the currentPage instance.
What I am trying to do is to add a property to the page which will be fullfilled by the PageCreatedEvent programtically and not be allowed to tempered with from te admin view.
I have this
Is there a way that I can create a property and make it hidden on the page edit page? And then how do I store it programmitcally?
Thanks