Created
November 23, 2016 09:06
-
-
Save sbruggmann/53d73f02c2046dbcefcdb4529318c1d5 to your computer and use it in GitHub Desktop.
not properly working (!) solution for neos nodetype property inheritance
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
'WebExcess.AtomicTypes:NodeTypePostprocessor': | |
abstract: true | |
postprocessors: | |
# Allow `'myProperty < propertyTemplate': []` and `'useless >': []` directives in yaml NodeType Configuration.. | |
WebExcessNodeTypePostprocessor: | |
postprocessor: 'WebExcess\AtomicTypes\NodeTypePostprocessor\WebExcessNodeTypePostprocessor' | |
postprocessorOptions: | |
segments: | |
- 'childNodes' | |
- 'properties' | |
autoRemoveAtomProperties: false |
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 WebExcess\AtomicTypes\NodeTypePostprocessor; | |
use TYPO3\Flow\Annotations as Flow; | |
use TYPO3\Flow\Configuration\ConfigurationManager; | |
use TYPO3\TYPO3CR\Domain\Model\NodeType; | |
use TYPO3\TYPO3CR\NodeTypePostprocessor\NodeTypePostprocessorInterface; | |
/** | |
* NodeTypePostprocessor | |
*/ | |
class WebExcessNodeTypePostprocessor implements NodeTypePostprocessorInterface | |
{ | |
/** | |
* @var ConfigurationManager | |
* @Flow\Inject | |
*/ | |
protected $configurationManager; | |
/** | |
* @var boolean | |
*/ | |
protected $autoRemoveAtomProperties; | |
/** | |
* Returns the processed Configuration | |
* | |
* @param \TYPO3\TYPO3CR\Domain\Model\NodeType $nodeType (uninitialized) The node type to process | |
* @param array $configuration input configuration | |
* @param array $options The processor options | |
* @return void | |
*/ | |
public function process(NodeType $nodeType, array &$configuration, array $options) | |
{ | |
if (is_array($options) && array_key_exists('segments', $options)) { | |
$this->autoRemoveAtomProperties = is_array($options) && array_key_exists('autoRemoveAtomProperties', $options) && is_bool($options['autoRemoveAtomProperties']) ? $options['autoRemoveAtomProperties'] : false; | |
foreach ($options['segments'] as $segment) { | |
$this->walkTreeSegment($nodeType, $configuration, $options, $segment); | |
} | |
} | |
} | |
/** | |
* Returns the by tree segment processed Configuration | |
* | |
* @param \TYPO3\TYPO3CR\Domain\Model\NodeType $nodeType (uninitialized) The node type to process | |
* @param array $configuration input configuration | |
* @param array $options The processor options | |
* @param string $segment The tree segment to process | |
* @return void | |
*/ | |
private function walkTreeSegment(NodeType &$nodeType, array &$configuration, array &$options, $segment) { | |
if (array_key_exists($segment, $configuration)) { | |
foreach ($configuration[$segment] as $propertyName => $propertyValues) { | |
if (strpos($propertyName, ' < ')!==false) { | |
$exploded = explode(' < ', $propertyName); | |
if (count($exploded) == 2) { | |
$configuration[$segment][$exploded[0]] = \TYPO3\Flow\Utility\Arrays::arrayMergeRecursiveOverrule($configuration[$segment][$exploded[1]], | |
$configuration[$segment][$propertyName]); | |
unset($configuration[$segment][$propertyName]); | |
} | |
} | |
} | |
foreach ($configuration[$segment] as $propertyName => $propertyValues) { | |
if (strpos($propertyName, ' >')!==false) { | |
$propertyToRemove = substr($propertyName, 0, -2); | |
unset($configuration[$segment][$propertyToRemove]); | |
unset($configuration[$segment][$propertyName]); | |
}else if ($this->autoRemoveAtomProperties) { | |
if (strpos($propertyName, 'Atom_')!==false) { | |
$propertyToRemove = $propertyName; | |
unset($configuration[$segment][$propertyToRemove]); | |
unset($configuration[$segment][$propertyName]); | |
} | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment