Skip to content

Commit

Permalink
Improve AutoActionExtension to detect if actions exist
Browse files Browse the repository at this point in the history
  • Loading branch information
DumitracheAdrian committed May 18, 2024
1 parent d59cf2b commit 7cce8ea
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 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,23 @@ public function configureListFields(ListMapper $list): void
}
}

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

foreach ($this->actions as $action => $options) {
if (!$routes->has(sprintf('%s.%s', $routes->getBaseCodeRoute(), $action))) {
unset($this->actions[$action]);
}
}

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

0 comments on commit 7cce8ea

Please sign in to comment.