Skip to content

Instantly share code, notes, and snippets.

@aertmann
Last active December 4, 2015 04:42
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 aertmann/d431234ed931e36a3f78 to your computer and use it in GitHub Desktop.
Save aertmann/d431234ed931e36a3f78 to your computer and use it in GitHub Desktop.
Auto create content inside main collection for new pages in Neos CMS
<?php
namespace Acme\Demo;
use TYPO3\Flow\Package\Package as BasePackage;
use TYPO3\TYPO3CR\Domain\Model\NodeInterface;
class Package extends BasePackage {
/**
* @var \TYPO3\TYPO3CR\Domain\Service\NodeTypeManager nodeTypeManager
*/
protected $nodeTypeManager;
/**
* @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) {
/** @var \TYPO3\TYPO3CR\Domain\Service\NodeTypeManager nodeTypeManager */
$this->nodeTypeManager = $bootstrap->getObjectManager()->get('TYPO3\TYPO3CR\Domain\Service\NodeTypeManager');
// if we currently created ContentCollection "main" inside parent "Page" ...
if ($node->getName() === 'main'
&& $node->getNodeType()->getName() === 'TYPO3.Neos:ContentCollection'
&& $node->getParent()
&& $node->getParent()->getNodeType()->getName() === 'Acme:Page') {
$node->createNode(uniqid('node'), $this->nodeTypeManager->getNodeType('Acme.Demo:Teaser'));
}
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment