Help using elgg_list_entities, or alternate solutions for my problem?

Hi All - I am on my second Elgg plugin development and am hitting some problems, and could do with some more expert help please.

I am writing a plugin which will allow you to see a stream of all blog posts that ayou have permission to see, for a selected user, output on a single page. The reason for that specific display of blog posts is for assessment of blogs in an academic context.

I've got my 'stream of blog posts' part of the plugin working nicely, and now I'm focussing on how to select a specific user and reach their 'stream' page.

At the moment I'm using elgg_list_entities to output a list of all users within my plugin, but of course the default url for each user takes you to their profile page. I think there's 2 sensible things to do from here, but I'm strugging to see *how* to do them:

1. Somehow override the default url used for each user to link directly to the stream of blog posts instead of their profile. Is there any way of doing this and still using elgg_list_entities? or do i need to do something more significant?

OR

2. Ditch my list of users in the plugin and somehow hook the stream of blog posts option directly into the standard Profile page.

I don't want to remove the option for the site administrator to change out the profiles plugin if they want to (but can accept that might need to be a constraint). More than that I don't want to give us problems for future upgrades by hacking the core plugin. Is there any way of extending the profile plugin without touching the profile plugin code?

Has anyone with more understanding of elgg_list_entities and the Profile plugin got any bright ideas for me? My only other option is a 'for each' loop and some very nasty hacky inline HTML which I am ashamed to even be considering.

Thanks in advance.

Ammie.

  • Do you want the user's link to always go to their list of blogs?

    Regardless, I think you want to register for elgg_register_entity_url_handler() for users. Something like:

    elgg_register_entity_url_handler('user', 'all', 'my_plugin_set_user_url');

    Your callback function will be passed the ElggUser object and you are expected to return the user's URL as a string.

  • Thanks Cash - that makes a lot of sense. I can see the same being used within the blog plugin so that makes it even easier - having a good quality practical example to work through and fully understand. I'll give that a bash and see how I get on!

  • I've had a play around with this now and inevitably have another question :-)

    Using elgg_register_entity_url_handler seems to over-ride the default url for the user in *all* places it is used (specifically in Members it now over-rides the url to the user profile), rather than just in the one I'm working on. Is that just how it works? Or have I missed something subtle?

    Thanks.

  • what about making elgg_register_entity_url context-aware?

     

    $context = elgg_get_context();

    elgg_set_context('my_custom_context');

    elgg_list_entities($options); // list members

    elgg_set_context($context);

     

    function my_custom_member_url_handler($member) {

      if (elgg_get_context() == 'my_custom_context') {

        return $blog_url;

      }

     

      return $profile_url;

    }

  • Matt. I love you.

    (in a not-creepy way, I promise).

     

  • This reminds me of a thought I had a while back when I was working with entity urls - anytime you declare a url handler for an entity type it replaces the previous handler.  So in a case like this where you just want to modify it in a specific case it can only happen in one plugin (well, I do have a workaround that can still work with the current API but it's not elegant).  I think this would be better suited as a plugin hook where multiple plugins could have a chance of returning the url.

     

    I've made logged it as an issue to see what the core team thinks:

    https://github.com/Elgg/Elgg/issues/5290

  • Women explain love declarations. Men explain handler declarations.

  • This can be done at least several ways, Depends on the *absence of techie lang in yr reqmts, That entity url trick is but one, of the elongated routes... Best solution depends on what that blogs linking shud *mean for opearationals...

  • DhrupDeScoop - blogs linking should work exactly as it does at the moment. I want an additional link to view an alternate view of blog content. I considered adding another menu item within the Profile, but I think the best option for the site owners is to keep the plugin as self-contained as possible. So I then get to wanting to use elgg_list_entities to output a list of users within my plugin (because I'm lazy and this works well), but not have the URL going to their Profile page as it would do elsewhere in the site. What Matt suggested works perfectly for my needs. Hope that explains it better.

  • And good morningzz
    If u write up all yr 'reqmts' by next week...
    I will look at coding that when I am back home out of hospital...