Hello Drupal comunity,
I've tried to fix TaxonomyMenu+PathAuto issue. It "almost" works... Just need to solve this:

I'm trying to access array through foreach and change values for particular key.

I'm able to access array without reference, but when I add& to create reference I receive:

Parse error: syntax error, unexpected '&', expecting T_VARIABLE or '$' in /home/.../modules/taxonomy_menu/taxonomy_menu.inc on line 185

My code:

foreach ($items as &$menu_item){       
    $menu_item['path'] = drupal_get_path_alias( 'taxonomy/term/' . end(explode('/',$menu_item['path'])) );               
  }
unset ($menu_item);

Regarding to http://uk3.php.net/foreach this should work:

$arr = array(1, 2, 3, 4);
foreach ($arr as &$value) {
    $value = $value * 2;
}
// $arr is now array(2, 4, 6, 8)
unset($value); // break the reference with the last element

I'm really confused and can't figure it out... ???

Any way around? Can I access array value directly (from within fereach) and change it?

Could anyone with better knowlegde of PHP help me/us please?

Comments

nevets’s picture

You do not say which version of PHP you are using, the by reference feature is part of PHP 5.

You can do something similar without the need for a reference like this

<?php
foreach ($items as $key => $menu_item){      
    $items[$key]['path'] = drupal_get_path_alias( 'taxonomy/term/' . end(explode('/',$menu_item['path'])) );              
  }
?>
michalczernik’s picture

Thank you NEVETS,
my hosting provider claims we use PHP 5, but phpinfo() says we use PHP 4.2.6. :-(

So I've used $key instead of referencig...

michalczernik’s picture

to make this two modules working together I've added following code to taxonomy_menu.inc in function _taxonomy_menu_menu() just almost at the end before return $items; (about line 180):

foreach ($items as $k=>$menu_item){    
		if (variable_get( 'taxonomy_menu_display_page', 'category') == substr($menu_item['path'],0,strpos($menu_item['path'],'/')) )
			{
				$items[$k]['path'] = drupal_get_path_alias( 'taxonomy/term/' . end(explode('/',$menu_item['path'])) );			
			}		
  }

It works for me perfectly! And it's much easier fix than http://drupal.org/node/41476#comment-181146 (which didn't work for me anyway).

jdln’s picture

Which file do I add this code to?
Thanks