YiiFoundation
  • Namespace
  • Class
  • Tree

Namespaces

  • foundation
    • enum
    • exception
    • helpers
    • widgets
      • base
  • PHP

Classes

  • Alert
  • Breadcrumbs
  • Clearing
  • Dropdown
  • FlexVideo
  • Interchange
  • JoyRide
  • Magellan
  • Orbit
  • Pager
  • Reveal
  • Section
  • SwitchButton
  • Tooltip
  • TopBar
  1 <?php
  2 /**
  3  * @copyright Copyright &copy; 2amigOS! Consulting Group 2013-
  4  * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
  5  * @package foundation.components
  6  * @version 1.0.0
  7  */
  8 namespace foundation\widgets;
  9 
 10 use foundation\helpers\ArrayHelper;
 11 use foundation\helpers\Html;
 12 use foundation\helpers\Icon;
 13 use foundation\enum\Enum;
 14 
 15 /**
 16  * Breadcrumbs renders a Foundation breadcrumb
 17  *
 18  * @see http://foundation.zurb.com/docs/components/breadcrumbs.html
 19  *
 20  * @author Antonio Ramirez <amigo.cobos@gmail.com>
 21  * @package foundation\widgets
 22  */
 23 class Breadcrumbs extends base\Widget
 24 {
 25     /**
 26      * @var boolean whether to HTML encode the link labels.
 27      */
 28     public $encodeLabel = true;
 29     /**
 30      * @var string the label for the first link in the breadcrumb.
 31      */
 32     public $homeLabel;
 33     /**
 34      * @var array the url for the first link in the breadcrumb
 35      */
 36     public $homeUrl;
 37     /**
 38      * @var string the tag name to be used. Possible: 'nav' | 'ul'. Defaults to 'ul'.
 39      */
 40     public $tagName = 'ul';
 41     /**
 42      * @var array $items the items of breadcrumbs. The format is as follows:
 43      * <pre>
 44      *  'label'=>'#',
 45      *  'label'=>array('url'=>'#', 'options'=>array())
 46      * </pre>
 47      */
 48     public $items = array();
 49 
 50 
 51     /**
 52      * Widget's init method
 53      */
 54     public function init()
 55     {
 56         parent::init();
 57         $this->initItems();
 58     }
 59 
 60     /**
 61      * Renders the widget
 62      */
 63     public function run()
 64     {
 65         $this->renderItems();
 66     }
 67 
 68     /**
 69      * Initializes menu items
 70      */
 71     public function initItems()
 72     {
 73         if (!empty($this->items)) {
 74             $links = array();
 75             if ($this->homeLabel !== false) {
 76                 $label         = $this->homeLabel !== null ? $this->homeLabel : Icon::icon(Enum::ICON_HOME);
 77                 $links[$label] = array('href' => $this->homeUrl !== null ? $this->homeUrl : \Yii::app()->homeUrl);
 78             }
 79 
 80             foreach ($this->items as $label => $options) {
 81                 if (is_string($label)) {
 82                     if ($this->encodeLabel)
 83                         $label = \CHtml::encode($label);
 84                     if (is_string($options))
 85                         $links[$label] = array('href' => \CHtml::normalizeUrl($options));
 86                     else {
 87                         $url             = ArrayHelper::removeValue($options, 'url', '');
 88                         $options['href'] = \CHtml::normalizeUrl($url);
 89                         $links[$label]   = $options;
 90                     }
 91                 } else
 92                     $links[$options] = array('href' => '#');
 93             }
 94             $this->items = $links;
 95         }
 96     }
 97 
 98     /**
 99      * Renders breadcrumbs
100      */
101     public function renderItems()
102     {
103         if (empty($this->items))
104             return;
105 
106         Html::addCssClass($this->htmlOptions, Enum::BREADCRUMBS);
107         echo \CHtml::openTag($this->tagName, $this->htmlOptions);
108         foreach ($this->items as $label => $options) {
109             $this->renderItem($label, $options);
110         }
111         echo \CHtml::closeTag($this->tagName);
112 
113     }
114 
115     /**
116      * Generates the rendering of a breadcrumb item
117      * @param string $label
118      * @param array $options
119      */
120     public function renderItem($label, $options = array())
121     {
122         if ($this->tagName === 'nav') {
123             $url         = ArrayHelper::removeValue($options, 'href', '#');
124             $htmlOptions = ArrayHelper::removeValue($options, 'options', array());
125             echo \CHtml::openTag('li', $htmlOptions);
126             echo \CHtml::link($label, $url);
127             echo \CHtml::closeTag('li');
128         } else {
129             $htmlOptions = ArrayHelper::removeValue($options, 'options', array());
130             echo \CHtml::tag('a', array_merge($htmlOptions, $options), $label);
131         }
132     }
133 }
YiiFoundation API documentation generated by ApiGen 2.8.0