Skip to content

Commit

Permalink
[SonataExtraBundle] Show prevent delete support no stringnable
Browse files Browse the repository at this point in the history
  • Loading branch information
mpoiriert committed Nov 17, 2023
1 parent b68bd03 commit 6a85908
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<table class="table table-bordered table-striped table-hover sonata-ba-list">
{% for related_entity in related_entities %}
<tr>
<td>{{ related_entity }}</td>
<td>{{ related_entity|entity_to_string }}</td>
{% if related_admin %}
<td>
<div class="btn-group">
Expand Down
26 changes: 26 additions & 0 deletions packages/sonata-extra-bundle/Twig/EntityTwigExtension.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace Draw\Bundle\SonataExtraBundle\Twig;

use Doctrine\Common\Util\ClassUtils;
use Twig\Extension\AbstractExtension;
use Twig\TwigFilter;

class EntityTwigExtension extends AbstractExtension
{
public function getFilters(): array
{
return [
new TwigFilter('entity_to_string', [$this, 'entityToString']),
];
}

public function entityToString($entity): string
{
if (method_exists($entity, '__toString')) {
return (string) $entity;
}

return sprintf('%s:%s', ClassUtils::getClass($entity), spl_object_hash($entity));
}
}

0 comments on commit 6a85908

Please sign in to comment.