Last active
January 20, 2018 21:18
-
-
Save lorenzulrich/dc0ae2536a48160e9023df708e9582ca to your computer and use it in GitHub Desktop.
Neos CMS Eel Helper to get configuration of NodeTypes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# In this example, I want to render the same <select> box as a filter in the frontend I use to categorize a Node in the backend | |
@context.offerTypeSettings = ${Visol.NodeTypeConfigurationHelper.setting('My.FoobarCom:Document.Offer', 'properties.offerType.ui.inspector.editorOptions.values')} | |
offerTypes = Neos.Fusion:Collection { | |
collection = ${offerTypeSettings} | |
itemRenderer = ${'<option value="' + itemKey + '">' + item.label + '</option>'} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Visol\FoobarCom\Eel\Helper; | |
/* | |
* This file is part of the Neos.Eel package. | |
* | |
* (c) Contributors of the Neos Project - www.neos.io | |
* | |
* 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\Flow\Annotations as Flow; | |
use Neos\Eel\ProtectedContextAwareInterface; | |
use Neos\Flow\Configuration\ConfigurationManager; | |
/** | |
* Configuration helpers for Eel contexts | |
*/ | |
class NodeTypeConfigurationHelper implements ProtectedContextAwareInterface | |
{ | |
/** | |
* @Flow\Inject | |
* @var ConfigurationManager | |
*/ | |
protected $configurationManager; | |
/** | |
* Return the specified settings | |
* | |
* Examples:: | |
* | |
* NodeTypeConfiguration.setting('Neos.Flow.core.context') == 'Production' | |
* | |
* @param string $nodeType | |
* @param string $configurationPath | |
* @return mixed | |
*/ | |
public function setting($nodeType, $configurationPath = '') | |
{ | |
$nodeTypeDefinitions = $this->configurationManager->getConfiguration('NodeTypes'); | |
if (!array_key_exists($nodeType, $nodeTypeDefinitions)) { | |
return ''; | |
} | |
$nodeTypeDefinition = $nodeTypeDefinitions[$nodeType]; | |
$setting = \Neos\Utility\Arrays::getValueByPath($nodeTypeDefinition, $configurationPath); | |
return $setting; | |
} | |
/** | |
* All methods are considered safe | |
* | |
* @param string $methodName | |
* @return boolean | |
*/ | |
public function allowsCallOfMethod($methodName) | |
{ | |
return true; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
My.FoobarCom:Document.Offer: | |
properties: | |
offerType: | |
type: string | |
ui: | |
label: i18n | |
inspector: | |
group: offer | |
editor: 'Neos.Neos/Inspector/Editors/SelectBoxEditor' | |
editorOptions: | |
values: | |
type1: | |
label: 'Type 1' | |
type2: | |
label: 'Type 2' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Neos: | |
Fusion: | |
defaultContext: | |
'My.NodeTypeConfigurationHelper': 'Visol\FoobarCom\Eel\Helper\NodeTypeConfigurationHelper' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment