get_items_in_path in Menu.php - how is this supposed to work with breadcrumbs

edited May 2014 in Bug Reports
I am trying to use the breadcrumb function to create a breadcrumb - but I think there is a bug in the generation code.

If you look at...

https://github.com/daylightstudio/FUEL-CMS/blob/develop/fuel/modules/fuel/libraries/Menu.php

at line 1048, it looks for your place in the menu structure by looking at the key of the array and seeing if it matches the active page

if (isset($this->_items[$active]))

But my menu's are loaded from the CMS and seem to have numbers as the key

[29] => Array
(
[id] => 29
[label] => - Our Clients
[location] => /about/clients
[attributes] =>
[active] =>
[parent_id] => 3
[hidden] => no
[group_id] => 1
[nav_key] => /about/clients
[precedence] => 0
[selected] =>
[language] => english
[published] => yes
[group_name] => main
)

I don't see how this can work when your menu's come from the CMS. It should be looking to match the "location" I believe

Comments

  • edited 3:46AM
    If you are using the CMS to generate the menu structure, you need to grab the ID value of the menu item to set as the "active" value. Using something like $this->fuel->navigation->model()->find_by_nav_key('mylocation') should return the menu item in the database that is associated with that location and you can pass that menu items "id" as the active parameter.

    There is also a parameter to pass to fuel_nav called "use_nav_key" if set to TRUE will look at the location value as opposed to the ID value. This is set to "AUTO" by default.
  • edited 3:46AM
    I see that in the normalize function, it attempts to convert the numeric id to nav_key

    But since $return still has numeric array keys it never matches.

    if ($this->use_nav_key !== FALSE AND isset($return[$this->active]['nav_key']))
    {
    $active = $return[$this->active]['nav_key'];
    }

    $this->active = "/about/clients";

    and one of the elements of $return =
    [29] => Array
    (
    [id] => 29
    [label] => - Our Clients
    [location] => /about/clients
    [attributes] =>
    [active] =>
    [parent_id] => 3
    [hidden] => no
    [group_id] => 1
    [nav_key] => /about/clients
    [precedence] => 0
    [selected] =>
    [language] => english
    [published] => yes
    [group_name] => main
    )

    so isset($return[$this->active]['nav_key'])) is never true.
  • edited 3:46AM
    How are you generating the menu? If you use the fuel_nav() function, it maps to the Fuel_navigation::render() method and in it it uses the fuel_navigation_model::find_all_by_group() method which returns the nav_key as the array key and not an integer.
  • edited 3:46AM
    I was just using

    echo $this->fuel->navigation->breadcrumb();
  • edited 3:46AM
    Hmm... I'm having a hard time replicating this issue. In the Fuel_navigation::render method on line 225 should automatically do the lookup in the CMS for the appropriate active ID and use that instead of the nav_key value. Is that happening in your code?
  • edited 3:46AM
    Ok that helps, it isn't happening but I know why. Totally the web designers fault for entering the locations different than they are in the menu code (missing leading slash).

    But that being said the url's are functionally the same as far as the webserver/cms is concerned for displaying the page.

    I wonder if the compare should be more involved, I am generating some navigation from the pages structure rather than the menu and I am matching up using something like this

    $search_key = array_values(array_filter(explode('/', $page_name)));

    "go/here/for//links"
    "/go/here/for/links"

    Both gets somewhat normalized to

    Array
    (
    [0] => go
    [1] => here
    [2] => for
    [3] => links
    )

    But thanks for looking at my problem
    Dave Dula
  • edited 3:46AM
    Glad you got it figured out.
  • edited May 2014
    To solve the problem I just added something to the on_save method in the model

    public function on_before_save($values)
    {
    $CI = get_instance();
    $user = $CI->fuel->auth->user_data();
    $values['last_modified_by'] = $user['id'];


    // DOC XXX
    $search_key = array_values(array_filter(explode('/', $values['location'])));
    $values['location']=(implode('/',$search_key));

    return $values;
    }
Sign In or Register to comment.