XF 2.2 How to implement reactions in a custom content

I was expecting it to throw unknown template error. Check the server error log in ACP. If you still don't see anything then the next part is to create a template. To see what the template name should be look into \XF\Alert\AbstractHandler::getTemplateName().
 
I was expecting it to throw unknown template error. Check the server error log in ACP. If you still don't see anything then the next part is to create a template. To see what the template name should be look into \XF\Alert\AbstractHandler::getTemplateName().
No errors on log as well.
1712892970040.webp

What should be the name and content of this template, do you know?
 
@TickTackk but what should be the name? e.g. my template name is "user_profile" , so the it would be alert_user_profile_ ??? what is the action? didn't get this point. And where to call it?
 
PHP:
    public function getTemplateName($action)
    {
        return 'public:alert_' . $this->contentType . '_' . $action;
    }
We know $this->contentType will return user_profile for you. To find out what the value of $action will be you will need to run this query:
SQL:
SELECT action
FROM xf_user_alert
WHERE content_type = 'user_profile'
ORDER BY alert_id DESC
LIMIT 1

Or edit out this function
PHP:
    public function getTemplateName($action)
    {
        return 'public:alert_' . $this->contentType . '_' . $action;
    }
with
PHP:
    public function getTemplateName($action)
    {
        \XF::logError('public:alert_' . $this->contentType . '_' . $action);
        return 'public:alert_' . $this->contentType . '_' . $action;
    }
and that will log a server error when you are trying to view the alerts page or popup.
 
Didn't log anything here. I think it's not passing through getTemplateName function... :unsure:
Let me know if you have another solution for that...
 
Did you check the alert table to see if it's being inserted? The action for reaction alerts is reaction, but it won't be sent if the alerted user has no permission to view the content (as determined by the canViewContent method on the alert handler, which delegates to the entity canView method by default).
 
Did you check the alert table to see if it's being inserted? The action for reaction alerts is reaction, but it won't be sent if the alerted user has no permission to view the content (as determined by the canViewContent method on the alert handler, which delegates to the entity canView method by default).
Yes, the action 'reaction' is being inserted into the table 'xf_user_alert'. The view_date and read_date is being updated accordingly.
Reaction is working, but no message at all.
 
You can try {{ dump($alerts) }} on the account_alerts to see if it makes it to the page. If not, then it implies either the content couldn't be added to the alert (have you defined the entity field for your content type in the control panel?), or the canViewContent and/or canViewAlert methods on the handler return false.
 
You can try {{ dump($alerts) }} on the account_alerts to see if it makes it to the page.
I tried but no alert message.
1713323189663.webp
If not, then it implies either the content couldn't be added to the alert (have you defined the entity field for your content type in the control panel?),
The content was added to table xf_reaction_content
1713323913410.webp
And yes, the entity is defined, also the content_type reaction_handler_class
or the canViewContent and/or canViewAlert methods on the handler return false.
The methods return true, they are ok.

The reaction happens, I can see the alert signal (as I posted before), but when I click on it there's no message.
Where is the message template pointed to in this process? What else could it be?
 
And yes, the entity is defined, also the content_type reaction_handler_class
You have defined both entity and alert_handler_class (in addition to reaction_handler_class)?

screenshot-aJ8RLs.webp

If you try sticking \XF::dump(\XF::app()->findByContentType('fox_social_user_profile', 6)) somewhere, does it return the entity as expected?

Where is the message template pointed to in this process? What else could it be?
It's the render method of the alert handler. It renders the public:alert_{$contentType}_{$action} template. You can see the content type and action in the row of the xf_user_alert table.
 
Top Bottom