Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Jan 28, 2009 @ 23:57
    Dirk De Grave
    0

    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

    Jan 29, 2009 @ 09:27

    An actionhandler ?

    Could you post the code ?

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Jan 29, 2009 @ 09:52
    Dirk De Grave
    0

    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]

  • Finn 86 posts 50 karma points
    Jan 29, 2009 @ 14:25
    Finn
    0

    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]

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Jan 30, 2009 @ 00:46
    Dirk De Grave
    0

    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

  • John Hård 9 posts 29 karma points
    Sep 07, 2009 @ 14:41
    John Hård
    0

    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

Please Sign in or register to post replies

Write your reply to:

Draft