0

I'm using D8 and I have a panel page which has as parameter in the URL the uid (mysite/uid). In this page, are loaded different nodes and forms. What I want to do is to eliminate the access only to this user and the admin. It is not a node of a content type so as I can use the existing permissions (edit your own page).

Any idea how to implement this?

I was thinking to use something, maybe hook(?), triggered every time the user tries to access that page and doing some checks like the url and the uid and if the user is not admin or doesn't have the correct uid, throw an AccessDeniedHttpException();

1

I don't understand what you want to do specific to the panels page. In general you are looking for some kind of hook triggered every time a user visits a page. In D8 every page is connected to a route. You have to implement an access check on this route, see the documentation Access checking on routes. You can define the access check when you create a route or if you have an existing route from another module you can alter the route definition, see for this the next chapter in the documentation Altering existing routes

  • Thanks. I have panels pages where I display multiple node edit forms for each user. What I wanna do is to eliminate the access to each page based on uid and role. I will give a try to this one. My problem is that the path of those pages is eg /my-application/uid. Should I create a routing file like this example: path: '/my-application/{{uid}}' requirements: _custom_access: '\Drupal\example\Controller\ExampleController::access' – Ismini Jul 7 '17 at 12:51
  • The route probably exists. You can check this by installing Devel and list the routes /devel/routes. When you've found it, click on the button on the right and look, how the access is configured. Then use a RouteSubscriber as explained in the second link to add your custom access check to this route. – 4k4 Jul 7 '17 at 13:01
  • Thank you @4k4. I'm trying to make it work but doesn't seem to do anything. In my alterRoutes I'm trying to do something like if ($route = $collection->get(' /my-completion/{webform_submission}')) { $route->setRequirement('_access', 'FALSE'); } but it doesn't do anything. Any idea? – Ismini Aug 16 '17 at 13:20
  • The access is configured like this : [_page_access] => page_manager_page.view and I followed the second link but doesn't change the page access. – Ismini Aug 16 '17 at 14:30
0

add a variant, not panel variant, make it with a http response, do a permanent 301 redirect to whatever you want, in conditions set user role, user id, and/or some url, it's simple, straight and easy. no code is needed.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.