And yes, action handler instead of event handler... I'm too much into v4 ;)
[code]using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Collections;
namespace Namespace {
public class ActionHandlerClass : umbraco.BusinessLogic.Actions.IActionHandler {
#region IActionHandler Members
public bool Execute(umbraco.cms.businesslogic.web.Document documentObject, umbraco.interfaces.IAction action) {
if (string.Compare(documentObject.ContentType.Alias, "Alias", true) == 0) {
umbraco.cms.businesslogic.web.Document parentDocument = new umbraco.cms.businesslogic.web.Document(documentObject.Parent.Id);
In an earlier post you guided me towards action handlers. I followed http://umbraco.org/documentation/books/creating-and-using-an-action-handler
step by step and only changed or added values needed for my purpose. Here is one example of code I’m using (Umbraco 3.0.5), and it certainly does fire on new!
[code]
using System;
namespace FDO.Umb.Action.Library
{
public class DefaultValueHandler : umbraco.BusinessLogic.Actions.IActionHandler
{
string umbraco.BusinessLogic.Actions.IActionHandler.HandlerName()
{
return "FDO.Umb.Action.Library.DefaultValueHandler";
}
umbraco.interfaces.IAction[] umbraco.BusinessLogic.Actions.IActionHandler.ReturnActions()
{
return new umbraco.interfaces.IAction[] { new umbraco.BusinessLogic.Actions.ActionNew() };
}
I'll post an update on the issue, which isn't really an issue as the ActionNew is not fired for media items. Did some checks on v3.0.6 source and both Document and Media objects derive from Content node, but only the Document.MakeNew() runs over any registered action handler...
Yes, this helped me who indeed was scratching my head over the same issue. What did you do to work around the problem? I need an action handler to set a few default values on a new media item (I modified the File media type to meet my needs).
Can you use events instead to set default values on media items?
v3 eventhandler not firing on ActionNew()
Hi umbraco gurus,
Help filling my knowledge gap here?
I've got a v3 event handler, following the guidelines from the book section...
Event should fire on Action.New(), I've been setting breakpoints on all methods and it only seems to hit the HandlerName() method?
Any suggestions?
Either touching the web.config or restarting the app doesn't resolve the problem!
Cheers,
/Dirk
Comment author was deleted
An actionhandler ?
Could you post the code ?
Here's the code (some names have been changed...)
And yes, action handler instead of event handler... I'm too much into v4 ;)
[code]using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Collections;
namespace Namespace {
public class ActionHandlerClass : umbraco.BusinessLogic.Actions.IActionHandler {
#region IActionHandler Members
public bool Execute(umbraco.cms.businesslogic.web.Document documentObject, umbraco.interfaces.IAction action) {
if (string.Compare(documentObject.ContentType.Alias, "Alias", true) == 0) {
umbraco.cms.businesslogic.web.Document parentDocument = new umbraco.cms.businesslogic.web.Document(documentObject.Parent.Id);
if (parentDocument != null && parentDocument.Id > 0) {
umbraco.cms.businesslogic.property.Property p1 = documentObject.getProperty(settings["p1Alias"].ToString());
umbraco.cms.businesslogic.property.Property p2 = documentObject.getProperty(settings["p2Alias"].ToString());
if ((p1 != null) && (p2 != null)) {
p1.Value = p2.Value;
documentObject.Save();
return true;
}
}
}
return false;
}
public string HandlerName() {
return "Namespace.ActionHandlerClass";
}
public umbraco.interfaces.IAction[] ReturnActions() {
return new umbraco.interfaces.IAction[] { new umbraco.BusinessLogic.Actions.ActionNew(),
new umbraco.BusinessLogic.Actions.ActionSave() };
}
#endregion
}
}[/code]
Hi Dirk
I thought you were the guru ;-)
In an earlier post you guided me towards action handlers. I followed
http://umbraco.org/documentation/books/creating-and-using-an-action-handler
step by step and only changed or added values needed for my purpose. Here is one example of code I’m using (Umbraco 3.0.5), and it certainly does fire on new!
[code]
using System;
namespace FDO.Umb.Action.Library
{
public class DefaultValueHandler : umbraco.BusinessLogic.Actions.IActionHandler
{
string umbraco.BusinessLogic.Actions.IActionHandler.HandlerName()
{
return "FDO.Umb.Action.Library.DefaultValueHandler";
}
umbraco.interfaces.IAction[] umbraco.BusinessLogic.Actions.IActionHandler.ReturnActions()
{
return new umbraco.interfaces.IAction[] { new umbraco.BusinessLogic.Actions.ActionNew() };
}
Boolean umbraco.BusinessLogic.Actions.IActionHandler.Execute(umbraco.cms.businesslogic.web.Document documentObject, umbraco.interfaces.IAction action)
{
if (documentObject.ContentType.Alias == "bulletin")
{
try
{
string getWinUser = umbraco.library.RequestServerVariables("LOGON_USER").Replace("XXX.DOM\", "");
if (string.IsNullOrEmpty(getWinUser)) { getWinUser = "na"; }
umbraco.cms.businesslogic.property.Property gwu = documentObject.getProperty("fdoExtGetWinUser");
umbraco.cms.businesslogic.property.Property unh = documentObject.getProperty("umbracoNaviHide");
if (gwu != null) { gwu.Value = getWinUser; }
if (unh != null) { unh.Value = 1; }
//if (gwu == null) { return false; }
documentObject.Save();
}
catch (Exception)
{
return false;
}
return true;
}
else
{
return false;
}
}
}
}
[/code]
Hi,
I'll post an update on the issue, which isn't really an issue as the ActionNew is not fired for media items. Did some checks on v3.0.6 source and both Document and Media objects derive from Content node, but only the Document.MakeNew() runs over any registered action handler...
Might help someone with similiar issue.
Regards,
/Dirk
Hello.
Yes, this helped me who indeed was scratching my head over the same issue. What did you do to work around the problem? I need an action handler to set a few default values on a new media item (I modified the File media type to meet my needs).
Can you use events instead to set default values on media items?
/John
is working on a reply...