diff --git a/Classes/MenuService/ServiceInterface.php b/Classes/MenuService/ServiceInterface.php index cedac82..f72e77a 100644 --- a/Classes/MenuService/ServiceInterface.php +++ b/Classes/MenuService/ServiceInterface.php @@ -18,9 +18,9 @@ namespace DigiComp\Menu\MenuService; interface ServiceInterface { /** - * @param mixed $forPath + * @param string|null $forPath * * @return array|\Iterator */ - public function getItems($forPath = null); + public function getItems(string $forPath = null): array; } diff --git a/Classes/MenuService/SettingsService.php b/Classes/MenuService/SettingsService.php index f01427e..5e3c814 100644 --- a/Classes/MenuService/SettingsService.php +++ b/Classes/MenuService/SettingsService.php @@ -13,7 +13,6 @@ namespace DigiComp\Menu\MenuService; */ use Neos\Flow\Annotations as Flow; -use Neos\Flow\Configuration\ConfigurationManager; /** * @package DigiComp\Menu\Menu @@ -23,33 +22,24 @@ use Neos\Flow\Configuration\ConfigurationManager; class SettingsService implements ServiceInterface { /** - * @var \Neos\Flow\Configuration\ConfigurationManager + * @Flow\InjectConfiguration(type="Menu") + * @var array */ - protected $configurationManager; - public function injectConfigurationManager(ConfigurationManager $configurationManager) - { - $this->configurationManager = $configurationManager; - $this->menuConfiguration = $this->configurationManager->getConfiguration('Menu'); - } + protected array $menuConfiguration; /** * @var array */ - protected $menuConfiguration; + protected array $items = array(); /** - * @var array - */ - protected $items = array(); - - /** - * @param string $forMenu + * @param string|null $forPath * @return array */ - public function getItems($forMenu = null) + public function getItems(string $forPath = null): array { - if ($forMenu) { - $items = &$this->menuConfiguration[$forMenu]; + if ($forPath) { + $items = &$this->menuConfiguration[$forPath]; } else { $items = &$this->menuConfiguration; } diff --git a/Classes/ViewHelpers/ItemsViewHelper.php b/Classes/ViewHelpers/ItemsViewHelper.php index 59c1160..12ed9a9 100644 --- a/Classes/ViewHelpers/ItemsViewHelper.php +++ b/Classes/ViewHelpers/ItemsViewHelper.php @@ -12,8 +12,10 @@ namespace DigiComp\Menu\ViewHelpers; * source code. */ +use DigiComp\Menu\MenuService\ServiceInterface; use Neos\Flow\Annotations as Flow; use Neos\FluidAdaptor\Core\ViewHelper\AbstractViewHelper; +use Neos\FluidAdaptor\Core\ViewHelper\Exception; /** * Just adds the return of MenuService @@ -24,11 +26,14 @@ class ItemsViewHelper extends AbstractViewHelper protected $escapeOutput = false; /** - * @var \DigiComp\Menu\MenuService\ServiceInterface * @Flow\Inject + * @var ServiceInterface */ protected $menuService; + /** + * @throws Exception + */ public function initializeArguments(): void { $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->arguments['as'], diff --git a/Classes/ViewHelpers/ProgressViewHelper.php b/Classes/ViewHelpers/ProgressViewHelper.php index ce5f7e4..33a7e01 100644 --- a/Classes/ViewHelpers/ProgressViewHelper.php +++ b/Classes/ViewHelpers/ProgressViewHelper.php @@ -13,6 +13,7 @@ namespace DigiComp\Menu\ViewHelpers; */ use Neos\FluidAdaptor\Core\ViewHelper\AbstractViewHelper; +use Neos\FluidAdaptor\Core\ViewHelper\Exception; /** * Helps to get useful template variables for process menus @@ -22,32 +23,37 @@ 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 + * @throws Exception */ - public function render( - array $links, - $activeStep = 1, - $returnable = true, - $stepsAs = 'steps', - $backLinkAs = 'backLink', - $activeStepAs = 'activeStep', - $linksAs = 'links', - $activeStepLinkAs = 'activeStepLink', - $offset = 1, - $linkCount = null - ) { + 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); //handling famous off by one $activeStep -= $offset; //make sure our array index is numeric