This is my first time doing any custom module work in Drupal and need some advice. I have a django background.
I am accessing data on an external non-Drupal server to display on the Drupal site. I think I want to create a custom field type that holds the unique integer mapped to the data's ID on the external site.
1) user visits
/mymodule/1234
where1234
maps to the external data source (not the drupal node)
2) module performs a kind ofget_or_create
and either gets the node that matches the unique ID or creates one
3) the user will see get a node returned to them (can handle comments, statistics, etc) that also displays the external data (which I will query via REST)
I'm basically asking for advice if this approach is tenable in Drupal and how to implement the get_or_create part of this if it is.
what I can imagine so far
First, custom module and a url handler:
<?php
function mymodule_menu() {
$items['mymodule'] = array (
'testing' => 'I am just testing',
'page callback' => 'mymodule_view',
'access callback' => TRUE,
);
return $items;
}
Then a custom view function to do the heavy lifting when user visits /mymodule/1234
:
<?php
function mymodule_view($data_id = 0) {
// custom REST function to get the data via the $data_id
$data = get_my_data_cleverly($data_id);
if (!$data) {
//return 404
}
// not sure about this part
get_or_create_node($data_id);
// then return output to theme combining both node and $data
// this is an oversimplified render array output that doesn't
// work mostly because I don't understnand how Drupal does this yet
$output = array(
'node' => $node,
'data' +> $data,
);
return $output;
}
The result would be a node, with additional non-node information passed to the template.
Thanks