2

In Drupal, we can get argument values using arg() function. drupal.org uses path alias. For example https://www.drupal.org/project/elysia_cron is actually https://www.drupal.org/node/274365, the node with ID equal to 274365.

How can I get the node ID of a project page from drupal.org?

  • Are you asking specifically how to get the nid of a page on drupal.org or how to get the nid of a page on a Drupal site that you are administrating or developing? – rrr45 Apr 8 '15 at 15:57
  • no I want to get the nid of "drupal.org" project pages. – user46121 Apr 8 '15 at 15:58
  • 1
    In the HTML for the page, the body tag of nodes are given a class of page-node-[nid]. You can find it that way. Is that what you're asking? – rrr45 Apr 8 '15 at 16:00
  • 1
    Also, I edited your title. Node IDs are not the same as unclean URLs. What you're looking for are node IDs. – rrr45 Apr 8 '15 at 16:04
  • How can I convert that URL programatically? and get the nid from it. – user46121 Apr 8 '15 at 16:59
2

As already mentioned in the comments, you could parse the HTML from the web page and extract the node ID from a class value.

But that's very messy, and it'll break if Drupal.org changes its markup for node pages.

A more robust approach would be to use the API, and consume the project's update feed. That feed contains the raw URL of the project node, from which you can get the ID.

I'll leave the PHP implementation to you, but the steps are as simple as:

I realise that method also relies on the XML not being changed, but I think that's less likely to change than the markup on the HTML version.

  • Thanks. This is exactly what I need. Can I know what is the use of Drupal.org API Component in simple words? It is mentioned in the last line of the API link you mentioned in your answer – user46121 Apr 8 '15 at 17:08
  • I haven't used it before I'm afraid – Clive Apr 8 '15 at 17:41
  • I think the release link URL actually redirects to the Project releases page. Not for the module page. for eg: nid for elysia is 274365 but the release link says its 1480688. – user46121 Apr 8 '15 at 17:43
0

You can use PHP Simple HTML DOM Parser

Following is a sample code I wrote that you can use in drupal/php

include_once 'simple_html_dom.php';
$html = file_get_html('https://www.drupal.org/project/elysia_cron');
$real_link = '';
foreach($html->find('link') as $element) {
    $real_link = $element->href;
    break;
}
echo $real_link;

This will give your the full link with node ID. Hope you can filter out the ID.

Your Answer

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