|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @copyright Copyright (c) Flipbox Digital Limited |
|
5
|
|
|
* @license https://raw.githubusercontent.com/flipboxfactory/craft-link/master/LICENSE |
|
6
|
|
|
* @link https://github.com/flipboxfactory/craft-link |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace flipbox\craft\link\controllers; |
|
10
|
|
|
|
|
11
|
|
|
use Craft; |
|
12
|
|
|
use craft\web\Controller; |
|
13
|
|
|
use flipbox\craft\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
|
|
|
* @return Response |
|
25
|
|
|
* @throws HttpException |
|
26
|
|
|
* @throws \Twig_Error_Loader |
|
27
|
|
|
* @throws \yii\base\Exception |
|
28
|
|
|
* @throws \yii\web\BadRequestHttpException |
|
29
|
|
|
*/ |
|
30
|
|
|
public function actionSettings(): Response |
|
31
|
|
|
{ |
|
32
|
|
|
$this->requirePostRequest(); |
|
33
|
|
|
$this->requireAcceptsJson(); |
|
34
|
|
|
|
|
35
|
|
|
$view = $this->getView(); |
|
36
|
|
|
|
|
37
|
|
|
$type = Link::getInstance()->findType( |
|
38
|
|
|
Craft::$app->getRequest()->getRequiredBodyParam('type') |
|
39
|
|
|
); |
|
40
|
|
|
|
|
41
|
|
|
if (!$type) { |
|
42
|
|
|
throw new HttpException("Type not found"); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
// Allow explicit setting of the identifier |
|
46
|
|
|
if ($identifier = Craft::$app->getRequest()->getBodyParam('identifier')) { |
|
47
|
|
|
$type->setIdentifier($identifier); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
$html = $view->renderTemplate( |
|
51
|
|
|
'link/_components/fieldtypes/Link/type', |
|
52
|
|
|
[ |
|
53
|
|
|
'type' => $type, |
|
54
|
|
|
'namespace' => Craft::$app->getRequest()->getRequiredBodyParam('namespace') |
|
55
|
|
|
] |
|
56
|
|
|
); |
|
57
|
|
|
|
|
58
|
|
|
return $this->asJson( |
|
59
|
|
|
[ |
|
60
|
|
|
'label' => $type::displayName(), |
|
61
|
|
|
'paneHtml' => $html, |
|
62
|
|
|
'headHtml' => $view->getHeadHtml(), |
|
63
|
|
|
'footHtml' => $view->getBodyHtml(), |
|
64
|
|
|
] |
|
65
|
|
|
); |
|
66
|
|
|
} |
|
67
|
|
|
} |
|
68
|
|
|
|