/** * Inject the dependencies. * * @param InitializeNodeEvent $event The event. * * @return void */ public function injectDependencies(InitializeNodeEvent $event) { $node = $event->getNode(); if ($node instanceof TranslatorAware && !$node->getTranslator()) { $node->setTranslator($this->getServiceContainer()->getTranslator()); } if ($node instanceof DefinitionAware && !$node->getDefinition()) { $node->setDefinition($this->getServiceContainer()->getDcaManager()->get('tl_content')); } }
/** * Create a node. * * @param string $type The node type. * * @return Node * * @throws \InvalidArgumentException When node type is not configured. * @throws \RuntimeException When no node type could be created. */ public function create($type) { if (!isset($this->configs[$type])) { throw new \InvalidArgumentException(sprintf('Unknown node type "%s"', $type)); } $event = new CreateNodeEvent($type, $this->configs[$type]); $this->dispatcher->dispatch($event::NAME, $event); if ($event->getFactory()) { $node = call_user_func($event->getFactory(), $event->getType(), $event->getConfig()); } elseif ($event->getClassName()) { $className = $event->getClassName(); $node = new $className($type, $event->getConfigValue('children')); } else { throw new \RuntimeException(sprintf('Could not create node "%s"', $type)); } $event = new InitializeNodeEvent($node, $event->getConfig()); $this->dispatcher->dispatch($event::NAME, $event); return $node; }