Zend Framework  3.0
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
Menu Class Reference

Helper for rendering menus from navigation containers. More...

Public Member Functions

 __invoke ($container=null)
 View helper entry point.
 
 render ($container=null)
 Renders menu.
 
 renderMenu ($container=null, array $options=[])
 Renders helper.
 
 renderPartial ($container=null, $partial=null)
 Renders the given $container by invoking the partial view helper.
 
 renderPartialWithParams (array $params=[], $container=null, $partial=null)
 Renders the given $container by invoking the partial view helper with the given parameters as the model.
 
 renderSubMenu (AbstractContainer $container=null, $ulClass=null, $indent=null, $liActiveClass=null)
 Renders the inner-most sub menu for the active page in the $container.
 
 escapeLabels ($flag=true)
 Sets a flag indicating whether labels should be escaped.
 
 setAddClassToListItem ($flag=true)
 Enables/disables page class applied to element.
 
 getAddClassToListItem ()
 Returns flag indicating whether page class should be applied to element.
 
 setOnlyActiveBranch ($flag=true)
 Sets a flag indicating whether only active branch should be rendered.
 
 getOnlyActiveBranch ()
 Returns a flag indicating whether only active branch should be rendered.
 
 setPartial ($partial)
 Sets which partial view script to use for rendering menu.
 
 getPartial ()
 Returns partial view script to use for rendering menu.
 
 setRenderParents ($flag=true)
 Enables/disables rendering of parents when only rendering active branch.
 
 getRenderParents ()
 Returns flag indicating whether parents should be rendered when rendering only the active branch.
 
 setUlClass ($ulClass)
 Sets CSS class to use for the first 'ul' element when rendering.
 
 getUlClass ()
 Returns CSS class to use for the first 'ul' element when rendering.
 
 setLiActiveClass ($liActiveClass)
 Sets CSS class to use for the active 'li' element when rendering.
 
 getLiActiveClass ()
 Returns CSS class to use for the active 'li' element when rendering.
 
- Public Member Functions inherited from AbstractHelper
 __call ($method, array $arguments=[])
 Magic overload: Proxy calls to the navigation container.
 
 __toString ()
 Magic overload: Proxy to render().
 
 accept (AbstractPage $page, $recursive=true)
 Determines whether a page should be accepted when iterating.
 
 setAcl (Acl\AclInterface $acl=null)
 Sets ACL to use when iterating pages.
 
 getAcl ()
 Returns ACL or null if it isn't set using setAcl() or setDefaultAcl().
 
 hasAcl ()
 Checks if the helper has an ACL instance.
 
 setEventManager (EventManagerInterface $events)
 Set the event manager.
 
 getEventManager ()
 Get the event manager, if present.
 
 setContainer ($container=null)
 Sets navigation container the helper operates on by default.
 
 getContainer ()
 Returns the navigation container helper operates on by default.
 
 hasContainer ()
 Checks if the helper has a container.
 
 setIndent ($indent)
 Set the indentation string for using in render(), optionally a number of spaces to indent with.
 
 getIndent ()
 Returns indentation.
 
 setMaxDepth ($maxDepth=null)
 Sets the maximum depth a page can have to be included when rendering.
 
 getMaxDepth ()
 Returns maximum depth a page can have to be included when rendering.
 
 setMinDepth ($minDepth=null)
 Sets the minimum depth a page must have to be included when rendering.
 
 getMinDepth ()
 Returns minimum depth a page must have to be included when rendering.
 
 setRenderInvisible ($renderInvisible=true)
 Render invisible items?
 
 getRenderInvisible ()
 Return renderInvisible flag.
 
 setRole ($role=null)
 Sets ACL role(s) to use when iterating pages.
 
 getRole ()
 Returns ACL role to use when iterating pages, or null if it isn't set using setRole() or setDefaultRole().
 
 hasRole ()
 Checks if the helper has an ACL role.
 
 setServiceLocator (ContainerInterface $serviceLocator)
 Set the service locator.
 
 getServiceLocator ()
 Get the service locator.
 
 setUseAcl ($useAcl=true)
 Sets whether ACL should be used.
 
 getUseAcl ()
 Returns whether ACL should be used.
 
- Public Member Functions inherited from AbstractHtmlElement
 getClosingBracket ()
 Get the tag closing bracket.
 
- Public Member Functions inherited from AbstractHelper
 setView (Renderer $view)
 Set the View object.
 
 getView ()
 Get the view object.
 

