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

Alert users in addon?

Discussion in 'XenForo Development Discussions' started by Liam W, Mar 2, 2014.

  1. Liam W

    Liam W Well-Known Member

    OK, I'm going around in circles with headaches here...

    Is there a guide or can someone tell me exactly how to alert users, just with plain text, in an addon?

    There's no specific content with it - it's just plain text and a link.

    I've looked through the code, and I created an entry in `xf_content_type_field` and it still doesn't work. The alert 'alerts', as in it says I have a new alert, but when I go to view it it says I have no alert.

    I added a few var_dumps, and it looks like it can't find the alert handler for my content type - even though I put it in that table.

    Do I have to add another db entry somewhere?

    Liam
     
  2. Brogan

    Brogan XenForo Moderator Staff Member

    There are quite a few steps to getting alerts implemented.
    Very briefly, you will need:
    • An alert handler class
    • A datawriter (optional)
    • Data in the xf_content_type and xf_content_type_field tables
    • A specifically named template, e.g. alert_content_type_action
    It sounds like you missed the xf_content_type table.
     
    Daniel Hood, Liam W and Chris D like this.
  3. Chris D

    Chris D XenForo Developer Staff Member

    There needs to be an entry in xf_content_type which contains a cache of all the available content type fields ... this is rebuilt automatically. You just need to insert the content_type name and the add-on ID.

    During rebuild, matching fields in xf_content_type_field are serialised and stored in the "fields" field of xf_content_type.

    So once you have that, and the bits Brogan mentions above, you need to rebuild the content types cache. Otherwise you get the exact problem you describe. Easiest way to rebuild the cache is just to install an add-on (e.g. export your add-on XML and upgrade with it).

    Things should start working then.
     
    Daniel Hood and Liam W like this.
  4. Liam W

    Liam W Well-Known Member

    @Brogan @Chris D

    Perfect! I had everything except the xf_content_type entry. I added it, upgraded the addon to rebuild everything, and it works :)

    I'm not using a datawriter however, I'm just using the XenForo_Model_Alert model to alert users - there's no data associated with the alert, so there's nothing I need to store.

    Thanks :)

    Liam
     
    Chris D likes this.
  5. Daniel Hood

    Daniel Hood Well-Known Member

    I generally just delete the xf data registry row for content types. Is there a downside to this? It rebuilds exactly what I want on the next page load.
     
  6. Chris D

    Chris D XenForo Developer Staff Member

    TheBigK likes this.
  7. Daniel Hood

    Daniel Hood Well-Known Member

    I agree. It bugs me that we have to run queries to do those when everything else is in the xml. Hopefully it will be added soon.
     
  8. Liam W

    Liam W Well-Known Member

    I was surprised something like that wasn't in the addon XML, especially as the xf_content_type table has an addon_id column...

    This addon will make it much easier :p Thanks for the link! (And damn me for not searching for it sooner!)

    Liam
     

Share This Page