Hopefully I'll get to the point where I better understand these errors:


* warning: array_reverse() [function.array-reverse]: The argument should be an array in /home/estevan/public_html/drupal/includes/theme.inc on line 710.
* warning: Invalid argument supplied for foreach() in /home/estevan/public_html/drupal/includes/theme.inc on line 712.

I only receive this when I use this bit of code as a preprocess:

	// Step 1
	if (module_exists ('path')) {

		// Step 2
		$path_alias = drupal_get_path_alias($_GET['q']);

		// Step 3
		$alias_parts = explode('/', $path_alias);

		// Step 4
		$last = array_reverse($alias_parts);
		$last_part = $last[0];
		if ($last_part != "edit") {

		// Step 5
		$templates = array();
		$template_name = "page";

		// Step 6
			if (arg(0) == "node" && is_numeric(arg(1))) {
				$node_type = $vars['node']->type;
				$vars['template_files'] = "$template_name-node-$node_type.tpl.php";
			}

		} // End edit check
	} // End check path module

It's code from the Front End Drupal book of which I'm still going through. Thanks for your help.

Comments

nevets’s picture

Most likely line is $last = array_reverse($alias_parts); because $alias_parts is not an array.

You can simplify the code to

if (arg(0) == 'node' && is_numeric(arg(1)) && arg(2) != 'edit' ) {
$node_type = $vars['node']->type;
$vars['template_files'] = "page-node-$node_type.tpl.php";
}
estevan_carlos’s picture

So, I'm a bit new to this so I'll try to ask the best questions I can. First of all, assuming the code I typed above is exactly what's in the book, you're saying it's correct? I'm just trying to gauge whether or not I did something wrong or the tutorial I'm going over is wrong.

nevets’s picture

Since I have not read the book and have no real context for the code I can only go by the code which looks like it is trying to do something in a round about way. That said, the code looks "correct" but not robust, do you only get the error on the homepage or on any page?