I have made a custom form to create nodes for a specific content type. Due to that, I want to throw a 403 or 404 on the admin page that creates new node. The route I mean is 'node/add/'.

I guess in my_module.routing.yml I have to add something like this:

    path: '/node/add/<CONTENT_TYPE>'
        _controller: 'Symfony\Component\HttpKernel\Exception\NotFoundHttpException'

But I'm not able to find the right controller. Any idea?


You can define a route where _access is set to FALSE, like this one from a test in core:

  path: '/system-test/always-denied'
    _title: 'Always denied'
    _controller: 'chop'
    _access: 'FALSE'

Although in this case an extra route shouldn't be necessary, because you can deny the permission to add a content type in UI.

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.