Very specific question about overwrittig a page

Thanks in advance for the help! Basically I am making a basic plugin, and I've figured out most of it. I ave located where the changes are going to go and everything. Getting down to my question, I need to replace the file views\default\input\file.php with the file mod\SpikeDisplayPage\pages\file.php.I get the basic logic of how to use elgg_register_plugin_hook_handler, but I have not been able to find a hook that leads me to the right page and trying to use ../../../mod/SpikeDisplayPage/pages/avatar/edit.php does not seem to work on the location thing. Please help, I'm basically done with this plugin. Here is the code I am usingSo my start.php on my plugin looks like

function spikeDisplay_init() {
    elgg_register_plugin_hook_handler('view', 'input/file', 'newForm'); //replace form withone that only gets images Works perfectly
    //elgg_register_plugin_hook_handler('output', 'avatar/edit', 'noCrop'); //do no use crop DOES NOT WORK
function noCrop() {
    if (!include_once(dirname(dirname(__FILE__)) . "/SpikeDisplayPage/pages/avatar/edit.php"))
        return false;
    return true;

function newForm() {
    if (!include_once(dirname(dirname(__FILE__)) . "/SpikeDisplayPage/pages/avatar/file.php")){
        return false;}
    return true;

// register for the init, system event when our plugin start.php is loaded
elgg_register_event_handler('init', 'system', 'spikeDisplay_init');

  • Overwriting a view: place your modified version of Elgg core's views/default/input/file.php into mod/SpikeDisplay/views/default/input/file.php and it should work without the need to use any plugin hook or other methods.

  • is there any way I can test this? it does not seem to be working for me. Is there a line of code I need to add somewhere? If there is a place on the documentation I can read up on this I woud be mega appreciative. Thanks a lot for  your time anyways!

    PS. Does this work with files on the pages directory?

  • Overwriting a view (files located below the view directory) works without adding any code anywhere. The overwriting is done only based on the plugin priority, i.e. a core view can be overwritten by any plugin and a plugin that is below another plugin can overwrite any view of the other plugin.

    If the overwriting fails to work for you: do you have the caching enabled on your site? If yes, flush the cache for the changes in views (including overwriting) to take effect. While coding it's best to keep the caching disabled to see the changes immediately.

    If it still does not work: could it be that another plugin is overwriting the same view because it's placed below your plugin?

    Overwriting only works with view files and not with pages. For changing pages you would need to unregister the original pagehandler and add your own. But in your case: does it not work to move the modified code from mod/SpikeDisplay/pages/file.php to mod/SpikeDisplay/views/default/input/file.php.

    For more informations about views (the concept, overwriting and extending):

  • ok, I got the view one to work now. But I still need to do the second one. I need to make it so that instead of uploading /elgg-1.8.15\pages\avatar\edit.php I need \elgg-1.8.15\mod\SpikeDisplayPage\pages\avatar\edit.php to be displayed. Can you give me a hand with this?


    Once again I REALLY appreciate the help!

  • Replacing a single page (from some other plugin) is a little trickier. There's a plugin hook called "route" that gets called for every (non-action) page. You'll want to register for that hook, analyze the segments of the URL and, if they match what you want, you call your function to echo a page and return true.

    I highly recomment setting up an xdebug environment where you can walk through requests, set breakpoints, see values at each step, etc.

  • What exactly do you want to change in pages/avatar/edit.php?

    This page is built up with two views:


    and in case an avatar image has been uploaded also


    The noCrop() function in your initial posting makes me believe that you might want to prevent image cropping. This might work without changing the pages/avatar/edit.php. You can not only overwrite a view by adding a view file with code in your own plugin. If the view file (same name for the view file in the corresponding place within the views directory of your plugin) is present but is only an empty file (more precisely not creating any output) the original view gets overwritten nonetheless. So, if you create a placeholder file mod/SpikeDisplay/views/default/views/default/core/avatar/crop.php it could already solve your issue.

    Or it might work by "extending" the views/default/core/avatar/upload and/or views/default/core/avatar/crop views to add some options to the avatar edit page. I've extended this page by extending the upload view for example in my Identicon plugin ( In this case the line elgg_extend_view('core/avatar/upload', 'identicon/editusericon'); in start.php extends the upload view with the editusericon view.

  • yes, I am just removing the crop functionality,I have not tried the dummy functionality or extentions, so I'll be trying this now, thanks a lot for all your help!

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