Protected Member Functions

 renderDeepestMenu (AbstractContainer $container, $ulClass, $indent, $minDepth, $maxDepth, $escapeLabels, $addClassToListItem, $liActiveClass)
 Renders the deepest active menu within [$minDepth, $maxDepth], (called from renderMenu()).
 
 renderNormalMenu (AbstractContainer $container, $ulClass, $indent, $minDepth, $maxDepth, $onlyActive, $escapeLabels, $addClassToListItem, $liActiveClass)
 Renders a normal menu (called from renderMenu()).
 
 normalizeOptions (array $options=[])
 Normalizes given render options.
 
- Protected Member Functions inherited from AbstractHelper
 parseContainer (&$container=null)
 Verifies container and eventually fetches it from service locator if it is a string.
 
 isAllowed ($params)
 Determines whether a page should be allowed given certain parameters.
 
 getWhitespace ($indent)
 Retrieve whitespace representation of $indent.
 
 htmlAttribs ($attribs)
 Converts an associative array to a string of tag attributes.
 
 translate ($message, $textDomain=null)
 Translate a message (for label, title, …)
 
 normalizeId ($value)
 Normalize an ID.
 
 setDefaultListeners ()
 Attaches default ACL listeners, if ACLs are in use.
 
- Protected Member Functions inherited from AbstractHtmlElement
 isXhtml ()
 Is doctype XHTML?
 
 htmlAttribs ($attribs)
 Converts an associative array to a string of tag attributes.
 
 normalizeId ($value)
 Normalize an ID.
 

Protected Attributes

 $addClassToListItem = false
 
 $escapeLabels = true
 
 $onlyActiveBranch = false
 
 $partial = null
 
 $renderParents = true
 
 $ulClass = 'navigation'
 
 $liActiveClass = 'active'
 
- Protected Attributes inherited from AbstractHelper
 $events
 
 $container
 
 $minDepth
 
 $maxDepth
 
 $indent = ''
 
 $acl
 
 $renderInvisible = false
 
 $role
 
 $serviceLocator
 
 $useAcl = true
 
- Protected Attributes inherited from AbstractHtmlElement
 $closingBracket = null
 
- Protected Attributes inherited from AbstractHelper
 $view = null
 

Additional Inherited Members

- Static Public Member Functions inherited from AbstractHelper
static setDefaultAcl (Acl\AclInterface $acl=null)
 Sets default ACL to use if another ACL is not explicitly set.
 
static setDefaultRole ($role=null)
 Sets default ACL role(s) to use when iterating pages if not explicitly set later with setRole().
 
- Public Attributes inherited from AbstractHtmlElement
const EOL = PHP_EOL
 EOL character.
 
- Static Protected Attributes inherited from AbstractHelper
static $defaultAcl
 
static $defaultRole
 

Detailed Description

Helper for rendering menus from navigation containers.

Member Function Documentation

__invoke (   $container = null)

View helper entry point.

Retrieves helper and optionally sets container to operate on.

Parameters
AbstractContainer$container[optional] container to operate on
Returns
self
escapeLabels (   $flag = true)

Sets a flag indicating whether labels should be escaped.

Parameters
bool$flag[optional] escape labels
Returns
self
getAddClassToListItem ( )

Returns flag indicating whether page class should be applied to element.

By default, this value is false.

Returns
bool whether parents should be rendered
getLiActiveClass ( )

Returns CSS class to use for the active 'li' element when rendering.

Returns
string
getOnlyActiveBranch ( )

Returns a flag indicating whether only active branch should be rendered.

By default, this value is false, meaning the entire menu will be be rendered.

Returns
bool
getPartial ( )

Returns partial view script to use for rendering menu.

Returns
string|array|null
getRenderParents ( )

Returns flag indicating whether parents should be rendered when rendering only the active branch.

By default, this value is true.

Returns
bool
getUlClass ( )

Returns CSS class to use for the first 'ul' element when rendering.

Returns
string
normalizeOptions ( array  $options = [])
protected

Normalizes given render options.

Parameters
array$options[optional] options to normalize
Returns
array
render (   $container = null)

Renders menu.

Implements HelperInterface::render().

If a partial view is registered in the helper, the menu will be rendered using the given partial script. If no partial is registered, the menu will be rendered as an 'ul' element by the helper's internal method.

See Also
renderPartial()
renderMenu()
Parameters
AbstractContainer$container[optional] container to render. Default is to render the container registered in the helper.
Returns
string

Implements HelperInterface.

renderDeepestMenu ( AbstractContainer  $container,
  $ulClass,
  $indent,
  $minDepth,
  $maxDepth,
  $escapeLabels,
  $addClassToListItem,
  $liActiveClass 
)
protected

Renders the deepest active menu within [$minDepth, $maxDepth], (called from renderMenu()).

