diff --git a/src/Oro/Bundle/ActionBundle/Datagrid/EventListener/ButtonListener.php b/src/Oro/Bundle/ActionBundle/Datagrid/EventListener/ButtonListener.php index d7e2af96207..5a5865fcbbd 100644 --- a/src/Oro/Bundle/ActionBundle/Datagrid/EventListener/ButtonListener.php +++ b/src/Oro/Bundle/ActionBundle/Datagrid/EventListener/ButtonListener.php @@ -93,10 +93,13 @@ public function onConfigureActions(ConfigureActionsBefore $event) } $this->searchContext = $this->getButtonSearchContext($config); - $this->buttons = $this->getButtons( - $this->searchContext, - $config->offsetGetOr(ActionExtension::ACTION_KEY, []) - ); + + if (null === $this->buttons) { + $this->buttons = $this->getButtons( + $this->searchContext, + $config->offsetGetOr(ActionExtension::ACTION_KEY, []) + ); + } if (0 === count($this->buttons)) { return; @@ -154,8 +157,12 @@ function ( ) { $name = strtolower($button->getName()); $enabled = false; - $newButton = clone $button; + + if ($searchContext->getEntityId() === null) { + $configuration[$name] = false; + } + if (!array_key_exists($name, $configuration) || $configuration[$name] !== false) { $enabled = $extension->isAvailable($newButton, $searchContext); } diff --git a/src/Oro/Bundle/ActionBundle/Tests/Unit/Datagrid/EventListener/ButtonListenerTest.php b/src/Oro/Bundle/ActionBundle/Tests/Unit/Datagrid/EventListener/ButtonListenerTest.php index 2fb34ae64de..7e124a597b0 100644 --- a/src/Oro/Bundle/ActionBundle/Tests/Unit/Datagrid/EventListener/ButtonListenerTest.php +++ b/src/Oro/Bundle/ActionBundle/Tests/Unit/Datagrid/EventListener/ButtonListenerTest.php @@ -376,6 +376,25 @@ public function getRowConfigurationProvider() 'action3' => false ], ], + 'operations not allowed' => [ + 'config' => DatagridConfiguration::create([ + 'name' => 'datagrid_name', + 'source' => [ + 'type' => OrmDatasource::TYPE, + ], + ]), + 'record' => new ResultRecord([]), + 'buttonCollection' => $this->createButtonsCollection( + [ + $this->createButton('operation1', true), + $this->createButton('operation2', false) + ] + ), + 'expectedActions' => [ + 'operation1' => false, + 'operation2' => false + ], + ], '1 allowed action and array parent config' => [ 'config' => DatagridConfiguration::create([ 'name' => 'datagrid_name',