urlGenerator = $urlGenerator; } /** * Generates an URL to a page, where info about this entity can be viewed. * * @param $entity mixed The entity for which the info should be generated. * * @return string The URL to the info page * * @throws EntityNotSupported If the method is not supported for the given Entity */ public function infoURL($entity): string { if ($entity instanceof Part) { return $this->urlGenerator->generate('part_info', ['id' => $entity->getID()]); } //Otherwise throw an error throw new EntityNotSupported('The given entity is not supported yet!'); } public function editURL($entity): string { if ($entity instanceof Part) { return $this->urlGenerator->generate('part_edit', ['id' => $entity->getID()]); } //Otherwise throw an error throw new EntityNotSupported('The given entity is not supported yet!'); } public function createURL($entity): string { if ($entity instanceof Part) { return $this->urlGenerator->generate('part_new'); } throw new EntityNotSupported('The given entity is not supported yet!'); } public function cloneURL($entity): string { if ($entity instanceof Part) { return $this->urlGenerator->generate('part_clone', ['id' => $entity->getID()]); } throw new EntityNotSupported('The given entity is not supported yet!'); } /** * Generates an HTML link to the info page about the given entity. * * @param $entity mixed The entity for which the info link should be generated. * * @return string The HTML of the info page link * * @throws EntityNotSupported */ public function infoHTML($entity): string { $href = $this->infoURL($entity); if ($entity instanceof NamedDBElement) { return sprintf('%s', $href, $entity->getName()); } } }