Hello

I am quite new to module development although I have experience in modifying existing 6.x block modules developed by others. I have a need to develop a 7.x module and in spite of a lot of documentation reading seem to be missing a basic starting point. I have been looking at the documentation on drupal.org and other third party sites but through my own fault seem to be missing a basic concept.

The site I am working on has a content type called project. At present there are many project pages busing this content type. One of the field types is a User Reference field, called key_contact.

The idea is that I need to create a block that gets the key_contact's username (stored as an id number in the key_contact field) and then from that number perform an SQL query, on another table, to get the id's details and then display them in a block.

At present I have a View that can return the id and I have been asked to replace this view with a module that does the entire job.

Once I get the id for the key_contact I will have no trouble with the SQL query and formatting the output how I want it. I am familiar with creating a block module.

Where I am stuck is understanding how to get the key_contact value from the content type project page when it is loaded.

I would appreciate it if I could either be shown documentation or an example, or even an explanation, that will show me how to extract a field value from a content type like this.

I appreciate any help.

Regards

Richard

Comments

benmalen’s picture

I can't directly help with your question, but you could try using Features http://drupal.org/project/features to export what you want into a module. Maybe this could give you a stepping stone.

rickl_unsw’s picture

Thanks for the reply

I had already looked at features and it does not seem to be what I want. It appears to let me export the view I already have as a module in much the same way as the Bulk Exporter. The module it produces is still dependent upon the views API.

I do not want to use views as I can see no way to take the id returned by the view and push it into the custom SQL query and new resultant block. The view is already returning a block with the id before I get the chance to add the SQL query

Regards

Richard

fndtn357’s picture

"Returns a renderable array for the value of a single field in an entity. The resulting output is a fully themed field with label and multiple values. This function can be used by third-party modules that need to output an isolated field."

Another thought, since you have already created a View, I imagine a Page, and can't you within the same View create a Block grabbing only the content you want based on the User Reference value from the View? When you convert this View won't the Block also be converted?

PawelR’s picture

Hi, if you need to access any data of the current node you can call node_load() function within your block code:

$path = explode('/', $_GET['q']);
$node = node_load($path[1]);

Then you can access all properties of current node object. (like echo $node->key_contact;)
Calling this function for the node which is currently displayed (was just loaded) isn't time expensive because once loaded node stays in memory as static variable.

stemount’s picture

The best way to do this is use Drupal arg()

$node = node_load(arg(1));

didlix’s picture

tsk, do some checks stemount!

<?php if (arg(0) == 'node' && is_numeric(arg(1))) { $node_id = arg(1); }