Completed
Push — master ( fe0f99...6b22ab )
by Nate
03:54
created

TypeController   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 5
dl 0
loc 43
ccs 0
cts 28
cp 0
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B actionSettings() 0 35 3
1
<?php
2
3
/**
4
 * @copyright  Copyright (c) Flipbox Digital Limited
5
 * @license    https://flipboxfactory.com/software/link/license
6
 * @link       https://www.flipboxfactory.com/software/link/
7
 */
8
9
namespace flipbox\link\controllers;
10
11
use Craft;
12
use craft\web\Controller;
13
use flipbox\link\Link;
14
use yii\web\HttpException;
15
use yii\web\Response;
16
17
/**
18
 * @author Flipbox Factory <[email protected]>
19
 * @since 1.0.0
20
 */
21
class TypeController extends Controller
22
{
23
24
    /**
25
     * @return Response
26
     * @throws HttpException
27
     */
28
    public function actionSettings(): Response
29
    {
30
        $this->requirePostRequest();
31
        $this->requireAcceptsJson();
32
33
        $view = $this->getView();
34
35
        $type = Link::getInstance()->getType()->find(
36
            Craft::$app->getRequest()->getRequiredBodyParam('type')
37
        );
38
39
        if (!$type) {
40
            throw new HttpException("Type not found");
41
        }
42
43
        // Allow explicit setting of the identifier
44
        if ($identifier = Craft::$app->getRequest()->getBodyParam('identifier')) {
45
            $type->setIdentifier($identifier);
46
        }
47
48
        $html = $view->renderTemplate(
49
            'link/_components/fieldtypes/Link/type',
50
            [
51
                'type' => $type,
52
                'namespace' => Craft::$app->getRequest()->getRequiredBodyParam('namespace')
53
            ]
54
        );
55
56
        return $this->asJson([
57
            'label' => $type::displayName(),
58
            'paneHtml' => $html,
59
            'headHtml' => $view->getHeadHtml(),
60
            'footHtml' => $view->getBodyHtml(),
61
        ]);
62
    }
63
}
64