I don't know why but I can't wrap my head around Drupal at all, and so I hope someone will be able to give me some assistance.

I am trying to create a block that will show documents. I have created a document content type, and it has a custom field called category. Category is a dropdown.

In this block, I want a dropdown, the same as the Document's. When a user selects an category it will show the documents pertaining to that category.

Currently I have a block called 'infocus' and I have created 'block-infocus.tpl.php' which is defined in 'block.tpl.php'. So far it seems to work if I input dummy information.

However, where do I go from here? I have searched through all the drupal code trying to figure out where to start and I keep going in circles. It feels like every function calls each other but there is never a starting point. Should I not bother trying to use Drupal functions, and just connect right to the database and take out data manually?

Any assistance would be great.

Thank you,

Sejr

Comments

diegogers’s picture

I would recommend using views with the views filterblock module
http://drupal.org/project/views_filterblock

Related Post
http://drupal.org/node/48843

leamas’s picture

I tried using the Views Filter Block but it didn't do exactly what I wanted.
Instead of showing the information in the same block that I submited from, it just goes to the Page View of the documents... And it just showed all the documents without filtering them.

I don't think that this is the type of thing I'm looking for.

nevets’s picture

Normally when making a custom block without a module you would place the PHP code as the block content. Any tpl.php file should be used for theming so I am not sure in what way block-infocus.tpl.php plays or the dummy information.

Also when you say you have a custom field called category, do you mean you have a taxonomy vocabulary associated with this content, if not how are you populating the dropdown?

Basically, how I would expect this to work, is you create a custom block (either in code or by adding a block from the admin interface). Either way I would build the dropdown using something similiar to way the dropdown is built for the content form. The difference is that dropdown would simply map some key to each category term and expect a callback to handle the submission. Without that your dropdown needs to map the category terms (the part the user sees) to a URL that displays the approriate information. The dropdown will require a little javascript to actually do something in this case.

leamas’s picture

When I was doing a little research, I noticed that if I put the following code within my block.tpl.php file:

	if ($block->module == 'block' && $block->delta == '4')
	{
		include 'block-infocus.tpl.php';
		return;
	}

I could then create the block-infocus.tpl.php file. The reason I like customizing my block this was is because if I were to modify it within the block and I made a syntax error, I would have to go into the database and disable the block so I could edit it again.

When I said category I didn't mean the taxonomy. I created a content type called Document, and within that, there is a field called category.

What I have done so far in my block-infocus.tpl.php file is this:

		$uid = arg(1);
		$result = db_query("SELECT global_settings FROM node_field WHERE field_name='field_topic_area'", $uid);
		
		$row = @mysql_fetch_array($result);
		$data = unserialize($row[0]);
		$allowed_values = $data['allowed_values'];
	
		$allowed_values = split("\r", $allowed_values);

		echo "<select id='infocus-doc'>\n";
		foreach ($allowed_values as $key => $val)
		{
			echo "<option value='$key'>$val</option>";			
		}		
		echo "</select>\n";
	

It seems to work so far, except I don't know how to get the documents from the selected dropdown.