Skip to content
This repository has been archived by the owner on Jan 31, 2020. It is now read-only.

Commit

Permalink
Merge branch 'feature/5358' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
weierophinney committed Oct 30, 2013
155 parents ea86306 + 6bc8c90 + 6ec1d0f + 53d9070 + fefc773 + 83cbc8a + 1b9fd60 + 8a8b989 + 10da323 + e6aba5a + b71d0a2 + 2aa926c + 8405746 + bf1a8de + f16339d + ed1dbc8 + dbf56da + bdb277e + 364ced3 + 9fccdf3 + 40f5963 + 9d7ddea + e1e4aa8 + 870703b + 958decf + e49a08e + a051e7e + b9f6e35 + 2bbef72 + aea30ce + faec0a2 + 098e166 + 51d6372 + 8757ace + 42477b6 + 32cf329 + 0ebadc5 + 188fa4d + a41bbf0 + a29bbbc + 941280d + d691226 + e547023 + d91c234 + 006ef75 + 69d1518 + 7dc0d1a + a995715 + e780008 + e810876 + 9e4090a + 269bf01 + 3a1f2fd + 0cab32d + 704cc7f + e20c9e6 + a0dfc1a + 76b3e1c + fd429e8 + 187ea79 + 2b43ea6 + e3b1be1 + 19f0ef6 + 33bf9c0 + 3729984 + a5ce396 + 698dbe0 + 0efca0b + 08b2a78 + ddaa846 + 7fe4493 + 0da7331 + 7226b1d + 851904c + a2eb795 + f658a03 + de83270 + 806df8a + 4e7ff23 + 409b768 + 1b97191 + d2649e3 + f0162d1 + 6f01416 + a2b3753 + 1786961 + d157fcb + 4444c37 + 192d20c + 811122b + 3a2cf9b + eb2029b + 7a6edab + 8d8a05d + c1ddf21 + 0090b4d + ef80e35 + 59b30de + 4656098 + 377b920 + ccba82c + 5d2770e + 41714a1 + 8adef43 + a78628f + b35fa7a + 3953c79 + aa28e42 + 38f9a49 + 47ed633 + 0a6bf6e + b61d89d + a1fbb6f + 238512b + f40a328 + 62dc143 + 328df3b + e12fe2d + e34a942 + 04e956d + a19a8c2 + ac4b6c0 + d28282e + bd5af3d + b976cb5 + 4feb67b + 7164be7 + 40174df + e4918ae + 1d9f9a2 + c77ae57 + 223b881 + c2f4e25 + e08b166 + e58e548 + 85e6bbd + 0ac2052 + c7ba6af + f443c57 + 1380626 + 5316b6e + a6136d4 + d233be3 + c100a2a + c6a0e2c + e7eef3c + 812f35d + 604cdcd + 5472285 + 6e2f420 + 76c4d1c + c60cca9 + a67cdeb + 5d412ee + 9b6b2fb commit 42f98be
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 65 deletions.
51 changes: 33 additions & 18 deletions src/Helper/Navigation/AbstractHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,12 @@ public function findActive($container, $minDepth = null, $maxDepth = -1)

$found = null;
$foundDepth = -1;
$iterator = new RecursiveIteratorIterator($container, RecursiveIteratorIterator::CHILD_FIRST);
$iterator = new RecursiveIteratorIterator(
$container,
RecursiveIteratorIterator::CHILD_FIRST
);

