Browse Source

Champs EntityType filtré sur Merchant pour les FilterMultipleMerchantsInterface

master
Guillaume 4 years ago
parent
commit
7164be3a84
1 changed files with 7 additions and 2 deletions
  1. +7
    -2
      ShopBundle/Controller/Admin/AdminController.php

+ 7
- 2
ShopBundle/Controller/Admin/AdminController.php View File



protected function commonQueryFilter($entityClass, $queryBuilder) protected function commonQueryFilter($entityClass, $queryBuilder)
{ {

if (new $entityClass instanceof FilterMultipleMerchantsInterface) { if (new $entityClass instanceof FilterMultipleMerchantsInterface) {
$queryBuilder->andWhere(':currentMerchant MEMBER OF entity.merchants') $queryBuilder->andWhere(':currentMerchant MEMBER OF entity.merchants')
->setParameter(':currentMerchant', $this->getUser()->getMerchant()->getId()); ->setParameter(':currentMerchant', $this->getUser()->getMerchant()->getId());
$passedOptions = $child->getConfig()->getOptions(); $passedOptions = $child->getConfig()->getOptions();
$classImplements = class_implements($passedOptions['class']); $classImplements = class_implements($passedOptions['class']);


if (in_array('Lc\ShopBundle\Context\FilterMerchantInterface', $classImplements)) {
$isFilterMerchantInterface = in_array('Lc\ShopBundle\Context\FilterMerchantInterface', $classImplements) ;
$isFilterMultipleMerchantsInterface = in_array('Lc\ShopBundle\Context\FilterMultipleMerchantsInterface', $classImplements) ;

if ($isFilterMerchantInterface || $isFilterMultipleMerchantsInterface) {


$propertyMerchant = 'merchant'; $propertyMerchant = 'merchant';
if($isFilterMultipleMerchantsInterface) {
$propertyMerchant .= 's' ;
}


$form->add($child->getName(), EntityType::class, array( $form->add($child->getName(), EntityType::class, array(
'class' => $this->em->getClassMetadata($passedOptions['class'])->getName(), 'class' => $this->em->getClassMetadata($passedOptions['class'])->getName(),

Loading…
Cancel
Save