Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates Breadcrumbs.php #5

Merged
merged 1 commit into from
Jul 20, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
118 changes: 66 additions & 52 deletions src/Helper/Navigation/Breadcrumbs.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<?php

/**
* Zend Framework (http://framework.zend.com/)
* Zend Framework (http://framework.zend.com/).
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
*
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
Expand All @@ -15,49 +17,50 @@
use Zend\View\Exception;

/**
* Helper for printing breadcrumbs
* Helper for printing breadcrumbs.
*/
class Breadcrumbs extends AbstractHelper
{
/**
* Whether last page in breadcrumb should be hyperlinked
* Whether last page in breadcrumb should be hyperlinked.
*
* @var bool
*/
protected $linkLast = false;

/**
* The minimum depth a page must have to be included when rendering
* The minimum depth a page must have to be included when rendering.
*
* @var int
*/
protected $minDepth = 1;

/**
* Partial view script to use for rendering menu
* Partial view script to use for rendering menu.
*
* @var string|array
*/
protected $partial;

/**
* Breadcrumbs separator string
* Breadcrumbs separator string.
*
* @var string
*/
protected $separator = ' &gt; ';

/**
* Array with variables to populate in the view
* Array with variables to populate in the view.
*
* @var array
*/
protected $partialParams = [];

/**
* Helper entry point
* Helper entry point.
*
* @param string|AbstractContainer $container container to operate on
*
* @param string|AbstractContainer $container container to operate on
* @return Breadcrumbs
*/
public function __invoke($container = null)
Expand All @@ -70,12 +73,13 @@ public function __invoke($container = null)
}

/**
* Renders helper
* Renders helper.
*
* Implements {@link HelperInterface::render()}.
*
* @param AbstractContainer $container [optional] container to render. Default is
* to render the container registered in the helper.
* @param AbstractContainer $container [optional] container to render. Default is
* to render the container registered in the helper.
*
* @return string
*/
public function render($container = null)
Expand All @@ -90,10 +94,11 @@ public function render($container = null)

/**
* Renders breadcrumbs by chaining 'a' elements with the separator
* registered in the helper
* registered in the helper.
*
* @param AbstractContainer $container [optional] container to render. Default is
* to render the container registered in the helper.
*
* @param AbstractContainer $container [optional] container to render. Default is
* to render the container registered in the helper.
* @return string
*/
public function renderStraight($container = null)
Expand All @@ -116,7 +121,7 @@ public function renderStraight($container = null)
} else {
/** @var \Zend\View\Helper\EscapeHtml $escaper */
$escaper = $this->view->plugin('escapeHtml');
$html = $escaper(
$html = $escaper(
$this->translate($active->getLabel(), $active->getTextDomain())
);
}
Expand All @@ -126,8 +131,8 @@ public function renderStraight($container = null)
if ($parent instanceof AbstractPage) {
// prepend crumb to html
$html = $this->htmlify($parent)
. $this->getSeparator()
. $html;
.$this->getSeparator()
.$html;
}

if ($parent === $container) {
Expand All @@ -138,27 +143,29 @@ public function renderStraight($container = null)
$active = $parent;
}

return strlen($html) ? $this->getIndent() . $html : '';
return strlen($html) ? $this->getIndent().$html : '';
}

/**
* Renders the given $container by invoking the partial view helper
* Renders the given $container by invoking the partial view helper.
*
* The container will simply be passed on as a model to the view script,
* so in the script it will be available in <code>$this->container</code>.
*
* @param AbstractContainer $container [optional] container to pass to view script.
* Default is to use the container registered
* in the helper.
* @param string|array $partial [optional] partial view script to use.
* Default is to use the partial registered
* in the helper. If an array is given, it
* is expected to contain two values; the
* partial view script to use, and the module
* where the script can be found.
* @throws Exception\RuntimeException if no partial provided
* @param AbstractContainer $container [optional] container to pass to view script.
* Default is to use the container registered
* in the helper.
* @param string|array $partial [optional] partial view script to use.
* Default is to use the partial registered
* in the helper. If an array is given, it
* is expected to contain two values; the
* partial view script to use, and the module
* where the script can be found.
*
* @throws Exception\RuntimeException if no partial provided
* @throws Exception\InvalidArgumentException if partial is invalid array
* @return string helper output
*
* @return string helper output
*/
public function renderPartial($container = null, $partial = null)
{
Expand All @@ -178,8 +185,7 @@ public function renderPartial($container = null, $partial = null)
}

