Passed
Push — changelog-update ( bdf6a8...e2239a )
by Claudio
14:08 queued 08:25
created

AjaxOptionController::listAction()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
c 1
b 0
f 0
dl 0
loc 8
rs 10
cc 2
nc 2
nop 1
1
<?php
2
3
namespace Flagbit\Bundle\TableAttributeBundle\Controller;
4
5
use Akeneo\Pim\Structure\Component\Model\AttributeOption;
6
use Akeneo\Platform\Bundle\UIBundle\Controller\AjaxOptionController as BaseAjaxOptionController;
7
use Flagbit\Bundle\TableAttributeBundle\Entity\AttributeOption as TableAttributeOption;
8
use Symfony\Component\HttpFoundation\JsonResponse;
9
use Symfony\Component\HttpFoundation\Request;
10
11
class AjaxOptionController
12
{
13
    private BaseAjaxOptionController $baseController;
14
15
    public function __construct(BaseAjaxOptionController $baseController)
16
    {
17
        $this->baseController = $baseController;
18
    }
19
20
    /**
21
     * Because of another hardcoded PHP class name in
22
     *
23
     * @see vendor/akeneo/pim-enterprise-dev/src/Akeneo/Pim/Automation/RuleEngine/front/src/fetch/AttributeOptionFetcher.ts
24
     *
25
     * the AttributeOption class can and should not be overridden in Akeneo PIM, we came up with this workaround to
26
     * support the legacy code of the Table attribute.
27
     *
28
     * @param Request $request
29
     *
30
     * @return JsonResponse
31
     */
32
    public function listAction(Request $request)
33
    {
34
        $class = $request->query->get('class');
35
        if ($class === AttributeOption::class) {
36
            $request->query->set('class', TableAttributeOption::class);
37
        }
38
39
        return $this->baseController->listAction($request);
40
    }
41
}
42