71 lines
2.1 KiB
PHP
71 lines
2.1 KiB
PHP
<?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;
|
|
|
|
/**
|
|
* TODO: initializeArguments
|
|
* @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();
|
|
}
|
|
}
|