Parameters
AbstractContainer$containercontainer to render
string$ulClassCSS class for first UL
string$indentinitial indentation
int | null$minDepthminimum depth
int | null$maxDepthmaximum depth
bool$escapeLabelsWhether or not to escape the labels
bool$addClassToListItemWhether or not page class applied to element
string$liActiveClassCSS class for active LI
Returns
string
renderMenu (   $container = null,
array  $options = [] 
)

Renders helper.

Renders a HTML 'ul' for the given $container. If $container is not given, the container registered in the helper will be used.

Available $options:

Parameters
AbstractContainer$container[optional] container to create menu from. Default is to use the container retrieved from getContainer().
array$options[optional] options for controlling rendering
Returns
string
renderNormalMenu ( AbstractContainer  $container,
  $ulClass,
  $indent,
  $minDepth,
  $maxDepth,
  $onlyActive,
  $escapeLabels,
  $addClassToListItem,
  $liActiveClass 
)
protected

Renders a normal menu (called from renderMenu()).

Parameters
AbstractContainer$containercontainer to render
string$ulClassCSS class for first UL
string$indentinitial indentation
int | null$minDepthminimum depth
int | null$maxDepthmaximum depth
bool$onlyActiverender only active branch?
bool$escapeLabelsWhether or not to escape the labels
bool$addClassToListItemWhether or not page class applied to element
string$liActiveClassCSS class for active LI
Returns
string
renderPartial (   $container = null,
  $partial = null 
)

Renders the given $container by invoking the partial view helper.

The container will simply be passed on as a model to the view script as-is, and will be available in the partial script as 'container', e.g. echo 'Number of pages: ', count($this->container);.

Parameters
null | AbstractContainer$container[optional] container to pass to view script. Default is to use the container registered in the helper.
null | 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.
Returns
string
Exceptions
Exception\RuntimeExceptionif no partial provided
Exception\InvalidArgumentExceptionif partial is invalid array
renderPartialWithParams ( array  $params = [],
  $container = null,
  $partial = null 
)

Renders the given $container by invoking the partial view helper with the given parameters as the model.

The container will simply be passed on as a model to the view script as-is, and will be available in the partial script as 'container', e.g. echo 'Number of pages: ', count($this->container);.

Any parameters provided will be passed to the partial via the view model.

Parameters
null | AbstractContainer$container[optional] container to pass to view script. Default is to use the container registered in the helper.
null | 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.
Returns
string
Exceptions
Exception\RuntimeExceptionif no partial provided
Exception\InvalidArgumentExceptionif partial is invalid array
renderSubMenu ( AbstractContainer  $container = null,
  $ulClass = null,
  $indent = null,
  $liActiveClass = null 
)

Renders the inner-most sub menu for the active page in the $container.

This is a convenience method which is equivalent to the following call: renderMenu($container, array( 'indent' => $indent, 'ulClass' => $ulClass, 'minDepth' => null, 'maxDepth' => null, 'onlyActiveBranch' => true, 'renderParents' => false, 'liActiveClass' => $liActiveClass ));

Parameters
AbstractContainer$container[optional] container to render. Default is to render the container registered in the helper.
string$ulClass[optional] CSS class to use for UL element. Default is to use the value from getUlClass().
string | int$indent[optional] indentation as a string or number of spaces. Default is to use the value retrieved from getIndent().
string$liActiveClass[optional] CSS class to use for UL element. Default is to use the value from getUlClass().
Returns
string
setAddClassToListItem (   $flag = true)

Enables/disables page class applied to element.

Parameters
bool$flag[optional] page class applied to element Default is true.
Returns
self fluent interface, returns self
setLiActiveClass (   $liActiveClass)

Sets CSS class to use for the active 'li' element when rendering.

Parameters
string$liActiveClassCSS class to set
Returns
self
setOnlyActiveBranch (   $flag = true)

Sets a flag indicating whether only active branch should be rendered.

Parameters
bool$flag[optional] render only active branch.
Returns
self
setPartial (   $partial)

Sets which partial view script to use for rendering menu.

Parameters
string | array$partialpartial 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.
Returns
self
setRenderParents (   $flag = true)

Enables/disables rendering of parents when only rendering active branch.

See setOnlyActiveBranch() for more information.

Parameters
bool$flag[optional] render parents when rendering active branch.
Returns
self
setUlClass (   $ulClass)

Sets CSS class to use for the first 'ul' element when rendering.

Parameters
string$ulClassCSS class to set
Returns
self

Member Data Documentation

$addClassToListItem = false
protected
$escapeLabels = true
protected
$liActiveClass = 'active'
protected
$onlyActiveBranch = false
protected
$partial = null
protected
$renderParents = true
protected
$ulClass = 'navigation'
protected