I am trying to build a module that checks if user session set in all pages of a certain book. if the session is not set it will be set. I am using a sso system so the user data will come from there, The users will not be Drupal registered users.

Now, I built a function in the controller that sets the session in a certain path and it work good.

My question is how do I turn the path value in the module routing file, so the function in the controller will work in all the specific book pages.

This is the routing file content:

  path: '/ssocheck'
    _controller: '\Drupal\achva_sso\Controller\SsoController::ssoCheck'
    _title: 'SSO Set ssocheck'
    _permission: 'access content'

This is the controller function:

class SsoController extends ControllerBase
    public function ssoCheck()
        $session = \Drupal::request()->getSession();

        if ($session->get('name') !== null) {
            $status = 'check is already logged in ' . $session->get('name');
        } else {
            $status = 'was logged out' . $session->get('name');
        return [
            '#type' => 'markup',
            '#markup' => '<p>' . $status . '</p>',
  • What are the book pages? Existing ones from core/contrib or your own? – 4k4 Nov 18 '18 at 10:45
  • The book pages will be pages that I will create by myself, from various content types. those pages outline will be assigned to the book as siblings, all pages url will be /bookname/ *or` /bookname/*/*` – DavSev Nov 18 '18 at 10:55
  • Use curly braces for the wildcards, see drupal.org/docs/8/api/routing-system/structure-of-routes – 4k4 Nov 18 '18 at 11:02
  • Thank you, it works great in every in every URL that is /bookname/* except in existing pages. I have an existing page called son the URL of the page is /bookname/son The I don't see the ssoCheck function return. If I write /bookname/sadasd or other page that doesn't exists I will see the function output. What can be the reason for that behavior? This is how the path in the routing looks now: path: '/bookname/{node}' – DavSev Nov 18 '18 at 11:28
  • This is why I asked in the first comment. For existing pages you have to alter the existing route to reroute to your own controller, which then could extend the original controller so that you don't need to repeat the existing code. – 4k4 Nov 18 '18 at 12:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.