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

Add-On Installing Profile Fields?

Discussion in 'XenForo Development Discussions' started by IFeelYourPain13, Jan 8, 2012.

  1. IFeelYourPain13

    IFeelYourPain13 Active Member

    I am creating a mod and looking for information on having the Add-on installing the profile fields for me.
     
  2. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    Unlike some objects in the Admin CP, user fields can't be attributed to an addon. You will need to write some install code for your addon to create the field. Refer to this controller for code to save a new field:

    XenForo_ControllerAdmin_UserField::actionSave
     
  3. IFeelYourPain13

    IFeelYourPain13 Active Member

    Any example install code?
     
  4. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    You can specify an install class when creating an addon:

    Admin CP -> Development -> Create Add-on

    But then you need to write the code to create the profile field. You can use that controller code for reference. Basically you need to call on the datawriter, set the field values, pass those values to the datawriter, and save the changes. The controller from my previous post is a good example to follow.
     
  5. DRE

    DRE Well-Known Member

  6. Jon W

    Jon W Well-Known Member

  7. DRE

    DRE Well-Known Member

  8. Jon W

    Jon W Well-Known Member

    This add-on does thread fields and user fields.

    With my add-on installed, you can attribute user fields to an add-on, and then they will be exported with the add-on. Also, you should be able to export user fields on their own as well. Both will require the end user to have the add-on installed in order to import them.
     
    DRE likes this.
  9. SheepCow

    SheepCow Well-Known Member

    In your add-ons installer code you could just spawn a profile field model, check if they already exist then spawn a data writer and create them
     
  10. Jon W

    Jon W Well-Known Member

    I think that is what Jake suggested. But if you don't want to do that, you can use my add-on and avoid writing any code at all.
     
  11. DRE

    DRE Well-Known Member

    How do I attach the userfield to an addon?
     
  12. SheepCow

    SheepCow Well-Known Member

    Oh yes, read fail ;)
     
    Jon W likes this.
  13. Jon W

    Jon W Well-Known Member

    Install custom fields, edit your user field and there should be a drop down menu to select an add-on. You may need to have debug mode enabled.
     
  14. DRE

    DRE Well-Known Member

  15. Jon W

    Jon W Well-Known Member

    DRE likes this.
  16. DRE

    DRE Well-Known Member

    Yeah I was able to make my first addon with it. I also don't like having to use TMS. Floris made a resource explaining how to create an addon that inserts a template edit. That's my next step but I would either have to track down Floris and ask if he saved it or beg someone to teach me.
     
    Jon W likes this.
  17. Jon W

    Jon W Well-Known Member

    There's this one for template hooks:
    http://xenforo.com/community/threads/how-to-use-template-hooks.13167

    But you probably want template post render. It's not that much different, it just searches on the template name instead of the hook name. If you follow the video but make the appropriate changes (i.e., selecting template_post_render instead of template_hook), you'll pretty much be there. You then just need to code your replacement, which could be not too difficult like:
    PHP:
    $content .= 'Some code I want to add at the end';
    to more complicated things like:
    PHP:
    $pattern 'Some code that already exists';
    $replacement 'Some code I want to put before it';
    $content str_replace($pattern$replacement $pattern$content;
    to the even more complicated things like:
    PHP:
    $pattern '#(Some reg(?:ular )?exp(?:ression) for the code )you want( to replace)#';
    $replacement '${1}DRE wants${2}';
    $content preg_replace($pattern$replacement $pattern$content;
    Just make sure to use $content instead of $contents.

    Can't believe there isn't a guide. If it wasn't for TMS, there would probably be plenty of guides for it.
     
    DRE likes this.
  18. DRE

    DRE Well-Known Member

    Yeah cause vbulletin had a ton of guides. I had only just started making addons for vbulletin using their guides before i switched over to xenforo.
     

Share This Page