1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77:
<?php
declare(strict_types=1);
namespace App\ConfigModule\Forms;
use App\ConfigModule\Model\MainManager;
use App\ConfigModule\Presenters\MainPresenter;
use App\Forms\FormFactory;
use Nette;
use Nette\Application\UI\Form;
class ConfigMainFormFactory {
use Nette\SmartObject;
private $manager;
private $factory;
public function __construct(FormFactory $factory, MainManager $manager) {
$this->manager = $manager;
$this->factory = $factory;
}
public function create(MainPresenter $presenter) {
$form = $this->factory->create();
$items = ['forwarding' => 'Forwarding', 'operational' => 'Operational', 'service' => 'Service'];
$form->addText('Configuration', 'Configuration');
$form->addText('ConfigurationDir', 'ConfigurationDir');
$form->addInteger('WatchDogTimeoutMilis', 'WatchDogTimeoutMilis');
$form->addSelect('Mode', 'Mode', $items);
$form->addSubmit('save', 'Save');
$form->setDefaults($this->manager->load());
$form->addProtection('Timeout expired, resubmit the form.');
$form->onSuccess[] = function (Form $form, $values) use ($presenter) {
$this->manager->save($values);
$presenter->redirect('Homepage:default');
};
return $form;
}
}