Last active
December 4, 2015 04:42
-
-
Save aertmann/d431234ed931e36a3f78 to your computer and use it in GitHub Desktop.
Auto create content inside main collection for new pages in Neos CMS
This file contains hidden or 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 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