Problem with notification url

Hello,

I've made a plug-in for my company, that work fine but there is still a problem. I have notification issues that i don't understand. On a specific object creation, a notification is made, and the text is correct : "Benaesan  a créé le tableau test il y a 6 minutes" . The first link works well, but in the second one the href is the home page of my site and not the object's url.

If someone have an idea, i'll take.

Thank by advance

  • Not enough information to give any advice.

    For the cited text I guess you are asking about the links in the title line of a river entry (activity page) and not about (site) notifications. Or am I wrong?

    If it's a river entry that has a wrong link, what's the code snippet (elgg_create_river_item() arguments) you use? Is the object_guid wrong here. And what about the river view corresponding to the created object? Are you sure you have no error there - what is the code of the view?

    Or is it really a notification you are asking about? Have you added any code for handling of the notification content then? If so, what's the code?

  • Thanks for the reply. I have fixed some of my problem. 

    I've had update_subtype("object", "mySubtype", "MyClass");

    so the river have the right content, 

    Benaesan a créer le tableau test_tab1 dans le groupe test groupe fermé il y a 7 minutes

    But in notification(By mail or by the notifier plugin) the text is

    subject => "Notification à propos de Benaesan"

    body => Voir la nouvelle activitée sur http://localhost/elgg_dev/obj/757 

    That seem to be a generical text, I don't understand why.

    In my Log file

    [13-Apr-2017 15:37:40 Europe/Paris] NOTICE: Missing English translation for "river:create:object:" language key[13-Apr-2017 15:37:40 Europe/Paris] NOTICE: Results for the notification event create:object:: Array(    [36] => Array        (            [email] =>             [notifier] =>             [site] =>         )    [111] => Array        (            [email] => 1            [notifier] => 1            [site] => 1        ))

     

  • It's best to use add a notification handler function to be able to set up the notification text for on-site and email notifications as you want it to be. If the handler functions is not added, Elgg most likely uses some fallback option to send out notifications that might not be fit 100% in all cases.

    As a sidenote: for the river entries you would have to add a language string to the language file(s) of your plugin with the subtype of the object created in the key like

    "river:create:object:mySubtype" => "%s added a new item %s",

    with the %s placeholders which will get replaced by the user's name and the link to the new content item.

    As for the notification handler you can look for example in start.php of the blog plugin or other plugins how to register for the notification event (in your case the "create" event) and how to add the notification handler function. In the init function you would add

    // notifications
    elgg_register_notification_event('object', 'mySubtype', array('create'));
        elgg_register_plugin_hook_handler('prepare', 'notification:create:object:mySubtype', 'mySubtype_prepare_notification');

    And then the function

    function mySubtype_prepare_notification($hook, $type, $notification, $params) {
        $entity = $params['event']->getObject();
        $owner = $params['event']->getActor();
        $recipient = $params['recipient'];
        $language = $params['language'];
        $method = $params['method'];
    
        $notification->subject = elgg_echo('mySubtype:notify:subject', array($entity->title), $language);
        $notification->body = elgg_echo('mySubtype:notify:body', array(
            $owner->name,
            $entity->title,
            $entity->getExcerpt(),
            $entity->getURL()
        ), $language);
        $notification->summary = elgg_echo('mySubtype:notify:summary', array($entity->title), $language);
    
        return $notification;
    }

    You also need to add the language strings used in the handler function.

  • Hello, 

    Sorry for the delay, I've been on a big project and I didn't take time for respond. So after some experiment All of this work. But in a first time the link within the notification doesn't work. I've had to add :

    elgg_register_plugin_hook_handler('entity:url', 'object', 'mySubtype_set_url');

    And now everything works. Thanks a lot

Beginning Developers

Beginning Developers

This space is for newcomers, who wish to build a new plugin or to customize an existing one to their liking