Alert users in addon?

Liam W

in memoriam 1998-2020
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
 
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.
 
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.
 
@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
 
Easiest way to rebuild the cache is just to install an add-on (e.g. export your add-on XML and upgrade with it).

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.
 
No, you're right. That's fine too.

I forgot about that approach because I actually use this:

http://xenforo.com/community/resources/content-type-management.2513/

Still unsure why something like this isn't in the core - but with improvements where the content types are included in the add-on XML.

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
 
Back
Top Bottom