hgtonight / Application-Yaga

Yet Another Gamification Application is a Garden application that provides a gamification platform for Vanilla Forums and other Garden applications.
GNU General Public License v2.0
28 stars 23 forks source link

Form->InputPrefix is deprecated #146

Closed R-J closed 7 years ago

R-J commented 7 years ago

The BadgeControllers Edit() method tries to fetch the rules form fields based on a prefix "_Rules" before the form fields. The RulesControllers GetCriteriaForm() supplies the forms through an AJAX call. Before the FormString gets built, Form->InputPrefix is set to "_Rules" in order to prefix every form field.

But InputPrefix has been deprecated. That's why there is no prefix any more before the form field names and therefore they cannot be found.

This is the reason for this error https://github.com/hgtonight/Application-Yaga/issues/142

I see four ways to react on that:

  1. Change all rules to incorporate a ['name' =>'_Rules/ElementName'] attribute. That way no logic would have to be changed. The downside is that people with custom rules may face problems.
  2. Prefix all other form field with something like "BadgeEdit_" by changing the edit view and change the logic in the Edit() method from if(substr($Key, 0, 7) == '_Rules/') { to if(substr($Key, 0, 10) != 'BadgeEdit_') {. You would only have to change two files then and everything else could stay the same.
  3. Pass all FormValues to the YagaRules Validate() method. But if any form field of a rule would have the same name as a form field of the edit view, you would get unpredictable errors.
  4. A magician like you would most probably be able to extend/replace the form class with a thin wrapper that would add a name attribute to every call. Although I think that this would be quite cool, I'd also say that this is overkill...
steam1 commented 7 years ago

R-J that's how it works ! Thanks and regards

if(substr($Key, 0, 10) != 'BadgeEdit_') { //$RealKey = substr($Key, 7); $Criteria[$Key] = $Value; }

HIAviator commented 7 years ago

By implementing #2 would you not have to also trim the "BadgeEdit_" prefix off the front of the other form values so that they store correctly?

R-J commented 7 years ago

I hope you are asking @steam1 and not me, since I never really made those changes but was just thinking about how that could be done...

HIAviator commented 7 years ago

For now I've hard coded the rules and perks fields in manually which works for my own implementation to get it working. @steam1 could you let me know if you have a more flexible solution done?

R-J commented 7 years ago

That one is less invasive, though far from being elegant... :-(

hgtonight commented 7 years ago

Closed by #148

HIAviator commented 7 years ago

That's a decent solution for the issue. This also needs to be done for Ranks as well.