Skip to content

Instantly share code, notes, and snippets.

@sbruggmann
Created November 23, 2016 09:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sbruggmann/53d73f02c2046dbcefcdb4529318c1d5 to your computer and use it in GitHub Desktop.
Save sbruggmann/53d73f02c2046dbcefcdb4529318c1d5 to your computer and use it in GitHub Desktop.
not properly working (!) solution for neos nodetype property inheritance
'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
<?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