nextras/forms

Nette 2.4 compatibility

Closed this issue · 7 comments

hrach commented

Well, this should be imo reported into the Nette issue tracker. I can't see why totally standard call should be "BC breaked".

$me->addMacro('label', array($me, 'macroLabel'), array($me, 'macroLabelEnd'));
hrach commented

@dg isn't possible to fix this on Nette side?

hrach commented

If I remember it corectly, addMacro was forpushed,so the impl. may be a mistake.

dg commented

It should be compatible, i.e. flag is optional. Is your macro registered before/after/instead of default macros?

ie. this seems https://github.com/nextras/forms/blob/master/src/DI/FormsExtension.php#L30 that macros are registered each time template is rendered, not only when is compiled.

@hrach Check dg commet. Maybe it is solution. Now I am stuck on "Incompatible flags for macro label".

hrach commented

Will try asap!

I must test it but it is looks like FormsExtension register Macro different way then LatteExtension:

If is loaded FormsExtension and in config.neon is latte.macros: [Nextras\Forms\Bridges\Latte\Macros\BS3InputMacros]

public function create()
    {
        $service = new Latte\Engine;
        $service->setTempDirectory('/var/www/app/../temp/cache/latte');
        $service->setAutoRefresh(TRUE);
        $service->setContentType('html');
        Nette\Utils\Html::$xhtml = FALSE;
//by Latte
        $service->onCompile[] = function ($engine) { Nextras\Forms\Bridges\Latte\Macros\BS3InputMacros::install($engine->getCompiler()); };
//by Nextras
        Nextras\Forms\Bridges\Latte\Macros\BS3InputMacros::install($service->getCompiler());
        return $service;
    }

I found this two possibility to solve this, both edit FormExtension::beforeCompile, but I do not know which is better/right. Both do the same, but different way:

public function beforeCompile()
    {
        parent::beforeCompile();

        $latteExtensionArray = $this->compiler->getExtensions(Nette\Bridges\ApplicationDI\LatteExtension::class);
        /** @var Nette\Bridges\ApplicationDI\LatteExtension $latteExtension */
        $latteExtension = reset($latteExtensionArray);
        $latteExtension->addMacro('Nextras\Forms\Bridges\Latte\Macros\BS3InputMacros::install');
    }
public function beforeCompile()
    {
        parent::beforeCompile();

        $builder = $this->getContainerBuilder();

        $builder->getDefinition('nette.latteFactory')
            ->addSetup('?->onCompile[] = function ($engine) { Nextras\Forms\Bridges\Latte\Macros\BS3InputMacros::install($engine->getCompiler());};', ['@self']);
    }

I send PR if you say which you prefer, one use knowledge of LatteExtension, second use knowledge into FormsExtension how Latte works and how it register macros.