Created
September 3, 2014 09:19
-
-
Save skurfuerst/33b403422f4fa2bf23f1 to your computer and use it in GitHub Desktop.
Neos Package.php - prepopulate content collection
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 TYPO3\Neos\NodeTypes; | |
/* * | |
* This script belongs to the TYPO3 Flow package "TYPO3.Neos". * | |
* * | |
* It is free software; you can redistribute it and/or modify it under * | |
* the terms of the GNU General Public License, either version 3 of the * | |
* License, or (at your option) any later version. * | |
* * | |
* The TYPO3 project - inspiring people to share! * | |
* */ | |
use TYPO3\Flow\Package\Package as BasePackage; | |
use TYPO3\TYPO3CR\Domain\Model\NodeInterface; | |
/** | |
* The TYPO3 Neos Package | |
*/ | |
class Package extends BasePackage { | |
/** | |
* @param \TYPO3\Flow\Core\Bootstrap $bootstrap The current bootstrap | |
* @return void | |
*/ | |
public function boot(\TYPO3\Flow\Core\Bootstrap $bootstrap) { | |
$dispatcher = $bootstrap->getSignalSlotDispatcher(); | |
$dispatcher->connect('TYPO3\TYPO3CR\Domain\Model\Node', 'nodeAdded', function(NodeInterface $node) use($bootstrap) { | |
// if we currently created ContentCollection "column0" inside parent "TwoColumn" ... | |
if ($node->getNodeType()->getName() === 'TYPO3.Neos:ContentCollection' | |
&& $node->getParent()->getNodeType()->getName() === 'TYPO3.Neos.NodeTypes:TwoColumn' | |
&& $node->getName() === 'column0') { | |
// ... then we check whether the defaultImage was created ... | |
$defaultImage = $node->getNode('defaultImage'); | |
if ($defaultImage === NULL) { | |
// ... and if not, create it. | |
/* @var $nodeTypeManager \TYPO3\TYPO3CR\Domain\Service\NodeTypeManager */ | |
$nodeTypeManager = $bootstrap->getObjectManager()->get('TYPO3\TYPO3CR\Domain\Service\NodeTypeManager'); | |
$node->createNode('defaultImage', $nodeTypeManager->getNodeType('TYPO3.Neos.NodeTypes:Image')); | |
} | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment