We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 22797
    • 134 Posts
    In the support thread for the Doc Finder module, Bogdan questioned whether it was appropriate to invoke events with the word "form" in them in places that have nothing to do with those forms (http://modxcms.com/forums/index.php/topic,24488.45.html%20#subject_189255). My response was that those were the only events available, and besides, they don’t have anything to do with the form per se. That’s true, but upon further reflection, it’s clear that someone might write a script that does make the assumption that the action is taking place in the context of the form.

    I think we need to alter the events a bit. First, I think we need to remove the word "Form" from all of them (though we can leave the event name in the database as an alias for backward compatibility). Rather than OnBeforeDocFormSave or onDocFormSave, we ought to have OnBeforeDocSave and OnDocSave. Instead of OnBeforeSnipFormSave and OnSnipFormSave, we should have OnBeforeSnipSave and OnSnipSave ... and so on. But we ought to allow script writers to take advantage of the context in which the event is invoked. For example, right now, the invocation of the event before saving a document includes two pieces of data: mode and id.
    $modx->invokeEvent("OnBeforeDocFormSave", array (
        "mode" => "upd",
        "id" => $id
    ));

    If we remove the word "Form" from the event name, we can still let it be known that the event was invoked from within the form:
    $modx->invokeEvent("OnBeforeDocSave", array (
        "invokedFrom" => "docForm",
        "mode" => "upd",
        "id" => $id
    ));

    This kind of structure would allow for greater specificity, accuracy, and relevance when creating scripts that depend on system events.
      • 3785
      • 143 Posts
      Another interesting question is: should this events be triggered always when the respective database fields are manipulated by a script or just in certain cases?
        Medianotions – Studio für Webdesign
        http://www.medianotions.de
        • 22303 MODX Staff
        • 10,725 Posts
        IMO they need to remain as they are, because moving forward (i.e. in Revolution), the events are very specific to the forms. I understand what you are wanting, which is a central location with which to control changes to the data, and this is exactly what Revolution’s OO approach attempts to address, but not using events (though they are no doubt still utilized greatly for extensibility).

        It would also require that more data be passed to the events; just having the id there if you don’t have the POST/REQUEST values you expected in the context of the forms isn’t really very useful.

        If I didn’t think it would cause a huge rift in the migration process, as well as for existing sites 0.9.x sites and custom code during upgrades, I would otherwise agree with the proposal.
          • 22797
          • 134 Posts
          Quote from: OpenGeek at Dec 09, 2008, 05:47 PM

          IMO they need to remain as they are, because moving forward (i.e. in Revolution), the events are very specific to the forms. I understand what you are wanting, which is a central location with which to control changes to the data, and this is exactly what Revolution’s OO approach attempts to address, but not using events (though they are no doubt still utilized greatly for extensibility).
          I do want a reliable central location that can react to changes in the data, similar to database triggers, but since MySQL’s triggers are rudimentary, they’re not powerful enough to do more complex actions. If the system events are tied so closely to the form in Revolution, what are the alternatives? How would I be able to write a script that reacts to database changes?

          Quote from: OpenGeek at Dec 09, 2008, 05:47 PM

          It would also require that more data be passed to the events; just having the id there if you don’t have the POST/REQUEST values you expected in the context of the forms isn’t really very useful.
          I have a functioning plugin on my site that retrieves those values rather easily, i.e. simply by using the $_POST variable. It may be nice to have those values built in to the system event, but I don’t think it’s absolutely necessary. In any case, passing that information along shouldn’t have a detrimental effect on existing scripts. It might pass more information than necessary for some scripts, but that’s not a problem.
          Quote from: OpenGeek at Dec 09, 2008, 05:47 PM

          If I didn’t think it would cause a huge rift in the migration process, as well as for existing sites 0.9.x sites and custom code during upgrades, I would otherwise agree with the proposal.
          I’m not sure why this would create a rift. It still passes the same information to existing scripts, while also proving additional information to scripts that need it.
            • 22303 MODX Staff
            • 10,725 Posts
            Quote from: paulb at Dec 13, 2008, 09:41 AM

            I do want a reliable central location that can react to changes in the data, similar to database triggers, but since MySQL’s triggers are rudimentary, they’re not powerful enough to do more complex actions. If the system events are tied so closely to the form in Revolution, what are the alternatives? How would I be able to write a script that reacts to database changes?
            It’s called an object model; you extend objects to extend their behavior, and all of the code is centrally available regardless of where or how it is called.
            Quote from: paulb at Dec 13, 2008, 09:41 AM

            I have a functioning plugin on my site that retrieves those values rather easily, i.e. simply by using the $_POST variable. It may be nice to have those values built in to the system event, but I don’t think it’s absolutely necessary. In any case, passing that information along shouldn’t have a detrimental effect on existing scripts. It might pass more information than necessary for some scripts, but that’s not a problem.
            It shouldn’t have to get that data from the POST, which won’t always be available; it should be passed explicitly from any kind of input mechanism.
            Quote from: paulb at Dec 13, 2008, 09:41 AM

            I’m not sure why this would create a rift. It still passes the same information to existing scripts, while also proving additional information to scripts that need it.
            Because every plugin tied to those events would have to change to accommodate the event parameters changes, all the plugins assigned to those events would have to be modified, and some just wouldn’t make sense anymore unless it was related to the form and had all of the form details available to it.

            This is not to mention the added overhead of calling these events anytime an object was saved or modified, which would require the events to be invoked inside the objects. IMO, having custom classes for these things is much more flexible and provides a more constistent way to interact with them.
              • 22797
              • 134 Posts
              Quote from: OpenGeek at Dec 13, 2008, 01:19 PM

              It’s called an object model; you extend objects to extend their behavior, and all of the code is centrally available regardless of where or how it is called.
              If this really does substitute for system events and can be triggered every time an item is saved, deleted, edited, etc., that would accomplish everything I want it to. But I worry that I won’t be able to catch all of the events, or that I’ll have to route events through the extension of an object, rather than directly to the core object, which means rewriting the way objects are called in the core. I’ve been looking at the code for Revolution, but it’s different enough from the code that I’ve been working with for so long, that I admit having some difficulty navigating through it all and trying to figure out how everything is connected. So my worries may prove unfounded, but at least at this point, I still worry.
              Quote from: OpenGeek at Dec 13, 2008, 01:19 PM

              Because every plugin tied to those events would have to change to accommodate the event parameters changes, all the plugins assigned to those events would have to be modified, and some just wouldn’t make sense anymore unless it was related to the form and had all of the form details available to it.
              I was suggesting leaving the existing parameters, and adding new ones. Existing plugins would still work, I would think, because the old parameters wouldn’t change.
              Quote from: OpenGeek at Dec 13, 2008, 01:19 PM

              This is not to mention the added overhead of calling these events anytime an object was saved or modified, which would require the events to be invoked inside the objects. IMO, having custom classes for these things is much more flexible and provides a more constistent way to interact with them.
              Yes, there would be some overhead. That’s to be expected with any script though. As long as you want the script(s) to be triggered, that’s a trade-off that’s unavoidable, no matter what you’re trying to accomplish, whether with system events or snippets or anything else. Just like it is now, the modx administrator would be the one making the decision to enable the plugins or not. At least that’s my perspective on the pre-Revolution code.
                • 3785
                • 143 Posts
                Is there any conclusion regarding wether to trigger the events when I write to the database with the Doc Finder module or not?

                Thanks,
                Bogdan
                  Medianotions – Studio für Webdesign
                  http://www.medianotions.de