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']); }
private function getLinkProperties(Nextras\Orm\Repository\IRepository $repository) { return array_filter($repository->getEntityMetadata()->getProperties(), function (Nextras\Orm\Entity\Reflection\PropertyMetadata $propertyMetadata) { return $propertyMetadata->relationship && ($propertyMetadata->relationship->entity === Ytnuk\Link\Entity::class || is_subclass_of($propertyMetadata->relationship->entity, Ytnuk\Link\Entity::class)) && $propertyMetadata->relationship->type === Nextras\Orm\Entity\Reflection\PropertyRelationshipMetadata::ONE_HAS_ONE; }); }