• Login
  • Register

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?

You are not authorized to post a reply.
Sort:


New Member


Posts:16
New Member

    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


    Posts:501
    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


      Basic Member


      Posts:91
      Basic 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 Member


        Posts:16
        New Member

          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.


          Basic Member


          Posts:91
          Basic 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 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. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
            2. 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.
            3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
            4. No Flaming or Trolling.
            5. No Profanity, Racism, or Prejudice.
            6. Site Moderators have the final word on approving / removing a thread or post or comment.
            7. 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