2017-06-05 18:40:50 +02:00
|
|
|
<?php
|
2021-05-12 02:01:22 +02:00
|
|
|
|
2017-06-05 18:40:50 +02:00
|
|
|
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;
|
2021-05-12 02:26:43 +02:00
|
|
|
use Neos\FluidAdaptor\Core\ViewHelper\Exception;
|
2017-06-05 18:40:50 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Helps to get useful template variables for process menus
|
|
|
|
*/
|
|
|
|
class ProgressViewHelper extends AbstractViewHelper
|
|
|
|
{
|
|
|
|
protected $escapeOutput = false;
|
|
|
|
|
|
|
|
/**
|
2021-05-12 02:26:43 +02:00
|
|
|
* @throws Exception
|
2017-06-05 18:40:50 +02:00
|
|
|
*/
|
2021-05-12 02:26:43 +02:00
|
|
|
public function initializeArguments(): void
|
|
|
|
{
|
|
|
|
$this->registerArgument('for', 'string', 'path in Menu.yaml', false);
|
|
|
|
$this->registerArgument('as', 'string', 'Name in Frontend', false);
|
|
|
|
$this->registerArgument('links', 'array', 'links to show', true);
|
|
|
|
$this->registerArgument('activeStep', 'int', 'current active link index', false, 1);
|
|
|
|
$this->registerArgument('returnable', 'bool', 'can you go back to the last index', false, true);
|
|
|
|
$this->registerArgument('stepsAs', 'string', 'variable name of a single step', false, 'steps');
|
|
|
|
$this->registerArgument('backLinkAs', 'string', 'variable name of a backlink', false, 'backLink');
|
|
|
|
$this->registerArgument('linksAs', 'string', 'variable name of the links array', false, 'links');
|
|
|
|
$this->registerArgument(
|
|
|
|
'activeStepLinkAs',
|
|
|
|
'string',
|
|
|
|
'variable name of the active step link',
|
|
|
|
false,
|
|
|
|
'activeStepLink'
|
|
|
|
);
|
|
|
|
$this->registerArgument('offset', 'int', 'offset to start with', false, 1);
|
|
|
|
$this->registerArgument('linkCount', 'int', 'force this number of steps', false);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function render()
|
|
|
|
{
|
|
|
|
$links = $activeStep = $returnable = $stepsAs = $backLinkAs = $activeStepAs = $linksAs =
|
|
|
|
$activeStepLinkAs = $offset = $linkCount = null;
|
|
|
|
extract($this->arguments);
|
2017-06-05 18:40:50 +02:00
|
|
|
//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();
|
|
|
|
}
|
|
|
|
}
|