Last active
December 29, 2015 10:49
-
-
Save duskohu/7659704 to your computer and use it in GitHub Desktop.
BaseForm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Nas; | |
use Kdyby\BootstrapFormRenderer\BootstrapRenderer; | |
use NasExt\Forms\Controls\RangeSlider; | |
use NasExt\Templating\ITemplateFilesFormatter; | |
use Nette\Application\UI\Control; | |
use Nette\ComponentModel\IContainer; | |
use Nette\Forms\Controls\SuggestionInput; | |
use Nette\Latte\Engine; | |
use Nette\Templating\ITemplate; | |
use Nette\Templating\Template; | |
class BaseFormControl extends Control | |
{ | |
/** @var string */ | |
protected $templateFile; | |
/** @var ITemplateFilesFormatter */ | |
protected $templateFilesFormatter; | |
/** | |
* @param IContainer $parent | |
* @param string|null $name | |
*/ | |
public function __construct(IContainer $parent = NULL, $name = NULL) | |
{ | |
parent::__construct($parent, $name); | |
// SuggestionInput | |
SuggestionInput::register(); | |
// RangeSlider | |
RangeSlider::register(); | |
} | |
/** | |
* INJECT TemplateFilesFormatter | |
* @param ITemplateFilesFormatter $templateFilesFormatter | |
*/ | |
public function injectTemplateFilesFormatter(ITemplateFilesFormatter $templateFilesFormatter) | |
{ | |
$this->templateFilesFormatter = $templateFilesFormatter; | |
} | |
/** | |
* @param string $templateFile | |
* @return $this | |
*/ | |
public function setFileTemplate($templateFile) | |
{ | |
$this->templateFile = $templateFile; | |
return $this; | |
} | |
/** | |
* @param Template $template | |
*/ | |
public function templatePrepareFilters($template) | |
{ | |
/** @var Engine $latte */ | |
$latte = $this->getPresenter()->getContext()->createService('nette.latte'); | |
\Kdyby\BootstrapFormRenderer\Latte\FormMacros::install($latte->getCompiler()); | |
$template->registerFilter($latte); | |
} | |
/** | |
* @param string|NULL | |
* @return ITemplate | |
*/ | |
protected function createTemplate($class = NULL) | |
{ | |
$template = parent::createTemplate($class); | |
$template->_form = $template->form = $this['form']; | |
// Implementacia \Kdyby\BootstrapFormRenderer | |
$this['form']->setRenderer(new BootstrapRenderer()); | |
$template->setFile($this->templateFilesFormatter(....)); | |
return $template; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Nas; | |
use ... | |
class BlockFormControl extends BaseFormControl | |
{ | |
/** @var BlockRepository */ | |
private $blockRepository; | |
/** @var ActiveRow */ | |
private $blockEntity; | |
/** | |
* @param BlockRepository $blockRepository | |
*/ | |
public function __construct(BlockRepository $blockRepository | |
{ | |
parent::__construct(); | |
$this->blockRepository = $blockRepository; | |
} | |
/** | |
* setBlockEntity | |
* @param bool|ActiveRow $blockEntity | |
* @return BlockFormControl provides fluent interface | |
*/ | |
public function setBlockEntity($blockEntity = FALSE) | |
{ | |
$this->blockEntity = $blockEntity; | |
return $this; | |
} | |
/** | |
* FORM block | |
* @return Form | |
*/ | |
protected function createComponentForm() | |
{ | |
$form = new Form; | |
...... | |
return $form; | |
} | |
/** | |
* PROCESS-SUBMIT-ADD-FORM - add new block | |
* @param Form $form | |
*/ | |
public function processAddSubmit(Form $form) | |
{ | |
..... | |
} | |
/** | |
* PROCESS-SUBMIT-EDIT-FORM - edit block item | |
* @param Form $form | |
*/ | |
public function processEditSubmit(Form $form) | |
{ | |
..... | |
} | |
/** | |
* HANDLE - DeleteBlock | |
*/ | |
public function handleDeleteBlock() | |
{ | |
..... | |
} | |
/** | |
* RENDER | |
*/ | |
public function render() | |
{ | |
$this->template->blockEntity = $this->blockEntity; | |
$this->template->render(); | |
} | |
} | |
/** | |
* IBlockFormControl | |
*/ | |
interface IBlockFormControl | |
{ | |
/** | |
* @return BlockFormControl | |
*/ | |
function create(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment