DNN Forums

Ask questions about your website to get help learning DNN and help resolve issues.

Can we add so called "Filters" to the DNN Event System?

Sort:
You are not authorized to post a reply.





New Around Here





    Many CMSs have built in "actions" and "filters". DNN's event system fulfills the the like of "actions" where you can add some custom code to do something after a particular event takes place. For example: "Every time a page is updated, send me an email".

    I now have a use case where I need a "filter" rather than an "action". The difference here is that some custom code needs to execute on the object that was just modified, before committing it to the data store, rather than after. For example: "Every time a page is updated, overwrite a property of the updated page (i.e. the TabInfo object) and commit it to the data store".

    This would be very useful if you want to constrain a property without making changes to the DNN core. Is there already a decent way to achieve this in DNN? If not, is it worth creating an RFC for this on GitHub?

    Paras Daryanani

    Celestify

    Celestify - we build digital ecosystems.





    Veteran Member





      Paras,

      I don't know of such a "filter" out of the box (but I might be wrong, as I never needed that, and DNN is really full of hidden treasures sometimes). Anyway, creating a RFC on GitHub is always a good idea...

      Happy DNNing!
      Michael

      Michael Tobisch
      DNN★MVP

      dnnWerk Austria
      DNN Connect





      Advanced Member





        Michael is right, there isn't anything built into DNN to let you intercept an object being saved to the database. However, depending on your scenario, you may be able to use an event like the TabUpdated event to see what changes are being done and adjust/revert them as needed.
        DNN partner specializing in custom, enterprise DNN development https://engagesoftware.com/showcase





        New Around Here





          Thank you, Michael and Brian.

          The issue with using the TabUpdated event is that I want to overwrite the TabInfo object itself, which will put me into infinite recursion:

          Line 34 will keep calling the TabUpdated method over and over again.

          I could probably write my own DAL2 controller and class to directly write the TabInfo object to the DB instead of using TabController, but I thought to ask here if there's a better way along the lines of "filters", which could look something like this:



          This is assuming that we can pass args.Tab by reference, such that it can be modified within the PreTabUpdated method. If not, then we could change it to return a TabInfo object rather than returning void. This is referred to as "filters" by other CMSs.

          Paras Daryanani

          Celestify

          Celestify - we build digital ecosystems.





          Advanced Member





            That would be an interesting feature to consider. That said, it would only work for "core" types (pages, modules, users, sites), and not for custom content within modules, which might limit its usefulness as a general pattern. But you can open a discussion if you think we should consider adding it to the platform.

            In this case, I think you'd want to check if the properties you're setting are different than the values that you're setting them to, and then avoid the update call if the values are already correct.

            Hope it helps!
            DNN partner specializing in custom, enterprise DNN development https://engagesoftware.com/showcase
            You are not authorized to post a reply.

            These Forums are dedicated to the discussion of DNN Platform.

            For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

            1. If you have (suspected) security issues, please DO NOT post them in the forums but instead follow the official DNN security policy
            2. No Advertising. This includes the promotion of commercial and non-commercial products or services which are not directly related to DNN.
            3. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
            4. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
            5. No Flaming or Trolling.
            6. No Profanity, Racism, or Prejudice.
            7. Site Moderators have the final word on approving / removing a thread or post or comment.
            8. English language posting only, please.

            Would you like to help us?

            Awesome! Simply post in the forums using the link below and we'll get you started.

            Get Involved