1. 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?

Discussion in 'XenForo Development Discussions' started by rhodes, Mar 21, 2016.

  1. rhodes

    rhodes Active Member

    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?
     
  2. Mike

    Mike XenForo Developer Staff Member

    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 likes this.
  3. rhodes

    rhodes Active Member

    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.
     
  4. rhodes

    rhodes Active Member

    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?
     
  5. Mike

    Mike XenForo Developer Staff Member

    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?
     
  6. rhodes

    rhodes Active Member

    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.
     
  7. Mike

    Mike XenForo Developer Staff Member

    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.
     

Share This Page