13 * to license@zend.com so we can send you a copy immediately. |
13 * to license@zend.com so we can send you a copy immediately. |
14 * |
14 * |
15 * @category Zend |
15 * @category Zend |
16 * @package Zend_View |
16 * @package Zend_View |
17 * @subpackage Helper |
17 * @subpackage Helper |
18 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
18 * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) |
19 * @license http://framework.zend.com/license/new-bsd New BSD License |
19 * @license http://framework.zend.com/license/new-bsd New BSD License |
20 * @version $Id: HelperAbstract.php 20096 2010-01-06 02:05:09Z bkarwin $ |
20 * @version $Id: HelperAbstract.php 25239 2013-01-22 09:45:01Z frosch $ |
21 */ |
21 */ |
22 |
22 |
23 /** |
23 /** |
24 * @see Zend_View_Helper_Navigation_Helper |
24 * @see Zend_View_Helper_Navigation_Helper |
25 */ |
25 */ |
34 * Base class for navigational helpers |
34 * Base class for navigational helpers |
35 * |
35 * |
36 * @category Zend |
36 * @category Zend |
37 * @package Zend_View |
37 * @package Zend_View |
38 * @subpackage Helper |
38 * @subpackage Helper |
39 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
39 * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) |
40 * @license http://framework.zend.com/license/new-bsd New BSD License |
40 * @license http://framework.zend.com/license/new-bsd New BSD License |
41 */ |
41 */ |
42 abstract class Zend_View_Helper_Navigation_HelperAbstract |
42 abstract class Zend_View_Helper_Navigation_HelperAbstract |
43 extends Zend_View_Helper_HtmlElement |
43 extends Zend_View_Helper_HtmlElement |
44 implements Zend_View_Helper_Navigation_Helper |
44 implements Zend_View_Helper_Navigation_Helper |
68 * Indentation string |
68 * Indentation string |
69 * |
69 * |
70 * @var string |
70 * @var string |
71 */ |
71 */ |
72 protected $_indent = ''; |
72 protected $_indent = ''; |
|
73 |
|
74 /** |
|
75 * Whether HTML/XML output should be formatted |
|
76 * |
|
77 * @var bool |
|
78 */ |
|
79 protected $_formatOutput = true; |
|
80 |
|
81 /** |
|
82 * Prefix for IDs when they are normalized |
|
83 * |
|
84 * @var string|null |
|
85 */ |
|
86 protected $_prefixForId = null; |
|
87 |
|
88 /** |
|
89 * Skip current prefix for IDs when they are normalized (flag) |
|
90 * |
|
91 * @var bool |
|
92 */ |
|
93 protected $_skipPrefixForId = false; |
73 |
94 |
74 /** |
95 /** |
75 * Translator |
96 * Translator |
76 * |
97 * |
77 * @var Zend_Translate_Adapter |
98 * @var Zend_Translate_Adapter |
262 $this->_indent = $this->_getWhitespace($indent); |
283 $this->_indent = $this->_getWhitespace($indent); |
263 return $this; |
284 return $this; |
264 } |
285 } |
265 |
286 |
266 /** |
287 /** |
267 * Returns indentation |
288 * Returns indentation (format output is respected) |
268 * |
289 * |
269 * @return string |
290 * @return string indentation string or an empty string |
270 */ |
291 */ |
271 public function getIndent() |
292 public function getIndent() |
272 { |
293 { |
|
294 if (false === $this->getFormatOutput()) { |
|
295 return ''; |
|
296 } |
|
297 |
273 return $this->_indent; |
298 return $this->_indent; |
|
299 } |
|
300 |
|
301 /** |
|
302 * Returns the EOL character (format output is respected) |
|
303 * |
|
304 * @see self::EOL |
|
305 * @see getFormatOutput() |
|
306 * |
|
307 * @return string standard EOL charater or an empty string |
|
308 */ |
|
309 public function getEOL() |
|
310 { |
|
311 if (false === $this->getFormatOutput()) { |
|
312 return ''; |
|
313 } |
|
314 |
|
315 return self::EOL; |
|
316 } |
|
317 |
|
318 /** |
|
319 * Sets whether HTML/XML output should be formatted |
|
320 * |
|
321 * @param bool $formatOutput [optional] whether output |
|
322 * should be formatted. Default |
|
323 * is true. |
|
324 * |
|
325 * @return Zend_View_Helper_Navigation_Sitemap fluent interface, returns |
|
326 * self |
|
327 */ |
|
328 public function setFormatOutput($formatOutput = true) |
|
329 { |
|
330 $this->_formatOutput = (bool)$formatOutput; |
|
331 |
|
332 return $this; |
|
333 } |
|
334 |
|
335 /** |
|
336 * Returns whether HTML/XML output should be formatted |
|
337 * |
|
338 * @return bool whether HTML/XML output should be formatted |
|
339 */ |
|
340 public function getFormatOutput() |
|
341 { |
|
342 return $this->_formatOutput; |
|
343 } |
|
344 |
|
345 /** |
|
346 * Sets prefix for IDs when they are normalized |
|
347 * |
|
348 * @param string $prefix Prefix for IDs |
|
349 * @return Zend_View_Helper_Navigation_HelperAbstract fluent interface, returns self |
|
350 */ |
|
351 public function setPrefixForId($prefix) |
|
352 { |
|
353 if (is_string($prefix)) { |
|
354 $this->_prefixForId = trim($prefix); |
|
355 } |
|
356 |
|
357 return $this; |
|
358 } |
|
359 |
|
360 /** |
|
361 * Returns prefix for IDs when they are normalized |
|
362 * |
|
363 * @return string Prefix for |
|
364 */ |
|
365 public function getPrefixForId() |
|
366 { |
|
367 if (null === $this->_prefixForId) { |
|
368 $prefix = get_class($this); |
|
369 $this->_prefixForId = strtolower( |
|
370 trim(substr($prefix, strrpos($prefix, '_')), '_') |
|
371 ) . '-'; |
|
372 } |
|
373 |
|
374 return $this->_prefixForId; |
|
375 } |
|
376 |
|
377 /** |
|
378 * Skip the current prefix for IDs when they are normalized |
|
379 * |
|
380 * @param bool $flag |
|
381 * @return Zend_View_Helper_Navigation_HelperAbstract fluent interface, returns self |
|
382 */ |
|
383 public function skipPrefixForId($flag = true) |
|
384 { |
|
385 $this->_skipPrefixForId = (bool) $flag; |
|
386 return $this; |
274 } |
387 } |
275 |
388 |
276 /** |
389 /** |
277 * Sets translator to use in helper |
390 * Sets translator to use in helper |
278 * |
391 * |
375 $role instanceof Zend_Acl_Role_Interface) { |
488 $role instanceof Zend_Acl_Role_Interface) { |
376 $this->_role = $role; |
489 $this->_role = $role; |
377 } else { |
490 } else { |
378 require_once 'Zend/View/Exception.php'; |
491 require_once 'Zend/View/Exception.php'; |
379 $e = new Zend_View_Exception(sprintf( |
492 $e = new Zend_View_Exception(sprintf( |
380 '$role must be a string, null, or an instance of ' |
493 '$role must be a string, null, or an instance of ' |
381 . 'Zend_Acl_Role_Interface; %s given', |
494 . 'Zend_Acl_Role_Interface; %s given', |
382 gettype($role) |
495 gettype($role) |
383 )); |
496 )); |
384 $e->setView($this->view); |
497 $e->setView($this->view); |
385 throw $e; |
498 throw $e; |
667 $title = $t->translate($title); |
780 $title = $t->translate($title); |
668 } |
781 } |
669 } |
782 } |
670 |
783 |
671 // get attribs for anchor element |
784 // get attribs for anchor element |
672 $attribs = array( |
785 $attribs = array_merge( |
673 'id' => $page->getId(), |
786 array( |
674 'title' => $title, |
787 'id' => $page->getId(), |
675 'class' => $page->getClass(), |
788 'title' => $title, |
676 'href' => $page->getHref(), |
789 'class' => $page->getClass(), |
677 'target' => $page->getTarget() |
790 'href' => $page->getHref(), |
|
791 'target' => $page->getTarget() |
|
792 ), |
|
793 $page->getCustomHtmlAttribs() |
678 ); |
794 ); |
679 |
795 |
680 return '<a' . $this->_htmlAttribs($attribs) . '>' |
796 return '<a' . $this->_htmlAttribs($attribs) . '>' |
681 . $this->view->escape($label) |
797 . $this->view->escape($label) |
682 . '</a>'; |
798 . '</a>'; |
798 } |
914 } |
799 |
915 |
800 /** |
916 /** |
801 * Normalize an ID |
917 * Normalize an ID |
802 * |
918 * |
803 * Overrides {@link Zend_View_Helper_HtmlElement::_normalizeId()}. |
919 * Extends {@link Zend_View_Helper_HtmlElement::_normalizeId()}. |
804 * |
920 * |
805 * @param string $value |
921 * @param string $value ID |
806 * @return string |
922 * @return string Normalized ID |
807 */ |
923 */ |
808 protected function _normalizeId($value) |
924 protected function _normalizeId($value) |
809 { |
925 { |
810 $prefix = get_class($this); |
926 if (false === $this->_skipPrefixForId) { |
811 $prefix = strtolower(trim(substr($prefix, strrpos($prefix, '_')), '_')); |
927 $prefix = $this->getPrefixForId(); |
812 |
928 |
813 return $prefix . '-' . $value; |
929 if (strlen($prefix)) { |
|
930 return $prefix . $value; |
|
931 } |
|
932 } |
|
933 |
|
934 return parent::_normalizeId($value); |
814 } |
935 } |
815 |
936 |
816 // Static methods: |
937 // Static methods: |
817 |
938 |
818 /** |
939 /** |