Completed
Pull Request — master (#114)
by Bart
05:36 queued 46s
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\Converters\Base\Field;
8
9
/**
10
 * Schematic Globals Converter.
11
 *
12
 * Sync Craft Setups.
13
 *
14
 * @author    Nerds & Company
15
 * @copyright Copyright (c) 2015-2018, Nerds & Company
16
 * @license   MIT
17
 *
18
 * @see      http://www.nerds.company
19
 */
20
class Matrix extends Field
21
{
22
    /**
23
     * {@inheritdoc}
24
     */
25
    public function getRecordDefinition(Model $record): array
26
    {
27
        $definition = parent::getRecordDefinition($record);
28
        $definition['blockTypes'] = Craft::$app->schematic_fields->export($record->getBlockTypes());
29
30
        return $definition;
31
    }
32
33
    /**
34
     * {@inheritdoc}
35
     */
36
    public function saveRecord(Model $record, array $definition): bool
37
    {
38
        if (parent::saveRecord($record, $definition)) {
39
            if (array_key_exists('blockTypes', $definition)) {
40
                Craft::$app->schematic_fields->import($definition['blockTypes'], $record->getBlockTypes(), ['fieldId' => $record->id]);
41
            }
42
43
            return true;
44
        }
45
46
        return false;
47
    }
48
}
49