breadcrumbs display hidden pages "exclude from nav"

Permalink 1 user found helpful
Hi

I have an auto_nav menu structure that has several "exclude from nav" or hidden pages.

I also have breadcrumb navigation, is it possible to override the "exclude from nav" so that all the parent pages are displayed in one menu but not the other?

thanks for any pointers

teknojunkey
View Replies:
teknojunkey replied on at Permalink Reply
teknojunkey
i used this as an auto_nav template file ..

<?php 
   defined('C5_EXECUTE') or die("Access Denied.");
   $aBlocks = $controller->generateNav();
   $c = Page::getCurrentPage();
   $nh = Loader::helper('navigation');
   $i = 0;
   foreach($aBlocks as $ni) {
      $_c = $ni->getCollectionObject();
         $pageLink = false;
         $target = $ni->getTarget();
         if ($target != '') {
            $target = 'target="' . $target . '"';
         }
         if ($_c->getCollectionAttributeValue('replace_link_with_first_in_nav')) {
            $subPage = $_c->getFirstChild();
johndorsay replied on at Permalink Reply
johndorsay
I have found that in these situations it is best to create an attribute like 'include_main_nav'
Then in your autonav block instead of this line
if (!$_c->getCollectionAttributeValue('exclude_nav')) {

use this
if ($_c->getCollectionAttributeValue('include_main_nav')) {
scalait replied on at Permalink Reply
scalait
I added this issue to the bug tracker:

http://www.concrete5.org/developers/bugs/5-4-1-1/breadcrumbs-do-not...

so please confirm the bug there, that it get changed in c5 core
Guido replied on at Permalink Reply
Guido
I also ran into this problem today. I solved it by overriding the getNavItems function from the AutonavBlockController.

First locate the following code:

//Retrieve the raw "pre-processed" list of all nav items (before any custom attributes are considered)
$allNavItems = $this->generateNav();


Directly after this code insert the following code:

$db = Loader::db();
$bFilename = $db->getOne("SELECT bFilename FROM Blocks WHERE bID = ? " , array($this->bID) );
$breadcrumb = $bFilename == 'breadcrumb.php'; //you could add more or another template filename here.


Then locate this code block:

if ($_c->getAttribute('exclude_nav') && ($current_level <= $excluded_parent_level)) {
   $excluded_parent_level = $current_level;
   $exclude_page = true;
} else if (($current_level > $excluded_parent_level) || ($current_level > $exclude_children_below_level)) {
   $exclude_page = true;
} else {
   $excluded_parent_level = 9999; //Reset to arbitrarily high number to denote that we're no longer excluding a parent
   $exclude_children_below_level = $_c->getAttribute('exclude_subpages_from_nav') ? $current_level : 9999;
   $exclude_page = false;
}


And replace it with this code:
if ($_c->getAttribute('exclude_nav') && ! $breadcrumb && ($current_level <= $excluded_parent_level)) {
   $excluded_parent_level = $current_level;
   $exclude_page = true;
} else if (($current_level > $excluded_parent_level) || ($current_level > $exclude_children_below_level)) {
   $exclude_page = true;
} else {
   $excluded_parent_level = 9999; //Reset to arbitrarily high number to denote that we're no longer excluding a parent
   $exclude_children_below_level = $_c->getAttribute('exclude_subpages_from_nav') && ! $breadcrumb ? $current_level : 9999;
   $exclude_page = false;
}


This works, though I think it's not ideal. If you have a second breadcrumb template you would have to edit the controller code again. Best would be if two checkboxes would be added in the edit view of the autonav block to be able to ignore the exclude_subpages_from_nav and exclude_nav page attribute.
drumrby replied on at Permalink Reply
drumrby
I ran into this issue too. I tried your code but I'm getting the following error

Fatal error: Using $this when not in object context in /concrete/blocks/autonav/controller.php on line 6


I added the code you provided to the controller file of the autonav block. Thank you in advance for any help you can provide.
Guido replied on at Permalink Reply
Guido
Hi, there. I see I wasn't quite clear about where to insert the modifications. I edited my solution a little, hope this clears things up.

Also, make sure you overwrite the controller function like this:

1. Copy the file /concrete/blocks/autonav/controller.php to /blocks/autonav/controller.php
2. Copy the function getNavItems() from /concrete/core/controllers/blocks/autonav.php to the AutonavBlockController Class in /blocks/autonav/controller.php

Then make the modifications in that function as described in my previous post.

Let me know if you need more help!
drumrby replied on at Permalink Reply 1 Attachment
drumrby
Thank you for the quick reply. I have followed the steps but the pages I want to exclude are still showing in the breadcrumb. I'm thinking it might be partly do to my file organization. I keep all my templates in the root /blocks folder, and each theme has its' own folder, e.g. /blocks/autonav/templates/breadcrumb_simple/view.php . I also put the new controller file in this breadcrumb_simple folder. Will this type of organization not work with this line of code?

$breadcrumb = $bFilename == 'breadcrumb_simple/view.php';


I have also attached my edited controller.php file, just to make sure I executed it properly.
Guido replied on at Permalink Reply
Guido
You'll have to move the getNavItems function inside the AutonavBlockController class. The file structure should look like this:

defined('C5_EXECUTE') or die("Access Denied.");
class AutonavBlockController extends Concrete5_Controller_Block_Autonav {
   function getNavItems($ignore_exclude_nav = false) {
      //function's content...
   }
}
class AutonavBlockItem extends Concrete5_Controller_Block_AutonavItem { }


I think 'breadcrumb_simple/view.php' is correct in your case. If it still won't work simply echo the $bFilename variable right after where it's set and check the block output on the page:

$bFilename = $db->getOne("SELECT bFilename FROM Blocks WHERE bID = ? " , array($this->bID) );
echo 'view file to use:' . $bFilename;