diff --git a/assets/controllers/dropdown.js b/assets/controllers/dropdown.js deleted file mode 100644 index abbefd06..00000000 --- a/assets/controllers/dropdown.js +++ /dev/null @@ -1,15 +0,0 @@ -import {Controller} from '@hotwired/stimulus' - -export default class extends Controller { - static values = { - toggledClass: { type: String, default: 'show' }, - } - - static targets = [ - 'content', - ]; - - toggle() { - this.contentTarget.classList.toggle(this.toggledClassValue) - } -} diff --git a/assets/package.json b/assets/package.json index afcc6e62..36305897 100755 --- a/assets/package.json +++ b/assets/package.json @@ -19,11 +19,6 @@ "main": "controllers/state.js", "fetch": "eager", "enabled": true - }, - "dropdown": { - "main": "controllers/dropdown.js", - "fetch": "eager", - "enabled": true } }, "importmap": { diff --git a/src/Action/Type/Dropdown/DropdownActionType.php b/src/Action/Type/Dropdown/DropdownActionType.php index 146365f0..2d1d027a 100644 --- a/src/Action/Type/Dropdown/DropdownActionType.php +++ b/src/Action/Type/Dropdown/DropdownActionType.php @@ -8,6 +8,8 @@ use Kreyu\Bundle\DataTableBundle\Action\ActionInterface; use Kreyu\Bundle\DataTableBundle\Action\ActionView; use Kreyu\Bundle\DataTableBundle\Action\Type\AbstractActionType; +use Kreyu\Bundle\DataTableBundle\Column\ColumnValueView; +use Kreyu\Bundle\DataTableBundle\Exception\UnexpectedTypeException; use Symfony\Component\OptionsResolver\OptionsResolver; class DropdownActionType extends AbstractActionType @@ -15,8 +17,18 @@ class DropdownActionType extends AbstractActionType public function buildView(ActionView $view, ActionInterface $action, array $options): void { $itemActions = []; - /** @var ActionBuilderInterface $itemActionBuilder */ + + if (is_callable($options['actions']) && $view->parent instanceof ColumnValueView) { + $options['actions'] = $options['actions']($view->parent->value); + } + foreach ($options['actions'] as $itemActionBuilder) { + if (!$itemActionBuilder instanceof ActionBuilderInterface) { + throw new UnexpectedTypeException($itemActionBuilder, ActionBuilderInterface::class); + } + + $itemActionBuilder->setContext($action->getConfig()->getContext()); + $itemAction = $itemActionBuilder->getAction(); $itemAction->setDataTable($action->getDataTable()); @@ -29,7 +41,7 @@ public function buildView(ActionView $view, ActionInterface $action, array $opti public function configureOptions(OptionsResolver $resolver): void { $resolver->define('actions') - ->allowedTypes(ActionBuilderInterface::class.'[]') + ->allowedTypes(ActionBuilderInterface::class.'[]', 'callable') ->required() ; } diff --git a/src/Resources/views/themes/base.html.twig b/src/Resources/views/themes/base.html.twig index cd8796a5..cd46160d 100755 --- a/src/Resources/views/themes/base.html.twig +++ b/src/Resources/views/themes/base.html.twig @@ -633,14 +633,13 @@ {% endblock %} {% block action_dropdown_control %} -