/** @var \Zend\Navigation\Page\AbstractPage $page */
foreach ($iterator as $page) {
$currDepth = $iterator->getDepth();
if ($currDepth < $minDepth || !$this->accept($page)) {
Expand Down Expand Up @@ -388,25 +392,12 @@ protected function htmlAttribs($attribs)
* Returns an HTML string containing an 'a' element for the given page
*
* @param AbstractPage $page page to generate HTML for
* @return string
* @return string HTML string (<a href="…">Label</a>)
*/
public function htmlify(AbstractPage $page)
{
// get label and title for translating
$label = $page->getLabel();
$title = $page->getTitle();

if (null !== ($translator = $this->getTranslator())) {
if (null === ($textDomain = $page->getTextDomain())) {
$textDomain = $this->getTranslatorTextDomain();
}
if (is_string($label) && !empty($label)) {
$label = $translator->translate($label, $textDomain);
}
if (is_string($title) && !empty($title)) {
$title = $translator->translate($title, $textDomain);
}
}
$label = $this->translate($page->getLabel(), $page->getTextDomain());
$title = $this->translate($page->getTitle(), $page->getTextDomain());

// get attribs for anchor element
$attribs = array(
Expand All @@ -417,9 +408,33 @@ public function htmlify(AbstractPage $page)
'target' => $page->getTarget()
);

/** @var \Zend\View\Helper\EscapeHtml $escaper */
$escaper = $this->view->plugin('escapeHtml');
$label = $escaper($label);

return '<a' . $this->htmlAttribs($attribs) . '>' . $label . '</a>';
}

/**
* Translate a message (for label, title, …)
*
* @param string $message ID of the message to translate
* @param string $textDomain Text domain (category name for the translations)
* @return string Translated message
*/
protected function translate($message, $textDomain = null)
{
if (is_string($message) && !empty($message)) {
if (null !== ($translator = $this->getTranslator())) {
if (null === $textDomain) {
$textDomain = $this->getTranslatorTextDomain();
}

return $translator->translate($message, $textDomain);
}
}

return '<a' . $this->htmlAttribs($attribs) . '>' . $escaper($label) . '</a>';
return $message;
}

/**
Expand Down
19 changes: 8 additions & 11 deletions src/Helper/Navigation/Breadcrumbs.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,11 @@ public function renderStraight($container = null)
if ($this->getLinkLast()) {
$html = $this->htmlify($active);
} else {
$html = $active->getLabel();
if (null !== ($translator = $this->getTranslator())) {
if (null === ($textDomain = $active->getTextDomain())) {
$textDomain = $this->getTranslatorTextDomain();
}
$html = $translator->translate($html, $textDomain);
}
/** @var \Zend\View\Helper\EscapeHtml $escaper */
$escaper = $this->view->plugin('escapeHtml');
$html = $escaper($html);
$html = $escaper(
$this->translate($active->getLabel(), $active->getTextDomain())
);
}

// walk back to root
Expand Down Expand Up @@ -200,6 +196,9 @@ public function renderPartial($container = null, $partial = null)
$model['pages'] = array_reverse($model['pages']);
}

/** @var \Zend\View\Helper\Partial $partialHelper */
$partialHelper = $this->view->plugin('partial');

if (is_array($partial)) {
if (count($partial) != 2) {
throw new Exception\InvalidArgumentException(
Expand All @@ -209,11 +208,9 @@ public function renderPartial($container = null, $partial = null)
);
}

$partialHelper = $this->view->plugin('partial');
return $partialHelper($partial[0], /*$partial[1], */$model);
return $partialHelper($partial[0], $model);
}

$partialHelper = $this->view->plugin('partial');
return $partialHelper($partial, $model);
}

Expand Down
58 changes: 22 additions & 36 deletions src/Helper/Navigation/Menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ protected function renderDeepestMenu(
}

$ulClass = $ulClass ? ' class="' . $ulClass . '"' : '';
$html = $indent . '<ul' . $ulClass . '>' . self::EOL;
$html = $indent . '<ul' . $ulClass . '>' . PHP_EOL;

foreach ($active['page'] as $subPage) {
if (!$this->accept($subPage)) {
Expand All @@ -163,9 +163,9 @@ protected function renderDeepestMenu(
}
$liClass = empty($liClasses) ? '' : ' class="' . implode(' ', $liClasses) . '"';

$html .= $indent . ' <li' . $liClass . '>' . self::EOL;
$html .= $indent . ' ' . $this->htmlify($subPage, $escapeLabels, $addClassToListItem) . self::EOL;
$html .= $indent . ' </li>' . self::EOL;
$html .= $indent . ' <li' . $liClass . '>' . PHP_EOL;
$html .= $indent . ' ' . $this->htmlify($subPage, $escapeLabels, $addClassToListItem) . PHP_EOL;
$html .= $indent . ' </li>' . PHP_EOL;
}

$html .= $indent . '</ul>';
Expand Down Expand Up @@ -305,19 +305,19 @@ protected function renderNormalMenu(
} else {
$ulClass = '';
}
$html .= $myIndent . '<ul' . $ulClass . '>' . self::EOL;
$html .= $myIndent . '<ul' . $ulClass . '>' . PHP_EOL;
} elseif ($prevDepth > $depth) {
// close li/ul tags until we're at current depth
for ($i = $prevDepth; $i > $depth; $i--) {
$ind = $indent . str_repeat(' ', $i);
$html .= $ind . ' </li>' . self::EOL;
$html .= $ind . '</ul>' . self::EOL;
$html .= $ind . ' </li>' . PHP_EOL;
$html .= $ind . '</ul>' . PHP_EOL;
}
// close previous li tag
$html .= $myIndent . ' </li>' . self::EOL;
$html .= $myIndent . ' </li>' . PHP_EOL;
} else {
// close previous li tag
$html .= $myIndent . ' </li>' . self::EOL;
$html .= $myIndent . ' </li>' . PHP_EOL;
}

