Any way to list all contexts in a system?

I'm writing a plugin to provide context-sensitive help based on Elgg context. It would be greatly improved if I were able to find all of the contexts that might exist on a server, ideally as an array. Does anyone know whether there is a way to do that, simple or otherwise?

  • that would help me too.. i do not currently know that such a list is stored in elgg - it really should be.

    one method to building the array would be to add plugin hook handlers that trigger a function that maintains a list in the database of each unique context.. e.g.

           elgg_register_plugin_hook_handler("route", $context, "contexts_hook");
           elgg_register_plugin_hook_handler("view", $context, "contexts_hook");

    the contexts_hook function would do whatever is needed to build the list, such as write to a database table or to a logfile..

    maybe there is an easier way this can be done just using a global variable such as $CONFIG... i haven't used elgg in that way so i don't have direct experience to comment.

  • @Jon - have you seen this plugin? http://community.elgg.org/plugins/1496306/1.5/user-support
    I'm using it on a couple of projects and it's fantastic


    If that's not helpful enough and you still need contexts, I don't think there's a programmatic way to get them *all* as they can be set with an arbitrary string and aren't persisted beyond the current pageload, but you can get the majority of them by looking at registered page handlers.  By default, unless a context is explicitly set it's equivalent to the pagehandler.

    So after all plugins are loaded you can get an array of pagehandlers with something like this:

    array_keys(elgg_get_config('pagehandler'));

    This might not get *every* little custom context, but will get you the bulk of them.

  • That's brilliant, thanks both!

    I'd seen the user-support plugin in its former FAQ guise - this looks much better, thanks for that. The context-sensitive stuff is still useful and relevant though: I'm using it to add a spotlight footer that can be customized, so it remains useful even if there are better help options.

  • another way would be to search the code for elgg and all the plugins for elgg_set_context
    theoretically you 'should' find all of them that way.. maybe.. ;)