Nastaveni translatoru sablonam automaticky

dehtak
Člen | 113
+
0
-

zdravim ,
pokousim se toto

services:
	oldTemplateFactory:
		create: Nette\Bridges\ApplicationLatte\TemplateFactory
		autowired: false
	latte.templateFactory: TempTranslatorFactory (@oldTemplateFactory)
use Nette\Application\UI\ITemplateFactory,
    Nette\Application\UI\Control,
    Nette\Application\UI\ITemplate;

class TempTranslatorFactory implements ITemplateFactory
{
	private $templateFactory;
	private $translator;

	public function __construct(ITemplateFactory $templateFactory, Translator $translator)
	{
		$this->templateFactory = $templateFactory;
                $this->translator = $translator;

	}

	function createTemplate(Control $control = null): ITemplate
	{
		$template = $this->templateFactory->createTemplate($control);
		$template->setTranslator($this->translator);

		return $template;
	}
}

predelat do extension , mam to takhle

class Extension extends CompilerExtension {
	public function loadConfiguration() {
  				$builder = $this->getContainerBuilder();
 				$builder->addDefinition('oldTemplateFactory')
                        ->setClass('Nette\Bridges\ApplicationLatte\TemplateFactory')
                        ->setAutowired(FALSE);
                $builder->addDefinition('newlatteFactory')
                        ->setFactory(TempTranslatorFactory::class,['@oldTemplateFactory','@translator' ]);
	}
}

Asi delam neco blbe porad mi to pise

Service 'application.1' (type of Admin\Presenter\FilePresenter): Multiple services of type Nette\Application\UI\ITemplateFactory found: latte.templateFactory, newlatteFactory. If you want to overwrite service latte.templateFactory, give it proper name. (needed by $templateFactory in Nette\Application\UI\Presenter::injectPrimary())

kdyz to udelam prez neon tak to funguje

Editoval dehtak (1. 5. 2020 22:12)

dehtak
Člen | 113
+
0
-

vyreseno, diky za odpovedi !!

	public function beforeCompile(): void {
$builder = $this->getContainerBuilder();
$tempDefinition = $builder->addDefinition('oldTemplateFactory');
$tempDefinition->setClass('Nette\Bridges\ApplicationLatte\TemplateFactory');
$tempDefinition->setAutowired(FALSE);

$builder->addDefinition('newLatteFactory')
        ->setFactory(TempTranslatorFactory::class,['@oldTemplateFactory','@translator' ])->setAutowired(TRUE);
	}

Nevim proc ale ted to funguje