3

In a preprocess function I want to access the destination node id via the URL object

I cannot find any method that will return the node id for me but I can clearly see that it holds the node id. (see attached)

enter image description here

Any idea how I can get the node id without going the long way of generating it from the URL path?

1
  • 1
    $your_url_object->getRouteParameters() should do it I think from memory Commented Nov 10, 2020 at 9:48

1 Answer 1

3

Looks like you're using the latest Devel, 4.0.1, which sadly currently doesn't show the available methods tab unless you patch it.

If you had the available methods tab, you would've seen that you can retrieve using the public method getRouteParameters

$nid = $url_object->getRouteParameters()['node']; 
2
  • 1
    hey thanks, that worked although just ['node'] at the end did the job just fine, Commented Nov 10, 2020 at 9:58
  • Also thanks for the patch, do you know why this has been removed in the newest version? It is pretty handy. Commented Nov 10, 2020 at 11:31

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.