• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

How can I use a callback function for fields?

rhodes

Active member
#1
I have a custom field in one of my RM categories, lets say textfield_1 in category_1

textfield_1 is a multiline textfield. Within the setting I've defined a callbach function to modify the value of this field. Unfortunately nothing happens.

Code:
    function myfield(&$content){
        $content = "abc";
    }
Where is my mistake?
 

Mike

XenForo developer
Staff member
#2
Where have you set this callback? The only callback supported by default is for value matching, so it's only used when saving the value. It does actually take the value as the second argument by reference, so it can be modified at that time.
 

rhodes

Active member
#3
The only callback supported by default is for value matching, so it's only used when saving the value.
thank you @Mike. I thought I could use the callback to process the field value every time the resource is viewed, not only during value matching. I have to save an array of IDs (22364,638482,79792) and fetch information from an external database according to these IDs when viewing a single resource. But then I cannot use RM for this purpose.
 

rhodes

Active member
#4
One last question @Mike . If I want to use a callback function when viewing resource items, which would be the best starting point? The public controller?
 

Mike

XenForo developer
Staff member
#5
There are a lot of different options, including controller extension approaches. That's probably the most common option. What are you trying to do specifically?
 

rhodes

Active member
#6
I have a custom multiline textfield. Each line contains a text string and an ID, separated by comma
HTML:
String 1,432
String 2,555
...
String n, 2367
When viewing the resource item I would like to process every single textfield line.
 

Mike

XenForo developer
Staff member
#7
Your best bet may be to use the class extension system to extend XenResource_Model_Resource::prepareResource to "prepare" this custom field before display, and then you can use the prepared version in the template.