Custom Token + foreach not functionnal
I have rewrited my code from an example of a custom token:

$replacements = array();

if ($type == 'node' &amp;&amp; !empty($data['node'])) {

    $node = $data['node'];

    foreach ($tokens as $name =&gt; $original) {

        switch ($name) {

            case 'team_url':

            $path = 'node/'.$node-&gt;nid;

            $mlid = db_select('menu_links' , 'ml')
            -&gt;condition('ml.link_path' , $path)
            -&gt;fields('ml' , array('mlid'))
            -&gt;execute()
            -&gt;fetchField();

            $menuParents = token_menu_link_load_all_parents($mlid);

            foreach ($menuParents as $itemParent_mlid =&gt; $itemParent_title) {
                $item = menu_link_load($itemParent_mlid);
                $item_path = $item['link_path'];
                $item_path_args = explode('/', $item_path);
                $item_id = $item_path_args[1];
                $item_entity = entity_load('node', array($item_id));
                $item_type = $item_entity[$item_id]-&gt;type;
                if ($item_type == 'team' or $item_type == 'page_team') {
                    $itemParent[]= pathauto_cleanstring($itemParent_title);
                }
            }

            $itemsParents = implode("/", $itemParent);
            $replacements[$original] = $itemsParents;

        }
    }

}

return $replacements;


It's functionnal. Perhaps we can simplify this code and get a cleanly syntax.