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\services; |
12
|
|
|
|
13
|
|
|
use angellco\spoon\models\BlockType; |
14
|
|
|
use angellco\spoon\records\BlockType as BlockTypeRecord; |
15
|
|
|
use angellco\spoon\errors\BlockTypeNotFoundException; |
16
|
|
|
|
17
|
|
|
use Craft; |
18
|
|
|
use craft\base\Component; |
19
|
|
|
use craft\base\Field; |
20
|
|
|
use craft\db\Table; |
21
|
|
|
use craft\events\ConfigEvent; |
22
|
|
|
use craft\helpers\Db; |
23
|
|
|
use craft\helpers\ProjectConfig as ProjectConfigHelper; |
24
|
|
|
use craft\helpers\StringHelper; |
25
|
|
|
use craft\models\FieldLayout; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* BlockTypes Service |
29
|
|
|
* |
30
|
|
|
* @author Angell & Co |
31
|
|
|
* @package Spoon |
32
|
|
|
* @since 3.0.0 |
33
|
|
|
*/ |
34
|
|
|
class BlockTypes extends Component |
35
|
|
|
{ |
36
|
|
|
// Private Properties |
37
|
|
|
// ========================================================================= |
38
|
|
|
|
39
|
|
|
private $_blockTypesByContext; |
40
|
|
|
|
41
|
|
|
private $_superTablePlugin; |
42
|
|
|
|
43
|
|
|
private $_superTableService; |
44
|
|
|
|
45
|
|
|
const CONFIG_BLOCKTYPE_KEY = 'spoonBlockTypes'; |
46
|
|
|
|
47
|
|
|
// Public Methods |
48
|
|
|
// ========================================================================= |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Returns a Spoon block type model by its ID |
52
|
|
|
* |
53
|
|
|
* @param $id |
54
|
|
|
* |
55
|
|
|
* @return BlockType|null |
56
|
|
|
* @throws BlockTypeNotFoundException |
57
|
|
|
*/ |
58
|
|
|
public function getById($id) |
59
|
|
|
{ |
60
|
|
|
$blockTypeRecord = BlockTypeRecord::findOne($id); |
61
|
|
|
|
62
|
|
|
if (!$blockTypeRecord) { |
|
|
|
|
63
|
|
|
throw new BlockTypeNotFoundException(Craft::t('spoon', 'No Spoon block type exists with the ID “{id}”', ['id' => $id])); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
return $this->_populateBlockTypeFromRecord($blockTypeRecord); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Returns a single BlockType Model by its context and blockTypeId |
71
|
|
|
* |
72
|
|
|
* @param bool $context |
73
|
|
|
* @param bool $matrixBlockTypeId |
74
|
|
|
* |
75
|
|
|
* @return BlockType|bool|null |
76
|
|
|
*/ |
77
|
|
|
public function getBlockType($context = false, $matrixBlockTypeId = false) |
78
|
|
|
{ |
79
|
|
|
|
80
|
|
|
if (!$context || !$matrixBlockTypeId) |
81
|
|
|
{ |
82
|
|
|
return false; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
$blockTypeRecord = BlockTypeRecord::findOne([ |
86
|
|
|
'context' => $context, |
87
|
|
|
'matrixBlockTypeId' => $matrixBlockTypeId |
88
|
|
|
]); |
89
|
|
|
|
90
|
|
|
if (!$blockTypeRecord) { |
|
|
|
|
91
|
|
|
return null; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
return $this->_populateBlockTypeFromRecord($blockTypeRecord); |
95
|
|
|
|
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* Returns a block type by its context. |
100
|
|
|
* |
101
|
|
|
* @param string $context |
102
|
|
|
* @param null|string $groupBy Group by an optional model attribute to group by |
103
|
|
|
* @param bool $ignoreSubContext Optionally ignore the sub context (id) |
104
|
|
|
* @param null|integer $fieldId Optionally filter by fieldId |
105
|
|
|
* |
106
|
|
|
* @return array |
107
|
|
|
*/ |
108
|
|
|
public function getByContext($context, $groupBy = null, $ignoreSubContext = false, $fieldId = null): array |
109
|
|
|
{ |
110
|
|
|
|
111
|
|
|
if ($ignoreSubContext) { |
112
|
|
|
|
113
|
|
|
if ($fieldId !== null) { |
114
|
|
|
if ($context === 'global') { |
115
|
|
|
$condition = [ |
116
|
|
|
'fieldId' => $fieldId, |
117
|
|
|
'context' => 'global' |
118
|
|
|
]; |
119
|
|
|
} else { |
120
|
|
|
$condition = [ |
121
|
|
|
'fieldId' => $fieldId, |
122
|
|
|
['like', 'context', $context.'%', false] |
123
|
|
|
]; |
124
|
|
|
} |
125
|
|
|
} else { |
126
|
|
|
if ($context === 'global') { |
127
|
|
|
$condition = [ |
128
|
|
|
'context' => 'global' |
129
|
|
|
]; |
130
|
|
|
} else { |
131
|
|
|
$condition = ['like', 'context', $context.'%', false]; |
132
|
|
|
} |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
} else { |
136
|
|
|
$condition = [ |
137
|
|
|
'context' => $context |
138
|
|
|
]; |
139
|
|
|
|
140
|
|
|
if ($fieldId !== null) |
141
|
|
|
{ |
142
|
|
|
$condition['fieldId'] = $fieldId; |
143
|
|
|
} |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
$blockTypeRecords = BlockTypeRecord::find() |
147
|
|
|
->where($condition) |
148
|
|
|
->orderBy(['groupSortOrder' => SORT_ASC, 'sortOrder' => SORT_ASC]) |
149
|
|
|
->all(); |
150
|
|
|
|
151
|
|
|
if ($blockTypeRecords) { |
|
|
|
|
152
|
|
|
|
153
|
|
|
foreach ($blockTypeRecords as $blockTypeRecord) { |
154
|
|
|
$blockType = $this->_populateBlockTypeFromRecord($blockTypeRecord); |
155
|
|
|
$this->_blockTypesByContext[$context][$blockType->id] = $blockType; |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
} else { |
159
|
|
|
return []; |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
if ($groupBy !== null) { |
163
|
|
|
$return = []; |
164
|
|
|
|
165
|
|
|
foreach ($this->_blockTypesByContext[$context] as $blockType) |
166
|
|
|
{ |
167
|
|
|
$return[$blockType->$groupBy][] = $blockType; |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
return $return; |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
return $this->_blockTypesByContext[$context]; |
174
|
|
|
|
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
/** |
178
|
|
|
* Saves our version of a block type into the project config |
179
|
|
|
* |
180
|
|
|
* @param BlockType $blockType |
181
|
|
|
* |
182
|
|
|
* @return bool |
183
|
|
|
* @throws \Exception |
184
|
|
|
*/ |
185
|
|
|
public function save(BlockType $blockType): bool |
186
|
|
|
{ |
187
|
|
|
$isNew = !$blockType->id; |
188
|
|
|
|
189
|
|
|
// Ensure the block type has a UID |
190
|
|
|
if ($isNew) { |
191
|
|
|
$blockType->uid = StringHelper::UUID(); |
192
|
|
|
} else if (!$blockType->uid) { |
193
|
|
|
$existingBlockTypeRecord = BlockTypeRecord::findOne($blockType->id); |
194
|
|
|
|
195
|
|
|
if (!$existingBlockTypeRecord) { |
|
|
|
|
196
|
|
|
throw new BlockTypeNotFoundException("No Spoon Block Type exists with the ID “{$blockType->id}”"); |
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
$blockType->uid = $existingBlockTypeRecord->uid; |
200
|
|
|
} |
201
|
|
|
|
202
|
|
|
// Make sure it validates |
203
|
|
|
if (!$blockType->validate()) { |
204
|
|
|
return false; |
205
|
|
|
} |
206
|
|
|
|
207
|
|
|
// Save it to the project config |
208
|
|
|
$configData = [ |
209
|
|
|
'groupName' => $blockType->groupName, |
210
|
|
|
'groupSortOrder' => $blockType->groupSortOrder, |
211
|
|
|
'sortOrder' => $blockType->sortOrder, |
212
|
|
|
'context' => $blockType->context, |
213
|
|
|
'field' => $blockType->getField()->uid, |
|
|
|
|
214
|
|
|
'matrixBlockType' => $blockType->getBlockType()->uid, |
215
|
|
|
]; |
216
|
|
|
|
217
|
|
|
// Handle any currently attached field layouts |
218
|
|
|
/** @var FieldLayout $fieldLayout */ |
219
|
|
|
$fieldLayout = $blockType->getFieldLayout(); |
|
|
|
|
220
|
|
|
|
221
|
|
|
if ($fieldLayout && $fieldLayout->uid) { |
222
|
|
|
$fieldLayoutConfig = $fieldLayout->getConfig(); |
223
|
|
|
|
224
|
|
|
$layoutUid = $fieldLayout->uid; |
225
|
|
|
|
226
|
|
|
$configData['fieldLayout'] = [ |
227
|
|
|
$layoutUid => $fieldLayoutConfig |
228
|
|
|
]; |
229
|
|
|
} else { |
230
|
|
|
$configData['fieldLayout'] = null; |
231
|
|
|
} |
232
|
|
|
|
233
|
|
|
$configPath = self::CONFIG_BLOCKTYPE_KEY . '.' . $blockType->uid; |
234
|
|
|
|
235
|
|
|
Craft::$app->projectConfig->set($configPath, $configData); |
236
|
|
|
|
237
|
|
|
if ($isNew) { |
238
|
|
|
$blockType->id = Db::idByUid('{{%spoon_blocktypes}}', $blockType->uid); |
239
|
|
|
} |
240
|
|
|
|
241
|
|
|
return true; |
242
|
|
|
} |
243
|
|
|
|
244
|
|
|
/** |
245
|
|
|
* Deletes all the block types for a given context from the project config |
246
|
|
|
* |
247
|
|
|
* @param null $context |
|
|
|
|
248
|
|
|
* @param null $fieldId |
|
|
|
|
249
|
|
|
* |
250
|
|
|
* @return bool|null |
251
|
|
|
* @throws \Exception |
252
|
|
|
*/ |
253
|
|
|
public function deleteByContext($context = null, $fieldId = null) |
254
|
|
|
{ |
255
|
|
|
if (!$context) { |
|
|
|
|
256
|
|
|
return false; |
257
|
|
|
} |
258
|
|
|
|
259
|
|
|
$blockTypes = $this->getByContext($context, null, false, $fieldId); |
260
|
|
|
|
261
|
|
|
foreach ($blockTypes as $blockType) { |
262
|
|
|
Craft::$app->getProjectConfig()->remove(self::CONFIG_BLOCKTYPE_KEY . '.' . $blockType->uid); |
263
|
|
|
} |
264
|
|
|
|
265
|
|
|
return true; |
266
|
|
|
} |
267
|
|
|
|
268
|
|
|
// Project config methods |
269
|
|
|
// ========================================================================= |
270
|
|
|
|
271
|
|
|
/** |
272
|
|
|
* Handles a changed block type and saves it to the database |
273
|
|
|
* |
274
|
|
|
* @param ConfigEvent $event |
275
|
|
|
* |
276
|
|
|
* @throws \Throwable |
277
|
|
|
*/ |
278
|
|
|
public function handleChangedBlockType(ConfigEvent $event) |
279
|
|
|
{ |
280
|
|
|
$fieldsService = Craft::$app->getFields(); |
281
|
|
|
|
282
|
|
|
$uid = $event->tokenMatches[0]; |
283
|
|
|
$data = $event->newValue; |
284
|
|
|
|
285
|
|
|
$fieldUid = $data['field']; |
286
|
|
|
$fieldId = Db::idByUid(Table::FIELDS, $fieldUid); |
287
|
|
|
|
288
|
|
|
$matrixBlockTypeUid = $data['matrixBlockType']; |
289
|
|
|
$matrixBlockTypeId = Db::idByUid(Table::MATRIXBLOCKTYPES, $matrixBlockTypeUid); |
290
|
|
|
|
291
|
|
|
// Make sure fields and sites are processed |
292
|
|
|
ProjectConfigHelper::ensureAllSitesProcessed(); |
293
|
|
|
ProjectConfigHelper::ensureAllFieldsProcessed(); |
294
|
|
|
|
295
|
|
|
$db = Craft::$app->getDb(); |
296
|
|
|
$transaction = $db->beginTransaction(); |
297
|
|
|
|
298
|
|
|
try { |
299
|
|
|
// Get the record |
300
|
|
|
$blockTypeRecord = $this->_getBlockTypeRecord($uid); |
301
|
|
|
|
302
|
|
|
// Prep the record with the new data |
303
|
|
|
$blockTypeRecord->fieldId = $fieldId; |
304
|
|
|
$blockTypeRecord->matrixBlockTypeId = $matrixBlockTypeId; |
305
|
|
|
$blockTypeRecord->groupName = $data['groupName']; |
306
|
|
|
$blockTypeRecord->context = $data['context']; |
307
|
|
|
$blockTypeRecord->groupSortOrder = $data['groupSortOrder']; |
308
|
|
|
$blockTypeRecord->sortOrder = $data['sortOrder']; |
309
|
|
|
$blockTypeRecord->uid = $uid; |
310
|
|
|
|
311
|
|
|
// Handle the field layout |
312
|
|
|
if (!empty($data['fieldLayout'])) { |
313
|
|
|
// Save the field layout |
314
|
|
|
$layout = FieldLayout::createFromConfig(reset($data['fieldLayout'])); |
315
|
|
|
$layout->id = $blockTypeRecord->fieldLayoutId; |
316
|
|
|
$layout->type = BlockType::class; |
317
|
|
|
$layout->uid = key($data['fieldLayout']); |
318
|
|
|
$fieldsService->saveLayout($layout); |
319
|
|
|
$blockTypeRecord->fieldLayoutId = $layout->id; |
320
|
|
|
} else if ($blockTypeRecord->fieldLayoutId) { |
321
|
|
|
// Delete the field layout |
322
|
|
|
$fieldsService->deleteLayoutById($blockTypeRecord->fieldLayoutId); |
323
|
|
|
$blockTypeRecord->fieldLayoutId = null; |
324
|
|
|
} |
325
|
|
|
|
326
|
|
|
// Save the record |
327
|
|
|
$blockTypeRecord->save(false); |
328
|
|
|
|
329
|
|
|
$transaction->commit(); |
330
|
|
|
} catch (\Throwable $e) { |
331
|
|
|
$transaction->rollBack(); |
332
|
|
|
throw $e; |
333
|
|
|
} |
334
|
|
|
} |
335
|
|
|
|
336
|
|
|
/** |
337
|
|
|
* Handles a deleted block type and removes it from the database |
338
|
|
|
* |
339
|
|
|
* @param ConfigEvent $event |
340
|
|
|
* |
341
|
|
|
* @throws \Throwable |
342
|
|
|
*/ |
343
|
|
|
public function handleDeletedBlockType(ConfigEvent $event) |
344
|
|
|
{ |
345
|
|
|
$uid = $event->tokenMatches[0]; |
346
|
|
|
$blockTypeRecord = $this->_getBlockTypeRecord($uid); |
347
|
|
|
|
348
|
|
|
if (!$blockTypeRecord->id) { |
349
|
|
|
return; |
350
|
|
|
} |
351
|
|
|
|
352
|
|
|
$db = Craft::$app->getDb(); |
353
|
|
|
$transaction = $db->beginTransaction(); |
354
|
|
|
try { |
355
|
|
|
// Delete the block type record |
356
|
|
|
$db->createCommand() |
357
|
|
|
->delete('{{%spoon_blocktypes}}', ['id' => $blockTypeRecord->id]) |
358
|
|
|
->execute(); |
359
|
|
|
|
360
|
|
|
$transaction->commit(); |
361
|
|
|
} catch (\Throwable $e) { |
362
|
|
|
$transaction->rollBack(); |
363
|
|
|
throw $e; |
364
|
|
|
} |
365
|
|
|
} |
366
|
|
|
|
367
|
|
|
// Public Methods for FLDs on our Block Types |
368
|
|
|
// ========================================================================= |
369
|
|
|
|
370
|
|
|
/** |
371
|
|
|
* Saves a field layout into the project config nested under the block type config |
372
|
|
|
* |
373
|
|
|
* @param BlockType $blockType |
374
|
|
|
* |
375
|
|
|
* @return bool |
376
|
|
|
* @throws \Exception |
377
|
|
|
*/ |
378
|
|
|
public function saveFieldLayout(BlockType $blockType): bool |
379
|
|
|
{ |
380
|
|
|
/** @var FieldLayout $fieldLayout */ |
381
|
|
|
$fieldLayout = $blockType->getFieldLayout(); |
382
|
|
|
// $oldFieldLayoutId = $blockType->fieldLayoutId; |
383
|
|
|
|
384
|
|
|
if ($fieldLayout->uid) { |
385
|
|
|
$layoutUid = $fieldLayout->uid; |
386
|
|
|
} else { |
387
|
|
|
$layoutUid = StringHelper::UUID(); |
388
|
|
|
$fieldLayout->uid = $layoutUid; |
389
|
|
|
} |
390
|
|
|
|
391
|
|
|
$fieldLayoutConfig = $fieldLayout->getConfig(); |
392
|
|
|
|
393
|
|
|
$configPath = self::CONFIG_BLOCKTYPE_KEY . '.' . $blockType->uid . '.fieldLayout'; |
394
|
|
|
|
395
|
|
|
Craft::$app->projectConfig->set($configPath, [ |
396
|
|
|
$layoutUid => $fieldLayoutConfig |
397
|
|
|
]); |
398
|
|
|
|
399
|
|
|
return true; |
400
|
|
|
} |
401
|
|
|
|
402
|
|
|
/** |
403
|
|
|
* Returns an array of fieldLayoutIds indexed by matrixBlockTypeIds |
404
|
|
|
* for the given context and fieldId combination |
405
|
|
|
* |
406
|
|
|
* @param string $context required |
407
|
|
|
* @param bool|integer $fieldId required |
408
|
|
|
* @return false|array |
409
|
|
|
*/ |
410
|
|
|
public function getFieldLayoutIds($context, $fieldId = false) |
411
|
|
|
{ |
412
|
|
|
|
413
|
|
|
if (!$fieldId) |
414
|
|
|
{ |
415
|
|
|
return false; |
416
|
|
|
} |
417
|
|
|
|
418
|
|
|
$blockTypeRecords = BlockTypeRecord::findAll([ |
419
|
|
|
'context' => $context, |
420
|
|
|
'fieldId' => $fieldId |
421
|
|
|
]); |
422
|
|
|
|
423
|
|
|
$return = array(); |
424
|
|
|
foreach ($blockTypeRecords as $blockTypeRecord) |
425
|
|
|
{ |
426
|
|
|
$return[$blockTypeRecord->matrixBlockTypeId] = $blockTypeRecord->fieldLayoutId; |
427
|
|
|
} |
428
|
|
|
return $return; |
429
|
|
|
|
430
|
|
|
} |
431
|
|
|
|
432
|
|
|
|
433
|
|
|
// Private Methods |
434
|
|
|
// ========================================================================= |
435
|
|
|
|
436
|
|
|
/** |
437
|
|
|
* Gets a block type's record by uid. |
438
|
|
|
* |
439
|
|
|
* @param string $uid |
440
|
|
|
* |
441
|
|
|
* @return BlockTypeRecord |
442
|
|
|
*/ |
443
|
|
|
private function _getBlockTypeRecord(string $uid): BlockTypeRecord |
444
|
|
|
{ |
445
|
|
|
$record = BlockTypeRecord::findOne(['uid' => $uid]); |
446
|
|
|
return $record ?? new BlockTypeRecord(); |
|
|
|
|
447
|
|
|
} |
448
|
|
|
|
449
|
|
|
/** |
450
|
|
|
* Populates a BlockTypeModel with attributes from a BlockTypeRecord. |
451
|
|
|
* |
452
|
|
|
* @param BlockTypeRecord $blockTypeRecord |
453
|
|
|
* |
454
|
|
|
* @return BlockType|null |
455
|
|
|
*/ |
456
|
|
|
private function _populateBlockTypeFromRecord(BlockTypeRecord $blockTypeRecord) |
457
|
|
|
{ |
458
|
|
|
$blockType = new BlockType($blockTypeRecord->toArray([ |
459
|
|
|
'id', |
460
|
|
|
'uid', |
461
|
|
|
'fieldId', |
462
|
|
|
'matrixBlockTypeId', |
463
|
|
|
'fieldLayoutId', |
464
|
|
|
'groupName', |
465
|
|
|
'context', |
466
|
|
|
'groupSortOrder', |
467
|
|
|
'sortOrder' |
468
|
|
|
])); |
469
|
|
|
|
470
|
|
|
// Use the fieldId to get the field and save the handle on to the model |
471
|
|
|
/** @var Field $matrixField */ |
472
|
|
|
$matrixField = Craft::$app->fields->getFieldById($blockType->fieldId); |
|
|
|
|
473
|
|
|
if (!$matrixField) { |
|
|
|
|
474
|
|
|
return null; |
475
|
|
|
} |
476
|
|
|
$blockType->fieldHandle = $matrixField->handle; |
477
|
|
|
|
478
|
|
|
|
479
|
|
|
// Super Table support |
480
|
|
|
if (!$this->_superTablePlugin) { |
481
|
|
|
$this->_superTablePlugin = \Craft::$app->plugins->getPluginByPackageName('verbb/super-table'); |
482
|
|
|
} |
483
|
|
|
if ($this->_superTablePlugin) { |
484
|
|
|
|
485
|
|
|
if (!$this->_superTableService) { |
486
|
|
|
$this->_superTableService = new \verbb\supertable\services\SuperTableService(); |
|
|
|
|
487
|
|
|
} |
488
|
|
|
|
489
|
|
|
// If the field is actually inside a SuperTable |
490
|
|
|
if (strpos($matrixField->context, 'superTableBlockType') === 0) { |
491
|
|
|
$parts = explode(':', $matrixField->context); |
492
|
|
|
if (isset($parts[1])) { |
493
|
|
|
|
494
|
|
|
$superTableBlockTypeId = Db::idByUid('{{%supertableblocktypes}}', $parts[1]); |
495
|
|
|
|
496
|
|
|
/** @var \verbb\supertable\models\SuperTableBlockTypeModel $superTableBlockType */ |
497
|
|
|
$superTableBlockType = $this->_superTableService->getBlockTypeById($superTableBlockTypeId); |
498
|
|
|
|
499
|
|
|
/** @var \verbb\supertable\fields\SuperTableField $superTableField */ |
500
|
|
|
$superTableField = \Craft::$app->fields->getFieldById($superTableBlockType->fieldId); |
501
|
|
|
|
502
|
|
|
$blockType->fieldHandle = $superTableField->handle."-".$matrixField->handle; |
503
|
|
|
|
504
|
|
|
// If the context of _this_ field is inside a Matrix block ... then we need to do more inception |
505
|
|
|
if (strpos($superTableField->context, 'matrixBlockType') === 0) { |
506
|
|
|
$nestedParts = explode(':', $superTableField->context); |
507
|
|
|
if (isset($nestedParts[1])) { |
508
|
|
|
|
509
|
|
|
$matrixBlockTypeId = Db::idByUid('{{%matrixblocktypes}}', $nestedParts[1]); |
510
|
|
|
|
511
|
|
|
/** @var craft\models\MatrixBlockType $matrixBlockType */ |
512
|
|
|
$matrixBlockType = \Craft::$app->matrix->getBlockTypeById($matrixBlockTypeId); |
513
|
|
|
|
514
|
|
|
/** @var craft\fields\Matrix $globalField */ |
515
|
|
|
$globalField = \Craft::$app->fields->getFieldById($matrixBlockType->fieldId); |
516
|
|
|
|
517
|
|
|
$blockType->fieldHandle = $globalField->handle."-".$superTableField->handle."-".$matrixField->handle; |
518
|
|
|
} |
519
|
|
|
} |
520
|
|
|
} |
521
|
|
|
} |
522
|
|
|
} |
523
|
|
|
|
524
|
|
|
|
525
|
|
|
// Save the MatrixBlockTypeModel on to our model |
526
|
|
|
$blockType->matrixBlockType = $blockType->getBlockType(); |
527
|
|
|
|
528
|
|
|
// Save the field layout content on to our model |
529
|
|
|
if ($blockType->fieldLayoutId) { |
|
|
|
|
530
|
|
|
$layout = $blockType->getFieldLayout(); |
531
|
|
|
$blockType->fieldLayoutModel = [ |
532
|
|
|
'tabs' => $layout->getTabs(), |
533
|
|
|
'fields' => $layout->getFields() |
534
|
|
|
]; |
535
|
|
|
} |
536
|
|
|
|
537
|
|
|
return $blockType; |
538
|
|
|
} |
539
|
|
|
|
540
|
|
|
} |
541
|
|
|
|