FEATURE: Adding ProgressViewHelper and some minor cleanups
This commit is contained in:
parent
8c71d9ac07
commit
9e4380c524
4 changed files with 75 additions and 7 deletions
|
@ -23,4 +23,4 @@ interface ServiceInterface
|
|||
* @return array|\Iterator
|
||||
*/
|
||||
public function getItems($forPath = null);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,8 +17,6 @@ use Neos\Flow\Configuration\ConfigurationManager;
|
|||
|
||||
/**
|
||||
* Package base class of the DigiComp.Menu package.
|
||||
*
|
||||
* @Flow\Scope("singleton")
|
||||
*/
|
||||
class Package extends BasePackage
|
||||
{
|
||||
|
|
|
@ -18,7 +18,7 @@ use Neos\FluidAdaptor\Core\ViewHelper\AbstractViewHelper;
|
|||
* Just adds the return of MenuService
|
||||
* TODO: Write example
|
||||
*/
|
||||
class MenuViewHelper extends AbstractViewHelper
|
||||
class ItemsViewHelper extends AbstractViewHelper
|
||||
{
|
||||
|
||||
protected $escapeOutput = false;
|
||||
|
@ -31,12 +31,12 @@ class MenuViewHelper extends AbstractViewHelper
|
|||
|
||||
/**
|
||||
* @param string $as
|
||||
* @param string $forPath
|
||||
* @param string $for
|
||||
* @return string
|
||||
*/
|
||||
public function render($as = 'menuItems', $forPath = null)
|
||||
public function render($as = 'items', $for = null)
|
||||
{
|
||||
$this->templateVariableContainer->add($as, $this->menuService->getItems($forPath));
|
||||
$this->templateVariableContainer->add($as, $this->menuService->getItems($for));
|
||||
return $this->renderChildren();
|
||||
}
|
||||
}
|
70
Classes/ViewHelpers/ProgressViewHelper.php
Normal file
70
Classes/ViewHelpers/ProgressViewHelper.php
Normal file
|
@ -0,0 +1,70 @@
|
|||
<?php
|
||||
namespace DigiComp\Menu\ViewHelpers;
|
||||
|
||||
/*
|
||||
* This file is part of the DigiComp.Menu package.
|
||||
*
|
||||
* (c) digital competence
|
||||
*
|
||||
* This package is Open Source Software. For the full copyright and license
|
||||
* information, please view the LICENSE file which was distributed with this
|
||||
* source code.
|
||||
*/
|
||||
|
||||
use Neos\FluidAdaptor\Core\ViewHelper\AbstractViewHelper;
|
||||
|
||||
/**
|
||||
* Helps to get useful template variables for process menus
|
||||
*/
|
||||
class ProgressViewHelper extends AbstractViewHelper
|
||||
{
|
||||
|
||||
protected $escapeOutput = false;
|
||||
|
||||
/**
|
||||
* @param array $links
|
||||
* @param int $activeStep
|
||||
* @param bool $returnable
|
||||
* @param string $stepsAs
|
||||
* @param string $backLinkAs
|
||||
* @param string $activeStepAs
|
||||
* @param string $linksAs
|
||||
* @param string $activeStepLinkAs
|
||||
* @param int $offset
|
||||
* @param int $linkCount if given overrides count($links)
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function render(
|
||||
array $links,
|
||||
$activeStep = 1,
|
||||
$returnable = true,
|
||||
$stepsAs = 'steps',
|
||||
$backLinkAs = 'backLink',
|
||||
$activeStepAs = 'activeStep',
|
||||
$linksAs = 'links',
|
||||
$activeStepLinkAs = 'activeStepLink',
|
||||
$offset = 1,
|
||||
$linkCount = null
|
||||
) {
|
||||
//handling famous off by one
|
||||
$activeStep -= $offset;
|
||||
//make sure our array index is numeric
|
||||
$links = array_values($links);
|
||||
if (!$linkCount) {
|
||||
$linkCount = count($links);
|
||||
}
|
||||
foreach ($links as $i => &$link) {
|
||||
$link['completed'] = $activeStep > $i;
|
||||
$link['returnable'] = $returnable && $i < $activeStep;
|
||||
}
|
||||
$this->templateVariableContainer->add($linksAs, $links);
|
||||
$this->templateVariableContainer->add($stepsAs, $linkCount);
|
||||
$this->templateVariableContainer->add($activeStepAs, $activeStep + $offset);
|
||||
$this->templateVariableContainer->add($activeStepLinkAs, $links[$activeStep]);
|
||||
if (isset($links[$activeStep - 1])) {
|
||||
$this->templateVariableContainer->add($backLinkAs, $links[$activeStep - 1]);
|
||||
}
|
||||
return $this->renderChildren();
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue