Extending existing controller action

Hi!

I’m looking for a way to extend and modify an existing controller action, e.g. Omeka\Controller\Site\IndexController::actionIndex., in order to redirect to a login page depending on user authorizations.

I’ve got little experience developing modules on Zend based applications, mainly with XenForo that is quite different, but it used to require to extend the class and action, and call ::parent() within the code to avoid breaking core feature.

Is this feasible within Omeka-S? Or is this the wrong approach?

Thanks in advance for any clues or documentation links that could be of interest here.

Laurent

My first thought is that this sounds like more of an ACL concern, which a module might be able to handle without resorting to overriding controllers. Controllers are pretty well built-in to the was Omeka uses Zend structures and URL building, so at first glance I’d look toward giving more nuanced access based on ACL. The Group module might give some ideas, though I haven’t spent a lot of time with it.

1 Like

Hi patrickmj and thanks for the heads-up.

First, I’ve managed to extend an existing controller and its actions.
I had to overwrite some statements from module.config.php by replacing the original Omeka namespace with mine.
E.g.:

<?php
return [

        ...

    'router' => [ 'routes' => [ 'site' => [
        'defaults' => [
                '__NAMESPACE__' => 'RestrictedSites\Controller\Site',
              ] 
     ] ] ] ]
 ];

I then only had to implement my new IndexController class

<?php
namespace RestrictedSites\Controller\Site;

class IndexController extends \Omeka\Controller\Site\IndexController
{
    public function indexAction()
    {
        // Place additionnal code here

        return \Omeka\Controller\Site\IndexController::indexAction();
    }
}

I did not look further, because you are right and Acl should do the trick, but I guess this information could eventually be useful to someone.

So, now I’ve started to look into Acl and managed to deny access to all non admin users using this part of code in my Module.php:

    public function onBootstrap (MvcEvent $event)
    {
        parent::onBootstrap($event);
        
        /** @var Acl $acl */
        $acl = $this->getServiceLocator()->get('Omeka\Acl');
        $acl->deny(null, [
                'Omeka\Controller\Site\Page'
        ]);
    }

I’ll try to get more specific and look into what are the options to have a redirect instead of an error page showing when users are denied access to resources.

Have a nice day!

Laurent