Completed
Pull Request — master (#114)
by Bart
01:45
created

Matrix   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 2
dl 0
loc 29
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getRecordDefinition() 0 7 1
A saveRecord() 0 12 3
1
<?php
2
3
namespace NerdsAndCompany\Schematic\Converters\Fields;
4
5
use Craft;
6
use craft\base\Model;
7
use NerdsAndCompany\Schematic\Schematic;
8
use NerdsAndCompany\Schematic\Converters\Base\Field;
9
10
/**
11
 * Schematic Matrix Converter.
12
 *
13
 * Sync Craft Setups.
14
 *
15
 * @author    Nerds & Company
16
 * @copyright Copyright (c) 2015-2018, Nerds & Company
17
 * @license   MIT
18
 *
19
 * @see      http://www.nerds.company
20
 */
21
class Matrix extends Field
22
{
23
    /**
24
     * {@inheritdoc}
25
     */
26
    public function getRecordDefinition(Model $record): array
27
    {
28
        $definition = parent::getRecordDefinition($record);
29
        $definition['blockTypes'] = Craft::$app->controller->module->modelMapper->export($record->getBlockTypes());
30
31
        return $definition;
32
    }
33
34
    /**
35
     * {@inheritdoc}
36
     */
37
    public function saveRecord(Model $record, array $definition): bool
38
    {
39
        if (parent::saveRecord($record, $definition)) {
40
            if (array_key_exists('blockTypes', $definition)) {
41
                Craft::$app->controller->module->modelMapper->import($definition['blockTypes'], $record->getBlockTypes(), ['fieldId' => $record->id]);
42
            }
43
44
            return true;
45
        }
46
47
        return false;
48
    }
49
}
50