Initial Menu Functions (originally found in DigiComp.Controls)

This commit is contained in:
Sascha Kötzing 2014-07-07 15:49:44 +02:00
parent d0d1541344
commit 6301329853
5 changed files with 125 additions and 0 deletions

View file

@ -0,0 +1,15 @@
<?php
namespace DigiComp\Menu\MenuService;
/* *
* This script belongs to the FLOW3 package "DigiComp.Controls". *
* *
* */
/**
* Interface for Menu-Configuration
*/
interface ServiceInterface {
public function getItems();
}

View file

@ -0,0 +1,53 @@
<?php
namespace DigiComp\Menu\MenuService;
/* *
* This script belongs to the FLOW3 package "DigiComp.Controls". *
* *
* */
use TYPO3\Flow\Annotations as Flow;
use TYPO3\Flow\Configuration\ConfigurationManager;
/**
* Class Menu
* @package DigiComp\Controls\Menu
*
* @Flow\Scope("singleton")
*/
class SettingsService implements ServiceInterface {
/**
* @var \TYPO3\Flow\Configuration\ConfigurationManager
*/
protected $configurationManager;
public function injectConfigurationManager(ConfigurationManager $configurationManager) {
$this->configurationManager = $configurationManager;
$this->menu = $this->configurationManager->getConfiguration('Menu');
}
/**
* @var array
*/
protected $menu;
protected $items = array();
/**
* @param string $forMenu
* @return array
*/
public function getItems($forMenu = NULL) {
if ($forMenu){
$items = &$this->menu[$forMenu];
}else {
$items = &$this->menu;
}
if ($items) {
uasort($items, function ($a, $b) {
return $a['sorting'] > $b['sorting'];
});
}
return $items;
}
}

View file

@ -0,0 +1,25 @@
<?php
/**
* @author skoetzing
* @date 07.07.14
*/
namespace DigiComp\Menu;
use TYPO3\Flow\Core\Bootstrap;
use TYPO3\Flow\Package\Package as BasePackage;
use TYPO3\Flow\Annotations as Flow;
use TYPO3\Flow\Configuration\ConfigurationManager;
class Package extends BasePackage{
public function boot(Bootstrap $bootstrap){
parent::boot($bootstrap);
$dispatcher = $bootstrap->getSignalSlotDispatcher();
$dispatcher->connect('TYPO3\Flow\Configuration\ConfigurationManager', 'configurationManagerReady',
function(ConfigurationManager $configurationManager){
$configurationManager->registerConfigurationType('Menu');
});
}
}

View file

@ -0,0 +1,30 @@
<?php
namespace DigiComp\Menu\ViewHelpers;
/* *
* This script belongs to the FLOW3 package "DigiComp.Controls". *
* *
* */
use TYPO3\Flow\Annotations as Flow;
/**
* Renders the sum of given collection and property name
*/
class MenuViewHelper extends \TYPO3\Fluid\Core\ViewHelper\AbstractViewHelper {
/**
* @var \DigiComp\Menu\MenuService\ServiceInterface
* @Flow\Inject
*/
protected $menuService;
/**
* @param string $as
* @param string $forPath
* @return mixed
*/
public function render($as = 'menuItems', $forPath = NULL) {
$this->templateVariableContainer->add($as, $this->menuService->getItems($forPath));
return $this->renderChildren();
}
}
?>

View file

@ -0,0 +1,2 @@
DigiComp\Controls\Menu\ServiceInterface:
className: DigiComp\Controls\Menu\SettingsService