EPrints Technical Mailing List Archive

See the EPrints wiki for instructions on how to join this mailing list and related information.

Message: #05593


< Previous (by date) | Next (by date) > | < Previous (in thread) | Next (in thread) > | Messages - Most Recent First | Threads - Most Recent First

Re: [EP-tech] Replace an EPrints Function


Thanks John – for some reason on Friday I’d got it in my head that I needed some sort of superclassing wrapper based on the previous replacement mechanism, rather than child classing…

 

By now I must owe you several Guinness (or other beverage of choice) at OR2016!

 

 

 

From: eprints-tech-bounces@ecs.soton.ac.uk [mailto:eprints-tech-bounces@ecs.soton.ac.uk] On Behalf Of John Salter
Sent: 23 April 2016 07:46
To: eprints-tech@ecs.soton.ac.uk
Subject: Re: [EP-tech] Replace an EPrints Function

 

Hi Alan,

Take a look at these instructions: http://wiki.eprints.org/w/Instructions_for_local_plugins

As you're trying to do something in a plugin, it all works really well (like it was designed for this!).

 

One addition to the page would be that you could call the method you're overriding if you wanted to:
my $original_rendering = $self->SUPER::render( $things );

$original_rendering->appendChild( ... );

 

 - if you just want to append/prepend extra nodes to the original render.

 

Also, when I do this, I normally name the new package e.g. EPrints::Plugin::Screen::ArchiveIDItems rather than EPrints::Plugin::Screen::MyItems - makes it easier when you've got multiple archives running.

 

Cheers,

John

 


From: eprints-tech-bounces@ecs.soton.ac.uk <eprints-tech-bounces@ecs.soton.ac.uk> on behalf of Alan.Stiles <alan.stiles@open.ac.uk>
Sent: 22 April 2016 17:01
To: eprints-tech@ecs.soton.ac.uk
Subject: [EP-tech] Replace an EPrints Function

 

Hi All,

 

I’m trying to programmatically amend the EPrints::Plugin::Screen::Items screen.

 

We (one of my predecessors) have already replaced the render function with a local one using

 

undef &EPrints::Plugin::Screen::Items::render;

##Define new method and assign to exiting method

*EPrints::Plugin::Screen::Items::render = \&local_render;

 

So I could just amend the local_render to modify the doc_fragment as necessary whilst it gets built, but I’d like to do it in a more plugin-friendly way,  so, intercept the call to render as above, but then actually be able to call the original render function.

 

Thus far I’ve managed to send the (dev) server into several infinite loops – any suggestions for how to achieve it, or other suggestions gratefully received!

 

Cheers,

 

Alan

 

-- The Open University is incorporated by Royal Charter (RC 000391), an exempt charity in England & Wales and a charity registered in Scotland (SC 038302). The Open University is authorised and regulated by the Financial Conduct Authority.