From 87f00b3eb3833fa4d576c9ab2fab37f5cb7e41a3 Mon Sep 17 00:00:00 2001 From: Thomas Threadgold Date: Tue, 24 Oct 2017 13:01:45 +0200 Subject: [PATCH] Add option to ignore current page (#11) * #10 add option to ignore current page * #10 update blueprints with new setting * #10 add option documentation to readme * #10 fix typo in readme --- README.md | 3 ++- blueprints.yaml | 11 +++++++++++ breadcrumbs.yaml | 1 + classes/breadcrumbs.php | 20 ++++++++++++++------ 4 files changed, 28 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 18a0c58..7576279 100644 --- a/README.md +++ b/README.md @@ -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`. @@ -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 diff --git a/blueprints.yaml b/blueprints.yaml index 004ce5e..e802f47 100644 --- a/blueprints.yaml +++ b/blueprints.yaml @@ -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 diff --git a/breadcrumbs.yaml b/breadcrumbs.yaml index b6814af..5364d9d 100644 --- a/breadcrumbs.yaml +++ b/breadcrumbs.yaml @@ -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 diff --git a/classes/breadcrumbs.php b/classes/breadcrumbs.php index e1312ed..1b13078 100644 --- a/classes/breadcrumbs.php +++ b/classes/breadcrumbs.php @@ -44,17 +44,26 @@ 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)) { @@ -62,7 +71,6 @@ protected function build() } } - $this->breadcrumbs = array_reverse($hierarchy); } }