Search code examples
phpelgg

How to override a user profile view,, in our own plugin, in elgg


I have created a new plugin named 'adv' in my elgg site.

And in this plugin iam listing the users.Which using the view from other elgg plugin 'profile

ie the page profile/views/default/profile/listing.php.

Now i need to set a link in the existing view of each user.So i have to edit the profile plugin , mainly the page profile/views/default/profile/listing.php

But how can i do this, without modifying elggs default plugin 'profile'.

I have tried a method that i have copied the folder 'profile' from profile/views/default/profile and put it in adv/views/default/.But it donot working.]

Is any solution for adding new link to the user view with editing other plugin, only editing our own plugin example 'adv'.


Solution

  • You'll need to override the profile/listing view, but only when Elgg is rendering your plugin's pages, not to interfere with other plugins that might want to use the core profile/listing view.

    My approach to this problem is the following:

    1. Create a new directory that will hold the views that you want to override. In your case, I'd create the "adv/views/mod" directory within your_site_root/mod.

    2. Add the view you'd like to override into this directory. Again, your case, copy the profile/views/default/profile/listing.php to the following location: adv/views/mod/default/profile/listing.php

    3. Make your modifications to the newly created view. You can now safely modify the adv/views/mod/default/profile/listing.php file to your liking

    4. Tell Elgg to use the special view when your plugin is rendering the page. This means you'll have to call the set_view_location(..) method either from your page_handler function, or the php files that are referenced by your page_handler and usually prepare the data for the views (like index.php or read.php, but I don't know your plugin's file hierarchy) So in your case you'd call set_view_location('profile/listing', $CONFIG->pluginspath . 'adv/views/mod/'); either from your page_handler or from one of the above files. Make sure that $CONFIG is present and available by referencing it (global $CONFIG).