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

Matrix   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 2
dl 0
loc 27
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getRecordDefinition() 0 7 1
A saveRecord() 0 10 2
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)
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)
37
    {
38
        if (parent::saveRecord($record, $definition)) {
39
            Craft::$app->schematic_fields->import($definition['blockTypes'], $record->getBlockTypes(), ['fieldId' => $record->id]);
40
41
            return true;
42
        }
43
44
        return false;
45
    }
46
}
47