diff --git a/src/Container.php b/src/Container.php index 7c27703..6b2dfda 100644 --- a/src/Container.php +++ b/src/Container.php @@ -437,9 +437,10 @@ public function addComponent(IComponent $component, $name, $insertBefore = null) /** * @param string $methodName + * @param string $containerClass * @return void */ - public static function register(string $methodName = 'addDynamic') + public static function register(string $methodName = 'addDynamic', string $containerClass = '\Nette\Forms\Container') { if (self::$registered) { \Nette\Forms\Container::extensionMethod(self::$registered, function () { @@ -447,9 +448,10 @@ public static function register(string $methodName = 'addDynamic') }); } - \Nette\Forms\Container::extensionMethod($methodName, function (\Nette\Forms\Container $_this, $name, $factory, $createDefault = 0, $forceDefault = false) { + \Nette\Forms\Container::extensionMethod($methodName, function (\Nette\Forms\Container $_this, $name, $factory, $createDefault = 0, $forceDefault = false) use ($containerClass) { $control = new Container($factory, $createDefault, $forceDefault); $control->currentGroup = $_this->currentGroup; + $control->containerClass = $containerClass; return $_this[$name] = $control; }); diff --git a/src/DI/ReplicatorExtension.php b/src/DI/ReplicatorExtension.php index 85695be..5ce55ec 100644 --- a/src/DI/ReplicatorExtension.php +++ b/src/DI/ReplicatorExtension.php @@ -5,6 +5,7 @@ use Nette\Configurator; use Nette\DI\Compiler; use Nette\DI\CompilerExtension; +use Nette\Forms\Container; use Nette\PhpGenerator\ClassType; /** @@ -13,6 +14,15 @@ */ class ReplicatorExtension extends CompilerExtension { + private const DEFAULTS = [ + 'methodName' => 'addDynamic', + 'containerClass' => '\Nette\Forms\Container', + ]; + + public function loadConfiguration() + { + $this->validateConfig(self::DEFAULTS); + } /** * @param ClassType $class @@ -22,7 +32,10 @@ public function afterCompile(ClassType $class) parent::afterCompile($class); $init = $class->getMethod('initialize'); - $init->addBody('\Webwings\Replicator\Container::register();'); + $init->addBody("\Webwings\Replicator\Container::register(?, ?);", [ + $this->config['methodName'], + $this->config['containerClass'], + ]); }