Type hinting and no render method arguments

This commit is contained in:
Ferdinand Kuhl 2021-05-12 02:26:43 +02:00
parent e436e722c1
commit 6339e96084
4 changed files with 49 additions and 48 deletions

View file

@ -18,9 +18,9 @@ namespace DigiComp\Menu\MenuService;
interface ServiceInterface interface ServiceInterface
{ {
/** /**
* @param mixed $forPath * @param string|null $forPath
* *
* @return array|\Iterator * @return array|\Iterator
*/ */
public function getItems($forPath = null); public function getItems(string $forPath = null): array;
} }

View file

@ -13,7 +13,6 @@ namespace DigiComp\Menu\MenuService;
*/ */
use Neos\Flow\Annotations as Flow; use Neos\Flow\Annotations as Flow;
use Neos\Flow\Configuration\ConfigurationManager;
/** /**
* @package DigiComp\Menu\Menu * @package DigiComp\Menu\Menu
@ -23,33 +22,24 @@ use Neos\Flow\Configuration\ConfigurationManager;
class SettingsService implements ServiceInterface class SettingsService implements ServiceInterface
{ {
/** /**
* @var \Neos\Flow\Configuration\ConfigurationManager * @Flow\InjectConfiguration(type="Menu")
* @var array
*/ */
protected $configurationManager; protected array $menuConfiguration;
public function injectConfigurationManager(ConfigurationManager $configurationManager)
{
$this->configurationManager = $configurationManager;
$this->menuConfiguration = $this->configurationManager->getConfiguration('Menu');
}
/** /**
* @var array * @var array
*/ */
protected $menuConfiguration; protected array $items = array();
/** /**
* @var array * @param string|null $forPath
*/
protected $items = array();
/**
* @param string $forMenu
* @return array * @return array
*/ */
public function getItems($forMenu = null) public function getItems(string $forPath = null): array
{ {
if ($forMenu) { if ($forPath) {
$items = &$this->menuConfiguration[$forMenu]; $items = &$this->menuConfiguration[$forPath];
} else { } else {
$items = &$this->menuConfiguration; $items = &$this->menuConfiguration;
} }

View file

@ -12,8 +12,10 @@ namespace DigiComp\Menu\ViewHelpers;
* source code. * source code.
*/ */
use DigiComp\Menu\MenuService\ServiceInterface;
use Neos\Flow\Annotations as Flow; use Neos\Flow\Annotations as Flow;
use Neos\FluidAdaptor\Core\ViewHelper\AbstractViewHelper; use Neos\FluidAdaptor\Core\ViewHelper\AbstractViewHelper;
use Neos\FluidAdaptor\Core\ViewHelper\Exception;
/** /**
* Just adds the return of MenuService * Just adds the return of MenuService
@ -24,11 +26,14 @@ class ItemsViewHelper extends AbstractViewHelper
protected $escapeOutput = false; protected $escapeOutput = false;
/** /**
* @var \DigiComp\Menu\MenuService\ServiceInterface
* @Flow\Inject * @Flow\Inject
* @var ServiceInterface
*/ */
protected $menuService; protected $menuService;
/**
* @throws Exception
*/
public function initializeArguments(): void public function initializeArguments(): void
{ {
$this->registerArgument('for', 'string', 'path in Menu.yaml', false); $this->registerArgument('for', 'string', 'path in Menu.yaml', false);
@ -36,9 +41,9 @@ class ItemsViewHelper extends AbstractViewHelper
} }
/** /**
* @return string * @return mixed
*/ */
public function render(): string public function render()
{ {
$this->templateVariableContainer->add( $this->templateVariableContainer->add(
$this->arguments['as'], $this->arguments['as'],

View file

@ -13,6 +13,7 @@ namespace DigiComp\Menu\ViewHelpers;
*/ */
use Neos\FluidAdaptor\Core\ViewHelper\AbstractViewHelper; use Neos\FluidAdaptor\Core\ViewHelper\AbstractViewHelper;
use Neos\FluidAdaptor\Core\ViewHelper\Exception;
/** /**
* Helps to get useful template variables for process menus * Helps to get useful template variables for process menus
@ -22,32 +23,37 @@ class ProgressViewHelper extends AbstractViewHelper
protected $escapeOutput = false; protected $escapeOutput = false;
/** /**
* TODO: initializeArguments * @throws Exception
* @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( public function initializeArguments(): void
array $links, {
$activeStep = 1, $this->registerArgument('for', 'string', 'path in Menu.yaml', false);
$returnable = true, $this->registerArgument('as', 'string', 'Name in Frontend', false);
$stepsAs = 'steps', $this->registerArgument('links', 'array', 'links to show', true);
$backLinkAs = 'backLink', $this->registerArgument('activeStep', 'int', 'current active link index', false, 1);
$activeStepAs = 'activeStep', $this->registerArgument('returnable', 'bool', 'can you go back to the last index', false, true);
$linksAs = 'links', $this->registerArgument('stepsAs', 'string', 'variable name of a single step', false, 'steps');
$activeStepLinkAs = 'activeStepLink', $this->registerArgument('backLinkAs', 'string', 'variable name of a backlink', false, 'backLink');
$offset = 1, $this->registerArgument('linksAs', 'string', 'variable name of the links array', false, 'links');
$linkCount = null $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);
//handling famous off by one //handling famous off by one
$activeStep -= $offset; $activeStep -= $offset;
//make sure our array index is numeric //make sure our array index is numeric