Skip to content
This repository
Browse code

Added `startText` feature to HtmlHelper::getCrumbList()

  • Loading branch information...
commit af2fd0359072eebccc68f5bbc8e7ddfd6c1af829 1 parent bda0529
Tigran Gabrielyan authored February 16, 2012
44  lib/Cake/Test/Case/View/Helper/HtmlHelperTest.php
@@ -1786,6 +1786,50 @@ public function testCrumbList() {
1786 1786
 	}
1787 1787
 
1788 1788
 /**
  1789
+ * Test getCrumbList startText
  1790
+ */
  1791
+    public function testCrumbListFirstLink() {
  1792
+        $this->Html->addCrumb('First', '#first');
  1793
+        $this->Html->addCrumb('Second', '#second');
  1794
+
  1795
+        $result = $this->Html->getCrumbList(null, 'Home');
  1796
+        $this->assertTags(
  1797
+            $result,
  1798
+            array(
  1799
+                '<ul',
  1800
+                array('li' => array('class' => 'first')),
  1801
+                array('a' => array('href' => '/')), 'Home', '/a',
  1802
+                '/li',
  1803
+                '<li',
  1804
+                array('a' => array('href' => '#first')), 'First', '/a',
  1805
+                '/li',
  1806
+                array('li' => array('class' => 'last')),
  1807
+                array('a' => array('href' => '#second')), 'Second', '/a',
  1808
+                '/li',
  1809
+                '/ul'
  1810
+            )
  1811
+        );
  1812
+
  1813
+        $result = $this->Html->getCrumbList(null, array('url' => '/home', 'text' => '<img src="/home.png" />', 'escape' => false));
  1814
+        $this->assertTags(
  1815
+            $result,
  1816
+            array(
  1817
+                '<ul',
  1818
+                array('li' => array('class' => 'first')),
  1819
+                array('a' => array('href' => '/home')), 'img' => array('src' => '/home.png'), '/a',
  1820
+                '/li',
  1821
+                '<li',
  1822
+                array('a' => array('href' => '#first')), 'First', '/a',
  1823
+                '/li',
  1824
+                array('li' => array('class' => 'last')),
  1825
+                array('a' => array('href' => '#second')), 'Second', '/a',
  1826
+                '/li',
  1827
+                '/ul'
  1828
+            )
  1829
+        );
  1830
+    }
  1831
+
  1832
+/**
1789 1833
  * testLoadConfig method
1790 1834
  *
1791 1835
  * @return void
21  lib/Cake/View/Helper/HtmlHelper.php
@@ -719,15 +719,30 @@ public function getCrumbs($separator = '&raquo;', $startText = false) {
719 719
  * crumb was added with.
720 720
  *
721 721
  * @param array $options Array of html attributes to apply to the generated list elements.
  722
+ * @param mixed $startText This will be the first crumb, if false it defaults to first crumb in array. Can
  723
+ *   also be an array, see `HtmlHelper::getCrumbs` for details.
722 724
  * @return string breadcrumbs html list
723 725
  * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/html.html#creating-breadcrumb-trails-with-htmlhelper
724 726
  */
725  
-	public function getCrumbList($options = array()) {
  727
+	public function getCrumbList($options = array(), $startText = false) {
726 728
 		if (!empty($this->_crumbs)) {
727 729
 			$result = '';
728  
-			$crumbCount = count($this->_crumbs);
  730
+			$crumbs = $this->_crumbs;
  731
+			if ($startText) {
  732
+				if (!is_array($startText)) {
  733
+					$startText = array(
  734
+						'url' => '/',
  735
+						'text' => $startText
  736
+					);
  737
+				}
  738
+				$startText += array('url' => '/', 'text' => __('Home'));
  739
+				list($url, $text) = array($startText['url'], $startText['text']);
  740
+				unset($startText['url'], $startText['text']);
  741
+				array_unshift($crumbs, array($text, $url, $startText));
  742
+			}
  743
+			$crumbCount = count($crumbs);
729 744
 			$ulOptions = $options;
730  
-			foreach ($this->_crumbs as $which => $crumb) {
  745
+			foreach ($crumbs as $which => $crumb) {
731 746
 				$options = array();
732 747
 				if (empty($crumb[1])) {
733 748
 					$elementContent = $crumb[0];

0 notes on commit af2fd03

Please sign in to comment.
Something went wrong with that request. Please try again.