Info for tweaks to "Front Page Demo" (`custom_index`) plugin

I would like to modify the `content.php` file in the Front Page Demo plugin to use as a landing page for our "Walled Garden" instance of Elgg (2.3.8, freshly installed).

What I want to display for logged-in users is:

  • (left column) "Greet",
  • and "My Groups"; and
  • (in right column) "SITE Bookmarks" (not from any groups).

I've looked at `content.php`, searched on "custom[s|z]ing landing page", read the information in the stable docs that seemed relevant ... and I'm a bit overwhelmed! At the moment, it feels a bit like "needle in haystack" for me. I worked for some years with an open source CMS, and am somewhat comfortable with OO PHP but I'm not sure which way to turn with Elgg at the moment.

If someone could give me a pointer in the docs, or whatever, to my goal (bullet list, above), that would be wonderful.

  • Take a look at the view mod/custom_index/views/default/resources/index.php. That's one of two views that create the landing page for logged-in users when the custom_index (Front Page Demo) plugin is used. The other is mod/custom_index/views/default/custom_index/content.php that gets called from within the index.php view. Simply said, index.php deals with fetching the data and content.php deals with the layout.

    If you want to modify the landing page you would "override" these two views in your customization plugin by creating copies of these two views at

    mod/my_plugin/views/default/resources/index.php

    mod/my_plugin/views/default/custom_index/content.php

    If you add no other functionality to this plugin you would only need a mod/my_plugin/start.php (with only a <?php in the first line) and a mod/my_plugin/manifest.xml (copy and adjust it from another plugin).

    For customizing what is displayed in the widgets you would have to modify your index.php view, i.e. to get "My groups" (groups of the logged-in user) and "Bookmarks not from groups" you would have to alter the corresponding elgg_list_entities queries. Unfortunately, it's a bit too late for me today to come up with the necessary query code. For the groups of the user the Groups plugin most likely has the code somewhere as such a lists page already exists. The bookmarks that are not in groups is a bit more complicated and I don't think there's already some existing code for this specific clause. It would be necessary to work with the joins and wheres attributes for the query here.

  • Thanks so much, @iionly -- I got there! Well, enough of the way there for my needs. :)

    My first goal ("My Groups" in left column) was a surprisingly easy tweak: it just modding line 39 of the 2.3.8 custom_index plugin, changing 

    elgg_echo("custom:groups")

    to

    elgg_echo("groups:yours")

    It works. :)

    As for my second goal, I decided simply to go "old school" and hand-coded a "widget" to include my few "quick links" that I want users to see on the landing page. Obviously that can become more sophisticated in future as our use of Elgg and knowledge of its workings grows. My custom plugin even has a dependency in the `manifest.xml` to the "custom_index" pluging. All good!

    Again, I'm grateful for your guidance, iionly! Couldn't have got this far without your helpful intervention.

  • Changing the elgg_echo line would only change the widget title but not the content. The groups widget would still display the newest 4 groups of your site regardless if the user is a member of these groups or not.

    For changing the groups to "my groups" (i.e. the user is member of the groups) and to display bookmarks NOT made in a group you would have to make changes in index.php line 28 and 49:

    $dbprefix = elgg_get_config('dbprefix');
    
    $bookmarks = elgg_list_entities([
        'type' => 'object',
        'subtype' = 'bookmarks',
        'limit' => 4,
        'full_view' => false,
        'list_type_toggle' => false,
        'pagination' => false,
        'joins' => ["JOIN {$dbprefix}entities ue ON e.container_guid = ue.guid"],
        'wheres' => ["ue.type = 'user'"],
    ]);
    
    $groups = elgg_list_entities_from_relationship([
        'type' => 'group',
        'relationship' => 'member',
        'relationship_guid' => elgg_get_logged_in_user_guid(),
        'inverse_relationship' => false,
        'limit' => 4,
        'full_view' => false,
        'list_type_toggle' => false,
        'pagination' => false,
        'joins' => ["JOIN {$dbprefix}groups_entity ge ON e.guid = ge.guid"],
        'order_by' => 'ge.name ASC',
    ]);

    You need to add the $dbprefix line once before you make use of the variable within the two queries. I hope the code works... haven't tested.

  • Thanks (again!) @iionly. About this:

    Changing the elgg_echo line would only change the widget title but not the content. The groups widget would still display the newest 4 groups of your site regardless if the user is a member of these groups or not.

    I see now why I thought my simple change was working: I had the groups in my test install configured to be visible to group members only, so when I signed in as a user not in certain groups, and their "landing" page displayed the correct groups, I thought I was there. Of course, this was simply a function of the group settings, not the correct code for the `custom_index` tweak!

    I'll try your code supplied above (for which, thank you), and let you know how I get on.

  • @iionly - your code works beautifully. Thank you!

    I've used the "groups" code right away (and means I can set up the site slighly differently, and better, I think.)

    I have seen that the "bookmarks" code also works, but until I can work out how to produce the [link text + url] only from the Bookmarks object, I'll continue to use my hand-coded pseudo-widget.

    I've spent a few hours (really!) trying to work out how to get just the [link text + url] out of the bookmarks to build a simple anchor/link, but so far I've failed. But I'm learning things all the time. :)

  • elgg_list_entities() returns the result already as ready-to-use html code. It makes use of views/default/object/default.php as a generic fallback of how to format the list or (if available) a entity-specific object view (as in case of bookmarks views/default/object/bookmarks.php from the bookmarks plugin).

    If you want a different formatting to be used one possibility is to make use of the 'item_view' attribute of elgg_list_entities. This allows to provide a different view to be used to format the list items:

    $bookmarks = elgg_list_entities([
        'type' => 'object',
        'subtype' = 'bookmarks',
        'limit' => 4,
        'full_view' => false,
        'list_type_toggle' => false,
        'pagination' => false,
        'joins' => ["JOIN {$dbprefix}entities ue ON e.container_guid = ue.guid"],
        'wheres' => ["ue.type = 'user'"],
        'item_view' => 'myplugin/list/bookmarks'
    ]);

    The list formatting would be defined in mod/my_plugin/views/default/myplugin/list/bookmarks.php:

    <?php
    
    /* @var $entity ElggUser */
    $entity = elgg_extract('entity', $vars);
    
    // Now you can define what to output for one single list item_view
    // using the $entity variable

    The "old" way ('item_view' is quite new in Elgg) was to use elgg_get_entities() instead of elgg_list_entities(). Then you have the result without formatting as entity object array. Then you would use a foreach loop to go through the results and create the html output.

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