Do not throw an exception during rendering of log detail page, if element has no time travel URL

This commit is contained in:
Jan Böhmer 2023-06-06 23:15:14 +02:00
parent e68827bf3b
commit efc152e3c8
3 changed files with 18 additions and 5 deletions

View file

@ -34,6 +34,7 @@ use App\Entity\Parts\Supplier;
use App\Entity\PriceInformations\Currency;
use App\Entity\UserSystem\Group;
use App\Entity\UserSystem\User;
use App\Exceptions\EntityNotSupportedException;
use App\Services\ElementTypeNameGenerator;
use App\Services\EntityURLGenerator;
use App\Services\Trees\TreeViewGenerator;
@ -72,7 +73,7 @@ final class EntityExtension extends AbstractExtension
/* Returns the URL to the given entity */
new TwigFunction('entity_url', [$this, 'generateEntityURL']),
/* Returns the URL to the given entity in timetravel mode */
new TwigFunction('timetravel_url', [$this->entityURLGenerator, 'timetravelURL']),
new TwigFunction('timetravel_url', [$this, 'timeTravelURL']),
/* Generates a JSON array of the given tree */
new TwigFunction('tree_data', [$this, 'treeData']),
@ -81,6 +82,15 @@ final class EntityExtension extends AbstractExtension
];
}
public function timeTravelURL(AbstractDBElement $element, \DateTimeInterface $dateTime): ?string
{
try {
return $this->entityURLGenerator->timeTravelURL($element, $dateTime);
} catch (EntityNotSupportedException $e) {
return null;
}
}
public function treeData(AbstractDBElement $element, string $type = 'newEdit'): string
{
$tree = $this->treeBuilder->getTreeView(get_class($element), null, $type, $element);