. */ namespace App\DataTables\Column; use Omines\DataTablesBundle\Column\AbstractColumn; use Symfony\Component\OptionsResolver\OptionsResolver; class IconLinkColumn extends AbstractColumn { /** * @inheritDoc */ public function normalize($value) { return $value; } public function configureOptions(OptionsResolver $resolver) { parent::configureOptions($resolver); $resolver->setDefaults([ 'icon' => 'fas fa-fw fa-edit', 'title' => null, 'href' => null, ]); $resolver->setAllowedTypes('title', ['null', 'string', 'callable']); $resolver->setAllowedTypes('icon', ['null', 'string', 'callable']); $resolver->setAllowedTypes('href', ['null', 'string', 'callable']); } public function render($value, $context) { $href = $this->getHref($value, $context); $icon = $this->getIcon($value, $context); $title = $this->getTitle($value, $context); if ($href !== null) { return sprintf( '', $href, $title, $icon ); } return ""; } protected function getHref($value, $context): ?string { $provider = $this->options['href']; if (is_string($provider)) { return $provider; } if (is_callable($provider)) { return call_user_func($provider, $value, $context); } return null; } protected function getIcon($value, $context): ?string { $provider = $this->options['icon']; if (is_string($provider)) { return $provider; } if (is_callable($provider)) { return call_user_func($provider, $value, $context); } return null; } protected function getTitle($value, $context): ?string { $provider = $this->options['title']; if (is_string($provider)) { return $provider; } if (is_callable($provider)) { return call_user_func($provider, $value, $context); } return null; } }