I have an entity and when I try to pass the whole entity object, only the name is passed through the routing.

Here is the relevant code in routing.yml:

  path: '/admin/config/mymodule/myentity/{myentity}/info'
    _content: '\Drupal\mymodule\Controller\MyModuleController::info'
    _title: 'Myentity Info'
      type: entity:myentity
    _entity_create_access: 'mymodule_myentity'

After clicking the link, I get this error: Trying to get property of non-object

I've added an issue regarding this to my sandbox project: https://www.drupal.org/node/2301021

  • Couldn't be as simple as type not being indented correctly under the parameters? – Clive Jul 10 '14 at 0:46
  • @Clive: Nope. It still throws he same error. I tried doing a print_r($myentity). It just displays the name of that entity I added in string. Is there any example which I could refer to maybe? – xan Jul 10 '14 at 0:51
  • @Clive` I'm disturbed that the YAML options: and parameters: keys doesn't appear anywhere in google search results, or like drupal.org/node/2192175 or a change record i can find :( – tenken Jul 10 '14 at 0:59
  • @Clive: Yes. I took that from drupal.org/node/2092643. Basically, I'm trying to output an entity's info. The info($myentity) function should take the argument as the Entity object, but all it does is take just the name. – xan Jul 10 '14 at 1:02
  • Maybe you need a custom parameter converter for your entity type? I can't look right now but search around the change records and the new routing docs for parameter upcasting. I'm not sure if you're automagically provided one – Clive Jul 10 '14 at 1:05

What you are looking for is now called upcasting, the handbook page is https://www.drupal.org/node/2122223

I do not think options is necessarily for entity upcasting. For example, check the node.type_edit in core/modules/node/node.routing.yml for a routing definition not using any options (or user.admin_permission in user).

As with your previous question, I wonder whether your entity class properly defines its storage controller? If you have a debugger, the parameter conversion happens in core/lib/Drupal/Core/ParamConverter/EntityConverter.php

  • I followed your advice, and still was unable to debug it. You could view the issue that I've added to my sandbox project. drupal.org/node/2301021 – xan Jul 11 '14 at 23:21
  • Seems like the function name info was posing problems, maybe having conflicts. Changing the function name resolved the issue. Thanks! – xan Jul 13 '14 at 15:45
  • Which function name have you changed...? This sounds curious. – user49 Jul 13 '14 at 16:32
  • You may view my commit: cgit.drupalcode.org/sandbox-prateeksachan-2275583/commit/… – xan Jul 13 '14 at 16:53

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.