diff --git a/src/DataTables/Column/EntityColumn.php b/src/DataTables/Column/EntityColumn.php index 517fb753..00f095f8 100644 --- a/src/DataTables/Column/EntityColumn.php +++ b/src/DataTables/Column/EntityColumn.php @@ -33,13 +33,25 @@ namespace App\DataTables\Column; use App\Entity\Base\NamedDBElement; +use App\Entity\Parts\Part; +use App\Services\EntityURLGenerator; use Omines\DataTablesBundle\Column\AbstractColumn; use Symfony\Component\OptionsResolver\Options; use Symfony\Component\OptionsResolver\OptionsResolver; +use Symfony\Component\PropertyAccess\PropertyAccessorInterface; class EntityColumn extends AbstractColumn { + protected $urlGenerator; + protected $accessor; + + public function __construct(EntityURLGenerator $URLGenerator, PropertyAccessorInterface $accessor) + { + $this->urlGenerator = $URLGenerator; + $this->accessor = $accessor; + } + /** * The normalize function is responsible for converting parsed and processed data to a datatables-appropriate type. * @@ -61,5 +73,19 @@ class EntityColumn extends AbstractColumn $resolver->setDefault('field', function (Options $option) { return $option['property'] . '.name'; }); + + $resolver->setDefault('render', function (Options $options) { + return function ($value, Part $context) use ($options) { + $entity = $this->accessor->getValue($context, $options['property']); + + if ($entity) { + return sprintf( + '%s', + $this->urlGenerator->listPartsURL($entity), + $value + ); + } + }; + }); } } \ No newline at end of file diff --git a/src/DataTables/PartsDataTable.php b/src/DataTables/PartsDataTable.php index 42e6f4b5..49a59679 100644 --- a/src/DataTables/PartsDataTable.php +++ b/src/DataTables/PartsDataTable.php @@ -142,7 +142,7 @@ class PartsDataTable implements DataTableTypeInterface ]) ->add('category', EntityColumn::class, [ 'label' => $this->translator->trans('part.table.category'), - 'property' => 'category' + 'property' => 'category', ]) ->add('footprint', EntityColumn::class, [ 'property' => 'footprint',