em = $entityManager;
$this->entryRepository = $entityManager->getRepository(AbstractLogEntry::class);
$this->entityURLGenerator = $entityURLGenerator;
$this->elementTypeNameGenerator = $elementTypeNameGenerator;
$this->translator = $translator;
}
public function normalize($value)
{
return $value;
}
public function configureOptions(OptionsResolver $resolver)
{
parent::configureOptions($resolver);
return $this;
}
public function render($value, $context)
{
/** @var AbstractLogEntry $context */
$target = $this->entryRepository->getTargetElement($context);
//The element is existing
if ($target instanceof AbstractNamedDBElement) {
try {
return sprintf(
'%s',
$this->entityURLGenerator->infoURL($target),
$this->elementTypeNameGenerator->getTypeNameCombination($target, true)
);
} catch (EntityNotSupportedException $exception) {
return $this->elementTypeNameGenerator->getTypeNameCombination($target, true);
}
}
//Target does not have a name
if ($target instanceof AbstractDBElement) {
return sprintf(
'%s: %s',
$this->elementTypeNameGenerator->getLocalizedTypeLabel($target),
$target->getID()
);
}
//Element was deleted
if (null === $target && $context->hasTarget()) {
return sprintf(
'%s: %s [%s]',
$this->elementTypeNameGenerator->getLocalizedTypeLabel($context->getTargetClass()),
$context->getTargetID(),
$this->translator->trans('log.target_deleted')
);
}
//Log is not associated with an element
return '';
}
}