Skip to content

Commit

Permalink
[SonataExtraBundle] Improve AutoActionExtension to detect if actions …
Browse files Browse the repository at this point in the history
…exist (#267)
  • Loading branch information
DumitracheAdrian authored May 20, 2024
1 parent d59cf2b commit d525f33
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions packages/sonata-extra-bundle/Extension/AutoActionExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,24 @@ public function configureListFields(ListMapper $list): void
}
}

$list->add(
ListMapper::NAME_ACTIONS,
ListMapper::TYPE_ACTIONS,
[
'label' => 'Action',
'actions' => $this->actions,
]
);
$actions = [];
$routes = $admin->getRoutes();

foreach ($this->actions as $action => $options) {
if ($routes->has($routes->getCode($action))) {
$actions[$action] = $options;
}
}

if (!empty($actions)) {
$list->add(
ListMapper::NAME_ACTIONS,
ListMapper::TYPE_ACTIONS,
[
'label' => 'Action',
'actions' => $actions,
]
);
}
}
}

0 comments on commit d525f33

Please sign in to comment.