1 | <?php |
||||||
2 | /** |
||||||
3 | * Spoon plugin for Craft CMS 3.x |
||||||
4 | * |
||||||
5 | * Enhance Matrix |
||||||
6 | * |
||||||
7 | * @link https://angell.io |
||||||
8 | * @copyright Copyright (c) 2018 Angell & Co |
||||||
9 | */ |
||||||
10 | |||||||
11 | namespace angellco\spoon\controllers; |
||||||
12 | |||||||
13 | use angellco\spoon\Spoon; |
||||||
14 | |||||||
15 | use Craft; |
||||||
16 | use craft\web\Controller; |
||||||
17 | |||||||
18 | /** |
||||||
19 | * Configurator Controller |
||||||
20 | * |
||||||
21 | * @author Angell & Co |
||||||
22 | * @package Spoon |
||||||
23 | * @since 3.0.0 |
||||||
24 | */ |
||||||
25 | class ConfiguratorController extends Controller |
||||||
26 | { |
||||||
27 | |||||||
28 | // Protected Properties |
||||||
29 | // ========================================================================= |
||||||
30 | |||||||
31 | /** |
||||||
32 | * @var bool|array Allows anonymous access to this controller's actions. |
||||||
33 | * The actions must be in 'kebab-case' |
||||||
34 | * @access protected |
||||||
35 | */ |
||||||
36 | protected $allowAnonymous = false; |
||||||
37 | |||||||
38 | // Public Methods |
||||||
39 | // ========================================================================= |
||||||
40 | |||||||
41 | /** |
||||||
42 | * Returns the fld HTML for the main configurator |
||||||
43 | * |
||||||
44 | * @return \yii\web\Response |
||||||
45 | * @throws \Twig_Error_Loader |
||||||
46 | * @throws \yii\base\Exception |
||||||
47 | * @throws \yii\web\BadRequestHttpException |
||||||
48 | */ |
||||||
49 | public function actionGetHtml() |
||||||
50 | { |
||||||
51 | $this->requirePostRequest(); |
||||||
52 | $this->requireAcceptsJson(); |
||||||
53 | |||||||
54 | $fieldId = Craft::$app->getRequest()->getParam('fieldId'); |
||||||
55 | $field = Craft::$app->fields->getFieldById($fieldId); |
||||||
56 | $blockTypes = Craft::$app->matrix->getBlockTypesByFieldId($fieldId); |
||||||
57 | |||||||
58 | $blockTypeIds = []; |
||||||
59 | foreach ($blockTypes as $blockType) |
||||||
60 | { |
||||||
61 | $blockTypeIds[] = $blockType->id; |
||||||
62 | } |
||||||
63 | |||||||
64 | $context = Craft::$app->getRequest()->getParam('context'); |
||||||
65 | |||||||
66 | $spoonedBlockTypes = Spoon::$plugin->blockTypes->getByContext($context, 'groupName', false, $fieldId); |
||||||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||||||
67 | |||||||
68 | $fld = Craft::$app->view->renderTemplate('spoon/flds/configurator', array( |
||||||
69 | 'matrixField' => $field, |
||||||
70 | 'blockTypes' => $blockTypes, |
||||||
71 | 'blockTypeIds' => $blockTypeIds, |
||||||
72 | 'spoonedBlockTypes' => $spoonedBlockTypes |
||||||
73 | )); |
||||||
74 | |||||||
75 | return $this->asJson([ |
||||||
76 | 'html' => $fld |
||||||
77 | ]); |
||||||
78 | } |
||||||
79 | |||||||
80 | /** |
||||||
81 | * Returns the html for the individual block type fld. |
||||||
82 | * |
||||||
83 | * @return \yii\web\Response |
||||||
84 | * @throws \Twig_Error_Loader |
||||||
85 | * @throws \yii\base\Exception |
||||||
86 | * @throws \yii\web\BadRequestHttpException |
||||||
87 | */ |
||||||
88 | public function actionGetFieldsHtml() |
||||||
89 | { |
||||||
90 | $this->requirePostRequest(); |
||||||
91 | $this->requireAcceptsJson(); |
||||||
92 | |||||||
93 | $context = Craft::$app->getRequest()->getParam('context'); |
||||||
94 | $blockTypeId = Craft::$app->getRequest()->getParam('blockTypeId'); |
||||||
95 | |||||||
96 | $spoonedBlockType = Spoon::$plugin->blockTypes->getBlockType($context, $blockTypeId); |
||||||
97 | |||||||
98 | $fieldLayout = $spoonedBlockType->getFieldLayout(); |
||||||
0 ignored issues
–
show
The method
getFieldLayout() does not exist on angellco\spoon\models\BlockType . Since you implemented __call , consider adding a @method annotation.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
99 | |||||||
100 | $fld = Craft::$app->view->renderTemplate('spoon/flds/fields', array( |
||||||
101 | 'spoonedBlockType' => $spoonedBlockType, |
||||||
102 | 'fieldLayout' => $fieldLayout |
||||||
103 | )); |
||||||
104 | |||||||
105 | return $this->asJson([ |
||||||
106 | 'html' => $fld |
||||||
107 | ]); |
||||||
108 | } |
||||||
109 | |||||||
110 | } |
||||||
111 |