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