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?

0

2 Answers 2

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.

3
  • 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
    Commented Apr 8, 2015 at 17:08
  • I haven't used it before I'm afraid
    – Clive
    Commented Apr 8, 2015 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
    Commented Apr 8, 2015 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 and acknowledge you have read our privacy policy.