How do you set the priority for widgets on the profile page?

Allon Prooit Posted in Component Development 6 months ago

How does one go about setting priority for widgets placed onto the profile page? For instance, right now if I turn on my Mp3 component it shows up at the top and drops my new component's widget down one slot. Need it to come back up. How so?

Replies
German Michael Zülsdorff Replied 6 months ago

As for getting a little more in depth understanding about hooks prioritization you should start at line 124 of ossn.lib.system.php

function ossn_add_hook($hook, $type, $callback, $priority = 200) {

That is, if you omit the 4th parameter when adding hooks like

ossn_add_hook('profile', 'modules', 'function_of_component_ABC');

ossn_add_hook('profile', 'modules', 'function_of_component_DEF');

both hooks will get the same default priority of 200, and the order of appearance solely depends on the order the components have been installed (see your components list at the admin back end).
Thus, if component ABC was installed prior to component DEF you'll get a widget sequence like
Friends
Photo Albums
ABC
DEF

Checking the com files of OssnProfile and OssnPhotos gives, that their hooks have no explicit priority, too - so up to this point all four are running with priority = 200 with the earlier installed Ossn's core components on top.

Okay, so what to do if you want your ABC component's widget to appear before the Friends widget and DEF to be first one?

You would simply need to add explicit priority values smaller than 200 like

ossn_add_hook('profile', 'modules', 'function_of_component_ABC', 199);

ossn_add_hook('profile', 'modules', 'function_of_component_DEF', 198);

This will change the widget's sequence to
DEF
ABC
Friends
Photo Albums

Indonesian Arsalan Shah Replied 6 months ago

If widget is created using component php (not javascript) then it is easy as example for profile photos widget

in your component init

<?php
 ossn_register_callback('ossn', 'init', function(){
        ossn_unset_hook('profile', 'modules', 'profile_modules_albums');                                              
        ossn_add_hook('profile', 'modules', 'profile_modules_albums', 1);                                             
});
us David Orwig Replied 6 months ago

I've had the same question. How can we do this?