[Archivesspace_Users_Group] Overriding/Extending the new public interface in 2.2.0
Fox, Bobbi
bobbi_fox at harvard.edu
Tue Jan 30 09:24:26 EST 2018
Steve and Tim,
Thank you for your clear explanations. As it happens, as a member of the TAC, I’m working on improving the plugins documentation; be sure I’ll be incorporating this!
Cheers,
Bobbi
From: archivesspace_users_group-bounces at lyralists.lyrasis.org [mailto:archivesspace_users_group-bounces at lyralists.lyrasis.org] On Behalf Of Timothy Dilauro
Sent: Monday, January 29, 2018 11:51 PM
To: Archivesspace Users Group <archivesspace_users_group at lyralists.lyrasis.org>
Subject: Re: [Archivesspace_Users_Group] Overriding/Extending the new public interface in 2.2.0
You can control the timing of the loading of your extensions by placing them in an "config.after_initialize" block in plugin_init.rb. For the 1.5.4 PUI, I used the following block:
ArchivesSpacePublic::Application.config.after_initialize do
end
In addition, you can ensure that each needed module/class is loaded by mentioning it before you attempt to extend it:
RecordsController
class RecordsController
...
end
See https://github.com/jhu-archives-and-manuscripts/aspace_plugin-jhu_public/blob/master/public/plugin_init.rb
Cheers,
~Tim
On Jan 29, 2018, at 11:25 PM, Majewski, Steven Dennis (sdm7g) <sdm7g at virginia.edu<mailto:sdm7g at virginia.edu>> wrote:
I had a need to look into this issue of overriding existing routes or controllers again.
I was trying to make repositories#index be the default landing page instead of welcome#show .
Adding this to plugins/local/public/routes.rb and loading those routes from plugin_init.rb appended the new route to the end of the routes. This was visible when I ran ‘rake routes’ on the public rails app. However routing takes the first match from the route table, so the default ‘welcome at show’ was what was run.
I haven’t yet figured out if there is any way to add a new route to the start of the routes table rather than at the end.
I unsuccessfully tried several different methods of overriding welcome#show.
During that process, I also stuck in a binding.pry breakpoint in plugins/local/public/plugin_init.rb and verified that ApplicationController is not in scope. In fact, I suspect that since it is being loaded as an initializer, the controllers may not have been loaded and defined at that point.
What finally worked for me was:
plugins/local/public/controllers/my_controller.rb:
class WelcomeController
def show
redirect_to :controller => 'repositories' , :action => 'index'
end
end
This did successfully override welcome#show so that going to http://localhost:3001/ redirects to http://localhost:3001/repositories and show the list of repositories.
( In this case, I’ve also overridden views/repositories/index.html.erb in the the plugin so that it also includes the search form above the repository list. )
What I don’t completely understand is that if the same file is named plugins/local/public/controllers/welcome_controller.rb, it does not seem to work. Other arbitrary names, like “x_controller.rb” for example, do work. Just not “welcome_controller.rb” . It would appear that the existing application welcome controller may keep this file from loading. I just added a binding.pry breakpoint and renamed that file and verified that it never executes when named “welcome_controller.rb” .
So you might try something similar. Routes or plugin_init are probably not required if you’re just extending existing controller.
Add a file to the plugin controller directory that redefines resource controller, but give it a name that doesn’t duplicate any existing controller file.
If you try to inherit from and extend an existing controller, you may be able to add a new route pointing to it, but I don’t know a way to change the existing route to point to a the new class.
Let us know if you find something that works!
— Steve Majewski
On Dec 22, 2017, at 3:07 PM, Flanagan, Patrick <PJFlanagan at ship.edu<mailto:PJFlanagan at ship.edu>> wrote:
I think I just encountered that sort of issue. From public/plugin_init.rb both ResourcesController and ApplicationController don't appear to be in scope; so I can't even replace it let alone extend it. That, or I'm supposed to use require to get at the specific classes - but I haven't been able to do so. I think it's one of the intricacies of Rails that is escaping me.
Ideally, for an identifier of A/B/C/D on a given resource, I wanted the breadcrumb to link back to A - B - C - D - This Resource, a behavior that's more similar to Archon, and more useful than the default behavior of simply linking to the repository top itself, I think.
~Patrick Flanagan
KLN Applications Administrator
Keystone Library Network Hub
________________________________
From: archivesspace_users_group-bounces at lyralists.lyrasis.org<mailto:archivesspace_users_group-bounces at lyralists.lyrasis.org> <archivesspace_users_group-bounces at lyralists.lyrasis.org<mailto:archivesspace_users_group-bounces at lyralists.lyrasis.org>> on behalf of Majewski, Steven Dennis (sdm7g) <sdm7g at virginia.edu<mailto:sdm7g at virginia.edu>>
Sent: Thursday, December 21, 2017 4:40:29 PM
To: Archivesspace Users Group
Subject: Re: [Archivesspace_Users_Group] Overriding/Extending the new public interface in 2.2.0
I remember running into something like this where the problem was Rails lazy loading of classes.
The base classes were not actually defined when the plugins were loaded, so what was supposed to be additional methods extending an existing class became the entire replacement class definition. I had to add a reference to the class to force lazy loading before trying to extend the class.
This might be what you are running into.
I will look and see if I still have any notes with more details from that experiment.
— Steve.
On Dec 21, 2017, at 4:18 PM, Flanagan, Patrick <PJFlanagan at ship.edu<mailto:PJFlanagan at ship.edu>> wrote:
Hi Bobbi,
Thank you for this! I'll give it a try this way and see if I can make some progress.
~Patrick Flanagan
KLN Applications Administrator
Keystone Library Network Hub
________________________________
From: archivesspace_users_group-bounces at lyralists.lyrasis.org<mailto:archivesspace_users_group-bounces at lyralists.lyrasis.org> <archivesspace_users_group-bounces at lyralists.lyrasis.org<mailto:archivesspace_users_group-bounces at lyralists.lyrasis.org>> on behalf of Fox, Bobbi <bobbi_fox at harvard.edu<mailto:bobbi_fox at harvard.edu>>
Sent: Thursday, December 21, 2017 3:47:18 PM
To: Archivesspace Users Group
Subject: Re: [Archivesspace_Users_Group] Overriding/Extending the new public interface in 2.2.0
Hi, Patrick,
I’m having to do a lot of extending/overriding of controllers & methods in our new public interface.
You are correct; you can’t just override by placing your modified controller in the path location; instead, what *I’m* doing (and I know there’s a more elegant way of doing it); is put the changes in the plugin/plugin_init.rb ,using the [class|module]_eval method on something.
For instance, I’m changing what gets faceted in the Searchable concern this way in plugin_init.rb:
Searchable.module_eval do
def set_up_and_run_search(default_types = [],default_facets=[],default_search_opts={}, params={})
~ my stuff here ~~
end
end
I’m adding methods to controllers in a somewhat similar way, for instance, in plugin_init.rb, I’ve got:
# add a digital only action to the resources controller
class ResourcesController
def digital_only
uri = "/repositories/#{params[:rid]}/resources/#{params[:id]}"
begin
~ etc. ~
end
end
Hope this helps,
Bobbi
From: archivesspace_users_group-bounces at lyralists.lyrasis.org<mailto:archivesspace_users_group-bounces at lyralists.lyrasis.org> [mailto:archivesspace_users_group-bounces at lyralists.lyrasis.org] On Behalf Of Flanagan, Patrick
Sent: Thursday, December 21, 2017 3:27 PM
To: Archivesspace Users Group <archivesspace_users_group at lyralists.lyrasis.org<mailto:archivesspace_users_group at lyralists.lyrasis.org>>
Subject: [Archivesspace_Users_Group] Overriding/Extending the new public interface in 2.2.0
Hello,
I'm attempting to write a plugin that will modify the way the breadcrumb trail (shown in the new public UI) is generated to include more detail. I decided to try and override one of the files in the controller part of the architecture: resources_controller.rb, since I can see the :crumb being defined there. However, either my path is wrong, or the new UI isn't utilizing it. Following the instructions here:http://archivesspace.github.io/archivesspace/user/archivesspace-plug-ins-readme/<https://urldefense.proofpoint.com/v2/url?u=http-3A__archivesspace.github.io_archivesspace_user_archivesspace-2Dplug-2Dins-2Dreadme_&d=DwMFAw&c=WO-RGvefibhHBZq3fL85hQ&r=5xWUzLrZrVLeTqs3CDoeRpPtLv1fRM04CCu4TDULrSY&m=3DmZ4KyjSuOHTC-7rfq8Dv2MTeEFEBci91sKzca-4YQ&s=is5OAKKChee55MtdTuQYDj2OwuvI8f0Y6lBLS8-ast8&e=> I've placed the file in the following directory:
as220/plugins/local/public/controllers/resources_controller.rb
( source location: /public/app/controllers/resources_controller.rb )
Plugin Config: AppConfig[:plugins] = ['local', 'lcnaf', 'aspace-public-formats']
If I'm not mistaken that document indicates that this is something that can be overridden, but I'm suspecting I can't actually override something in the controller from a plugin.
The version is 2.2.0, running on Linux x64, openjdk version "1.8.0_151". Any advice would be appreciated!
Thank you,
~Patrick Flanagan
KLN Applications Administrator
Keystone Library Network Hub
_______________________________________________
Archivesspace_Users_Group mailing list
Archivesspace_Users_Group at lyralists.lyrasis.org<mailto:Archivesspace_Users_Group at lyralists.lyrasis.org>
http://lyralists.lyrasis.org/mailman/listinfo/archivesspace_users_group
_______________________________________________
Archivesspace_Users_Group mailing list
Archivesspace_Users_Group at lyralists.lyrasis.org<mailto:Archivesspace_Users_Group at lyralists.lyrasis.org>
http://lyralists.lyrasis.org/mailman/listinfo/archivesspace_users_group
_______________________________________________
Archivesspace_Users_Group mailing list
Archivesspace_Users_Group at lyralists.lyrasis.org<mailto:Archivesspace_Users_Group at lyralists.lyrasis.org>
http://lyralists.lyrasis.org/mailman/listinfo/archivesspace_users_group
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lyralists.lyrasis.org/pipermail/archivesspace_users_group/attachments/20180130/66515013/attachment.html>
More information about the Archivesspace_Users_Group
mailing list