mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 15:13:50 +00:00
handle kind as contacts
This commit is contained in:
@@ -8,8 +8,12 @@ use Chill\MainBundle\Pagination\PaginatorInterface;
|
||||
use Chill\MainBundle\Templating\Listing\FilterOrderHelper;
|
||||
use Chill\ThirdPartyBundle\Repository\ThirdPartyACLAwareRepositoryInterface;
|
||||
use Chill\ThirdPartyBundle\Repository\ThirdPartyRepository;
|
||||
use http\Exception\RuntimeException;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
use Symfony\Component\HttpFoundation\RequestStack;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
@@ -45,15 +49,19 @@ final class ThirdPartyController extends CRUDController
|
||||
|
||||
protected ThirdPartyACLAwareRepositoryInterface $thirdPartyACLAwareRepository;
|
||||
|
||||
protected RequestStack $requestStack;
|
||||
|
||||
public function __construct(
|
||||
AuthorizationHelper $authorizationHelper,
|
||||
TranslatorInterface $translator,
|
||||
PaginatorFactory $paginatorFactory,
|
||||
RequestStack $requestStack,
|
||||
ThirdPartyACLAwareRepositoryInterface $thirdPartyACLAwareRepository
|
||||
) {
|
||||
$this->authorizationHelper = $authorizationHelper;
|
||||
$this->translator = $translator;
|
||||
$this->paginatorFactory = $paginatorFactory;
|
||||
$this->requestStack = $requestStack;
|
||||
$this->thirdPartyACLAwareRepository = $thirdPartyACLAwareRepository;
|
||||
}
|
||||
|
||||
@@ -82,9 +90,38 @@ final class ThirdPartyController extends CRUDController
|
||||
}
|
||||
}
|
||||
|
||||
if ('new' === $action) {
|
||||
if (!$request->query->has('kind')) {
|
||||
return $this->render('@ChillThirdParty/ThirdParty/new_pick_kind.html.twig');
|
||||
} else {
|
||||
$kind = $request->query->getAlpha('kind', '');
|
||||
|
||||
if (!(ThirdParty::KIND_COMPANY === $kind || ThirdParty::KIND_CONTACT === $kind)) {
|
||||
throw new BadRequestHttpException('This kind is not supported: '.$kind);
|
||||
}
|
||||
|
||||
$entity->setKind($kind);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
protected function createFormFor(string $action, $entity, string $formClass = null, array $formOptions = []): FormInterface
|
||||
{
|
||||
if ('new' === $action) {
|
||||
return parent::createFormFor($action, $entity, $formClass, \array_merge(
|
||||
$formOptions, [ 'kind' => $this->requestStack->getCurrentRequest()->query->getAlpha('kind')]
|
||||
));
|
||||
} elseif ('edit' === $action) {
|
||||
return parent::createFormFor($action, $entity, $formClass, \array_merge(
|
||||
$formOptions, [ 'kind' => $entity->getKind()]
|
||||
));
|
||||
}
|
||||
|
||||
return parent::createFormFor($action, $entity, $formClass, $formOptions);
|
||||
}
|
||||
|
||||
protected function buildFilterOrderHelper(string $action, Request $request): ?FilterOrderHelper
|
||||
{
|
||||
return $this->getFilterOrderHelperFactory()
|
||||
|
Reference in New Issue
Block a user