Blog library override


I'm using elgg 2.3.14 and looking for some advice on how to change the behavior of the bundled blog plugin.  What I'm trying to do:

  1. When loading the blog view, for each blog entry I need to make a rest call to a webservice.
  2. Process the response of the rest call and check the values of the vars 'validated' and 'address'
  3. If 'validate' is TRUE then update the css of a blog menu icon to change the color to green and change the href address to 'address'
  4. If 'validate' is FALSE then update the css of a blog menu icon to change the color to red and remove the href address tag.
  5. Load the view.

When looking at the core code for blogs I saw that in the /mod/blog/lib/blog.php that there is a function blog_get_page_content_list that I wanted to override to add in my code to call my rest endpoint and process the data as explained above.  Is it true that overriding can't be done on a core library? And if so, I'm working on an figuring out an alternate solution.



  • Override views which calls this function:


    You can use this hook also:

    $options = [
        'type' => 'object',
        'subtype' => 'blog',
        'distinct' => false,
        'no_results' => elgg_echo('blog:none'),
    $viewer = function ($entities, $options) {
        return theme_elgg_view_entity_list($entities, $options);
    echo elgg_list_entities($options, 'elgg_get_entities', $viewer);
    Where theme_elgg_view_entity_list is your custom function to view entities, e.g.:
    function theme_elgg_view_entity_list($entities, array $vars = array()) {
        $offset = (int)get_input('offset', 0);
        // list type can be passed as request parameter
        $list_type = get_input('list_type', 'custom_type');
        $defaults = [
           'items' => $entities,
           'list_class' => 'custom_class',
           'full_view' => true,
           'pagination' => true,
           'list_type' => 'custom_type',
           'list_type_toggle' => false,
           'offset' => $offset,
           'limit' => null,
       $vars = array_merge($defaults, $vars);
       if (!$vars["limit"] && !$vars["offset"]) {
         // no need for pagination if listing is unlimited
         $vars["pagination"] = false;
       return elgg_view('page/components/custom_view', $vars);

    Or add any callback which you want to use.

  • Thanks RvR... I think we posted at the same time.  I had figured after playing around with the code last night that I could override the views to accomplish what I needed to do but I will look at your solution to guide me through some of the parts I haven't figured out yet.