1

I have a content type "Company", each company will have a login page that show the logo of the company and a login form via Restful.

I have created a module that define a route:

company_md.login:
  path: '/{company_slug}/login'
  defaults:
    _controller: '\Drupal\company_md\Controller\DefaultController::login'
    _title: 'Company XX Login'

When I go to that URL it give me Not Found 404, whats wrong in my routing?

EDIT 1

This how the path look:

http://companies.local/node-13-company/login4

EDIT 2

My routing file:

testd8.name:
  path: '/node/{node1}/login'
  defaults:
    _controller: '\Drupal\testd8\Controller\DefaultController::login'
  requirements:
    _access: 'TRUE'
  options:
    parameters:
      node1:
        type: entity:node

enter image description here

  • The system name of your entity type has to be "company_slug", just FYI since you did not mention that. Also in your controller you have to have argument such as login(EntityInterface $company_slug) so DI will work properly. But as I am looking at the route I think the issue is in the missing requirements. Add something like requirements: access: 'TRUE' which grants access to the route. Then change it to something else once(entity access or permission). – user21641 Nov 30 '15 at 17:24
  • @IvanJaros Please check the edit section and see the full path. – Lhassan Baazzi Nov 30 '15 at 17:40
1

Do you have an entity type or a content type? If you create one in the UI, it's a content Type. Then it really is a node, so what you want to use is {node}. Then upcasting will work (assuming you have NodeInterface $node in your controller).

That said, access denied is, as Ivan Jaros said, the missing access definitions. The default access definition is that that access is denied. access: 'TRUE' will give anyone access.

What you likely want to use is _entity_access: node:view then the standard node access system is invoked and the user has access if he can view that node.

  • I'm near to get what I need, I don't know why don't recognize the content slug ? and why I need to put something whatever before the parameter route to work if I put /{node}/login don't work but /something/{node}/login work? Please check the second edit section :) – Lhassan Baazzi Dec 1 '15 at 0:48
  • Yeah, I think I put a restriction in the relevant function back in Drupal 6 that the first part must be a fixed thing. Good question whether it could be removed now. – user49 Dec 1 '15 at 22:42
  • Not sure about that @chx, but the answer for the question for now is simple: You can't. You can however for example use aliases if you really want the first part to be a number. – Berdir Dec 1 '15 at 22:47
  • @Berdir I want to put the slug not a node ID, I have asking another question here please follow this link: drupal.stackexchange.com/questions/182540/… – Lhassan Baazzi Dec 1 '15 at 22:56
  • @berdir "Not sure about that chx, but the answer for the question for now is simple: You can't" -- I know, as I mentioned I have added that restriction myself to D6 :) – user49 Dec 2 '15 at 0:00

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.