Skip to content

Commit

Permalink
Add option to ignore current page (#11)
Browse files Browse the repository at this point in the history
* #10 add option to ignore current page

* #10 update blueprints with new setting

* #10 add option documentation to readme

* #10 fix typo in readme
  • Loading branch information
Regaez authored and rhukster committed Oct 24, 2017
1 parent 1fd1ead commit 87f00b3
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 7 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ This command will check your Grav install to see if your Breadcrumbs plugin is d
Manually updating Breadcrumbs is pretty simple. Here is what you will need to do to get this done:

* Delete the `your/site/user/plugins/breadcrumbs` directory.
* Downalod the new version of the Breadcrumbs plugin from either [GitHub](https://github.com/getgrav/grav-plugin-breadcrumbs) or [GetGrav.org](http://getgrav.org/downloads/plugins#extras).
* Download the new version of the Breadcrumbs plugin from either [GitHub](https://github.com/getgrav/grav-plugin-breadcrumbs) or [GetGrav.org](http://getgrav.org/downloads/plugins#extras).
* Unzip the zip file in `your/site/user/plugins` and rename the resulting folder to `breadcrumbs`.
* Clear the Grav cache. The simplest way to do this is by going to the root Grav directory in terminal and typing `bin/grav clear-cache`.

Expand All @@ -73,6 +73,7 @@ enabled: true
show_all: true
built_in_css: true
include_home: true
include_current: true
icon_home: ''
icon_divider_classes: 'fa fa-angle-right'
link_trailing: false
Expand Down
11 changes: 11 additions & 0 deletions blueprints.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,17 @@ form:
validate:
type: bool

include_current:
type: toggle
label: Include Current Page
highlight: 1
default: 1
options:
1: Enabled
0: Disabled
validate:
type: bool

icon_home:
type: text
size: medium
Expand Down
1 change: 1 addition & 0 deletions breadcrumbs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ enabled: true
show_all: true
built_in_css: true
include_home: true
include_current: true
icon_home: ''
icon_divider_classes: 'fa fa-angle-right'
link_trailing: false
20 changes: 14 additions & 6 deletions classes/breadcrumbs.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,25 +44,33 @@ protected function build()
$grav = Grav::instance();
$current = $grav['page'];

while ($current && !$current->root()) {
$hierarchy[$current->url()] = $current;
$current = $current->parent();
}

// Page cannot be routed.
if (!$current) {
$this->breadcrumbs = array();
return;
}

if (!$current->root()) {

if ($this->config['include_current']) {
$hierarchy[$current->url()] = $current;
}

$current = $current->parent();

while ($current && !$current->root()) {
$hierarchy[$current->url()] = $current;
$current = $current->parent();
}
}

if ($this->config['include_home']) {
$home = $grav['pages']->dispatch('/');
if ($home && !array_key_exists($home->url(), $hierarchy)) {
$hierarchy[] = $home;
}
}


$this->breadcrumbs = array_reverse($hierarchy);
}
}

0 comments on commit 87f00b3

Please sign in to comment.