protected function prepareEntity(Entity $entity) { /** @var \EvaCatalog\Entity\Attribute $entity */ if (!$entity->getCategory()) { if (!$this->getServiceManager()->getRouter()->getParams()->exists('id')) { $this->getServiceManager()->getRouter()->notFound(); } $categoryId = $this->getServiceManager()->getRouter()->getParams()->get('id'); /** @var \EvaCatalog\Entity\Category $category */ $category = $this->getCategoryRepository()->find($categoryId); $entity->setCategory($category); } parent::prepareEntity($entity); }