Skip to content

Instantly share code, notes, and snippets.

@skurfuerst
Created September 3, 2014 09:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save skurfuerst/33b403422f4fa2bf23f1 to your computer and use it in GitHub Desktop.
Save skurfuerst/33b403422f4fa2bf23f1 to your computer and use it in GitHub Desktop.
Neos Package.php - prepopulate content collection
<?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