From 6f5b16b31fcc95274ad51d73975d3f4ccf732751 Mon Sep 17 00:00:00 2001 From: Shunsuke Takahashi Date: Wed, 21 Dec 2016 16:34:35 +0900 Subject: [PATCH] Allow the prepend the addCrumb method --- .../Test/Case/View/Helper/HtmlHelperTest.php | 22 +++++++++++++++++++ lib/Cake/View/Helper/HtmlHelper.php | 13 +++++++++-- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/lib/Cake/Test/Case/View/Helper/HtmlHelperTest.php b/lib/Cake/Test/Case/View/Helper/HtmlHelperTest.php index e9096645385..8fb9eb83964 100644 --- a/lib/Cake/Test/Case/View/Helper/HtmlHelperTest.php +++ b/lib/Cake/Test/Case/View/Helper/HtmlHelperTest.php @@ -1500,6 +1500,28 @@ public function testBreadcrumb() { 'Fourth' ); $this->assertTags($result, $expected); + + $this->Html->addCrumb('Zeroth', '#zeroth', array('prepend' => true)); + + $result = $this->Html->getCrumbs(); + $expected = array( + array('a' => array('href' => '#zeroth')), + 'Zeroth', + '/a', + '»', + array('a' => array('href' => '#first')), + 'First', + '/a', + '»', + array('a' => array('href' => '#second')), + 'Second', + '/a', + '»', + array('a' => array('href' => '#third')), + 'Third', + '/a', + ); + $this->assertTags($result, $expected); } /** diff --git a/lib/Cake/View/Helper/HtmlHelper.php b/lib/Cake/View/Helper/HtmlHelper.php index 548c61e6bae..62e77204b55 100644 --- a/lib/Cake/View/Helper/HtmlHelper.php +++ b/lib/Cake/View/Helper/HtmlHelper.php @@ -180,8 +180,17 @@ public function __construct(View $View, $settings = array()) { * @see HtmlHelper::link() for details on $options that can be used. * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/html.html#creating-breadcrumb-trails-with-htmlhelper */ - public function addCrumb($name, $link = null, $options = null) { - $this->_crumbs[] = array($name, $link, $options); + public function addCrumb($name, $link = null, $options = array()) { + $prepend = false; + if (isset($options['prepend'])) { + $prepend = $options['prepend']; + unset($options['prepend']); + } + if ($prepend) { + array_unshift($this->_crumbs, array($name, $link, $options)); + } else { + array_push($this->_crumbs, array($name, $link, $options)); + } return $this; }