From 1115ea044a42e5918da901e8314bcd82a253acf1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yann=20Eugon=C3=A9?= Date: Tue, 9 Oct 2018 18:41:47 +0200 Subject: [PATCH] Added render_actions option to avoid menu to be rendered on all actions. Fixes #4 & #5 --- README.md | 4 +++- src/Admin/Extension/WorkflowExtension.php | 6 ++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 20bd071..0c08997 100644 --- a/README.md +++ b/README.md @@ -132,7 +132,8 @@ services: public: true arguments: - '@workflow.registry' - - workflow_name: pull_request + - render_actions: [show] + workflow_name: pull_request no_transition_label: No transition for pull request no_transition_icon: fa fa-times dropdown_transitions_label: Pull request transitions @@ -155,6 +156,7 @@ sonata_admin: What are these options ? +- `render_actions` : Admin action names on which the extension should render its menu (defaults to `[show, edit]`) - `workflow_name` : The name of the Workflow to handle (defaults to `null`) - `no_transition_display` : Whether or not to display a button when no transition is enabled (defaults to `false`) - `no_transition_label` : The button label when no transition is enabled (defaults to `workflow_transitions_empty`) diff --git a/src/Admin/Extension/WorkflowExtension.php b/src/Admin/Extension/WorkflowExtension.php index 64b5f56..4f4eb72 100644 --- a/src/Admin/Extension/WorkflowExtension.php +++ b/src/Admin/Extension/WorkflowExtension.php @@ -72,6 +72,10 @@ public function configureSideMenu( $action, AdminInterface $childAdmin = null ) { + if (!in_array($action, $this->options['render_actions'], true)) { + return; + } + $subject = $admin->getSubject(); if (null === $subject) { return; @@ -111,6 +115,7 @@ protected function configureOptions(OptionsResolver $resolver) { $resolver ->setDefaults([ + 'render_actions' => ['edit', 'show'], 'workflow_name' => null, 'no_transition_display' => false, 'no_transition_label' => 'workflow_transitions_empty', @@ -120,6 +125,7 @@ protected function configureOptions(OptionsResolver $resolver) 'transitions_default_icon' => null, 'transitions_icons' => [], ]) + ->setAllowedTypes('render_actions', ['string[]']) ->setAllowedTypes('workflow_name', ['string', 'null']) ->setAllowedTypes('no_transition_display', ['bool']) ->setAllowedTypes('no_transition_label', ['string'])