contributte / forms-multiplier

:repeat: Form multiplier & replicator for Nette Framework
https://contributte.org/packages/contributte/forms-multiplier.html
MIT License
26 stars 21 forks source link

WIP: Custom container #36

Closed kravcik closed 5 years ago

kravcik commented 5 years ago

Do you think this need deeper look? I don't think function addCustomContainer($form, $name) is necessary - better option would be add customForm and implement this function there.

This can be temporary solution.

MartkCz commented 5 years ago

Change to customForm (Form responsibility create custom container)?

But how? the only solution that comes to mind: create interface IFormContainerProvider, form implements the interface and multiplier checks if form implement interface...

kravcik commented 5 years ago

I just have a "strange" feeling about function (addCustomContainer()). Thats all. Origin idea was something like this.

protected function applyDefaultValues(Container $container) {
        $form = new CustomForm('_foo_multiplier');
        $factoryContainer = $form->addContainer('foo'); //return customContainer

Btw atm it's works well with custom Form and container.

$form = new customForm;
$form->addMultiplier('m', function($container, $form)
{
  $form->addWhisperer();
});

Should I prepare test for this solution?

MartkCz commented 5 years ago

how about

trait TFormComponents {
    public function addContainer(...) {
    // returns CustomContainer
    }

    public function addMultiplier(...) {
    // returns CustomMultiplier
    }

}
class CustomMultiplier extends Multiplier {
    use TFormComponents;
}
class CustomForm extends Form {
    use TFormComponents;
}
class CustomContainer extends Container {
    use TFormComponents;
}
kravcik commented 5 years ago

Good idea. So I guess I will this implement outside multiplier. Should I close this?

MartkCz commented 5 years ago

Thank you for your time :)