// put breadcrumb pages in model
$model = array_merge((array)$this->partialParams , array('pages' => array()), array('separator' => $this->getSeparator()));

$model = array_merge((array) $this->partialParams, ['pages' => []], ['separator' => $this->getSeparator()]);
$active = $this->findActive($container);
if ($active) {
$active = $active['page'];
Expand Down Expand Up @@ -208,8 +214,8 @@ public function renderPartial($container = null, $partial = null)
if (count($partial) != 2) {
throw new Exception\InvalidArgumentException(
'Unable to render menu: A view partial supplied as '
. 'an array must contain two values: partial view '
. 'script and module where script can be found'
.'an array must contain two values: partial view '
.'script and module where script can be found'
);
}

Expand All @@ -220,19 +226,21 @@ public function renderPartial($container = null, $partial = null)
}

/**
* Sets whether last page in breadcrumbs should be hyperlinked
* Sets whether last page in breadcrumbs should be hyperlinked.
*
* @param bool $linkLast whether last page should be hyperlinked
*
* @param bool $linkLast whether last page should be hyperlinked
* @return Breadcrumbs
*/
public function setLinkLast($linkLast)
{
$this->linkLast = (bool) $linkLast;

return $this;
}

/**
* Returns whether last page in breadcrumbs should be hyperlinked
* Returns whether last page in breadcrumbs should be hyperlinked.
*
* @return bool
*/
Expand All @@ -242,13 +250,14 @@ public function getLinkLast()
}

/**
* Sets which partial view script to use for rendering menu
* Sets which partial view script to use for rendering menu.
*
* @param string|array $partial partial view script or null. If an array is
* given, it is expected to contain two
* values; the partial view script to use,
* and the module where the script can be
* found.
*
* @param string|array $partial partial view script or null. If an array is
* given, it is expected to contain two
* values; the partial view script to use,
* and the module where the script can be
* found.
* @return Breadcrumbs
*/
public function setPartial($partial)
Expand All @@ -261,7 +270,7 @@ public function setPartial($partial)
}

/**
* Returns partial view script to use for rendering menu
* Returns partial view script to use for rendering menu.
*
* @return string|array|null
*/
Expand All @@ -271,9 +280,10 @@ public function getPartial()
}

/**
* Sets breadcrumb separator
* Sets breadcrumb separator.
*
* @param string $separator separator string
*
* @param string $separator separator string
* @return Breadcrumbs
*/
public function setSeparator($separator)
Expand All @@ -286,17 +296,18 @@ public function setSeparator($separator)
}

/**
* Returns breadcrumb separator
* Returns breadcrumb separator.
*
* @return string breadcrumb separator
* @return string breadcrumb separator
*/
public function getSeparator()
{
return $this->separator;
}

/**
* Returns partial params variable to populate in the view
* Returns partial params variable to populate in the view.
*
* @return array
*/
public function getPartialParams()
Expand All @@ -305,13 +316,16 @@ public function getPartialParams()
}

/**
* Sets partial params variable to populate in the view
* Sets partial params variable to populate in the view.
*
* @param array $partialParams
*
* @@return self
*/
public function setPartialParams($partialParams = array())
public function setPartialParams($partialParams = [])
{
$this->partialParams = $partialParams;

return $this;
}
}