Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
Options

Most elegant solution if there is no FireEvent when I need one?

R_JR_J Ex-FanboyMunich Admin

I've added extra fields to vanillas discussion. The input get's saved to an additional table. Now I want to edit the discussion and let my additional field values be displayed inside of the form elements and certainly save the changes made to them.

I've used PostController_AfterDiscussionSave_Handler, the only event in function Discussion of class.postcontroller.php I found (not counting BeforeDiscussionPreview because it seems to be useless for my plans)

While it is possible to use it when the discussion is created, it is totally useless when I edit a discussion. To my understanding, I'd need an additional event in the near of if ($this->Form->AuthenticatedPostBack() === FALSE) { where the form get's prefilled
Just to for testing purposes, I've hardcoded the form filling in this if statement and it seems to be the right place.

What would you suggest? I can think of:

  1. ask the developers for an additional hook and wait until (if ever) it will be implemented
  2. copy the complete function and override the original one, thus making it really hard to stay compatible with other versions than the one I used during development
  3. describe how to add an own FireEvent into the original source code, making it unpredictable for any other version (although I assume the probability that it will work is quite higher than for the 2. alternative) and not really fool proof

Is there any other and more elegant way?
Could hooking the class.discussionmodel.php functions Before- and AfterDiscussionSave be a solution for at least the db-storage-problem? It will not solve the edit-display-problem, though...

Comments

  • Options
    businessdadbusinessdad Stealth contributor MVP

    What are you trying to accomplish? If the purpose is to populate form fields automatically, all you have to do is modify the query used when the Discussion is loaded and add the new fields to the page, they will be populated automatically.

  • Options
    R_JR_J Ex-Fanboy Munich Admin

    I'd thought about that for a second, when I've discovered the hooks in the discussion model, but obviously I should have taken more time for thinking.
    And to be honest: it took me three times reading your answer before I understood that the way I tried to realize it was some kind of brutally avoiding the framework. I suppose that's why you didn't know what I was trying to do...

    I'll try to hook into the discussionmodel and I think I'll find what I need there in order to do what you've suggested. Many thanks!

Sign In or Register to comment.