// render li tag and page
Expand All @@ -332,8 +332,8 @@ protected function renderNormalMenu(
}
$liClass = empty($liClasses) ? '' : ' class="' . implode(' ', $liClasses) . '"';

$html .= $myIndent . ' <li' . $liClass . '>' . self::EOL
. $myIndent . ' ' . $this->htmlify($page, $escapeLabels, $addClassToListItem) . self::EOL;
$html .= $myIndent . ' <li' . $liClass . '>' . PHP_EOL
. $myIndent . ' ' . $this->htmlify($page, $escapeLabels, $addClassToListItem) . PHP_EOL;

// store as previous depth for next iteration
$prevDepth = $depth;
Expand All @@ -343,10 +343,10 @@ protected function renderNormalMenu(
// done iterating container; close open ul/li tags
for ($i = $prevDepth+1; $i > 0; $i--) {
$myIndent = $indent . str_repeat(' ', $i-1);
$html .= $myIndent . ' </li>' . self::EOL
. $myIndent . '</ul>' . self::EOL;
$html .= $myIndent . ' </li>' . PHP_EOL
. $myIndent . '</ul>' . PHP_EOL;
}
$html = rtrim($html, self::EOL);
$html = rtrim($html, PHP_EOL);
}

return $html;
Expand Down Expand Up @@ -394,6 +394,9 @@ public function renderPartial($container = null, $partial = null)
'container' => $container
);

/** @var \Zend\View\Helper\Partial $partialHelper */
$partialHelper = $this->view->plugin('partial');

if (is_array($partial)) {
if (count($partial) != 2) {
throw new Exception\InvalidArgumentException(
Expand All @@ -403,11 +406,9 @@ public function renderPartial($container = null, $partial = null)
);
}

$partialHelper = $this->view->plugin('partial');
return $partialHelper($partial[0], /*$partial[1], */$model);
return $partialHelper($partial[0], $model);
}

$partialHelper = $this->view->plugin('partial');
return $partialHelper($partial, $model);
}

Expand Down Expand Up @@ -471,27 +472,10 @@ public function renderSubMenu(
*/
public function htmlify(AbstractPage $page, $escapeLabel = true, $addClassToListItem = false)
{
// get label and title for translating
$label = $page->getLabel();
$title = $page->getTitle();

// translate label and title?
if (null !== ($translator = $this->getTranslator())) {
if (null === ($textDomain = $page->getTextDomain())) {
$textDomain = $this->getTranslatorTextDomain();
}
if (is_string($label) && !empty($label)) {
$label = $translator->translate($label, $textDomain);
}
if (is_string($title) && !empty($title)) {
$title = $translator->translate($title, $textDomain);
}
}

// get attribs for element
$attribs = array(
'id' => $page->getId(),
'title' => $title,
'title' => $this->translate($page->getTitle(), $page->getTextDomain()),
);

if ($addClassToListItem === false) {
Expand All @@ -508,8 +492,10 @@ public function htmlify(AbstractPage $page, $escapeLabel = true, $addClassToList
$element = 'span';
}

$html = '<' . $element . $this->htmlAttribs($attribs) . '>';
$html = '<' . $element . $this->htmlAttribs($attribs) . '>';
$label = $this->translate($page->getLabel(), $page->getTextDomain());
if ($escapeLabel === true) {
/** @var \Zend\View\Helper\EscapeHtml $escaper */
$escaper = $this->view->plugin('escapeHtml');
$html .= $escaper($label);
} else {
Expand Down

0 comments on commit 42f98be

Please sign in to comment.