protected function createComponentGrid() : Ytnuk\Grid\Control
{
$grid = new Ytnuk\Grid\Control(function (Nextras\Orm\Entity\IEntity $entity = NULL) {
if (!$entity) {
$entityClass = $this->repository->getEntityMetadata()->getClassName();
$entity = new $entityClass();
}
$form = $this->form->create($entity);
$form->onSubmit[] = function () {
$this->redirect('this');
};
return $form;
}, function (array $order, array $filter) {
return $this->repository->findBy($this->prepareValues($filter))->orderBy($this->prepareValues($order))->fetchPairs(current($this->repository->getEntityMetadata()->getPrimaryKey()));
});
return $grid->setLink(function ($entity) {
return $entity ? $this->getPresenter()->link('Presenter:edit', [current($this->repository->getEntityMetadata()->getPrimaryKey()) => $entity->id]) : $this->getPresenter()->link('Presenter:add');
})->filterInputs(['this']);
}