Skip to content

Commit

Permalink
[Resource] Fix flash for bulk delete action and routing configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
GSadee authored and stefandoorn committed Oct 30, 2017
1 parent dc50604 commit f3c83cc
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
Expand Up @@ -79,6 +79,9 @@ sylius_admin_product_variant_bulk_delete:
section: admin
redirect: referer
permission: true
repository:
method: findById
arguments: [$ids]

sylius_admin_product_variant_delete:
path: /{id}
Expand Down
Expand Up @@ -88,6 +88,10 @@ sylius_admin_promotion_coupon_bulk_delete:
section: admin
redirect: referer
permission: true
paginate: false
repository:
method: findById
arguments: [$ids]

sylius_admin_promotion_coupon_delete:
path: /{id}
Expand Down
19 changes: 18 additions & 1 deletion src/Sylius/Bundle/ResourceBundle/Controller/FlashHelper.php
Expand Up @@ -13,7 +13,9 @@

namespace Sylius\Bundle\ResourceBundle\Controller;

use Doctrine\Common\Inflector\Inflector;
use Sylius\Bundle\ResourceBundle\Event\ResourceControllerEvent;
use Sylius\Component\Resource\Metadata\MetadataInterface;
use Sylius\Component\Resource\Model\ResourceInterface;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\Translation\TranslatorBagInterface;
Expand Down Expand Up @@ -84,7 +86,7 @@ private function addFlashWithType(RequestConfiguration $requestConfiguration, st
{
$metadata = $requestConfiguration->getMetadata();
$metadataName = ucfirst($metadata->getHumanizedName());
$parameters = ['%resource%' => $metadataName];
$parameters = $this->getParametersWithName($metadataName, $actionName);

$message = (string) $requestConfiguration->getFlashMessage($actionName);
if (empty($message)) {
Expand Down Expand Up @@ -165,4 +167,19 @@ private function isTranslationDefined(string $message, string $locale, array $pa

return $message !== $this->translator->trans($message, $parameters, 'flashes');
}

/**
* @param string $metadataName
* @param string $actionName
*
* @return array
*/
private function getParametersWithName(string $metadataName, string $actionName): array
{
if (stripos($actionName, 'bulk') !== false) {
return ['%resources%' => ucfirst(Inflector::pluralize($metadataName))];
}

return ['%resource%' => ucfirst($metadataName)];
}
}
Expand Up @@ -6,7 +6,7 @@ sylius:
create: '%resource% has been successfully created.'
update: '%resource% has been successfully updated.'
delete: '%resource% has been successfully deleted.'
bulk_delete: 'Resources have been succesfully deleted.'
bulk_delete: '%resources% have been successfully deleted.'
move: '%resource% has been successfully moved.'
generate: '%resource%s have been successfully generated.'
revert: '%resource% has been successfully reverted.'
Expand Down

0 comments on commit f3c83cc

Please sign in to comment.