Completed
Push — 1.0 ( 8ff026...136d33 )
by David
9s
created

ColorFieldConverter   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 1
dl 0
loc 43
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A convert() 0 4 1
A canConvert() 0 4 1
1
<?php
2
3
namespace Drupal\easy_entity_reader\Converters;
4
5
use Drupal\Core\Field\FieldItemInterface;
6
use Drupal\field_collection\Plugin\Field\FieldType\FieldCollection;
7
use Drupal\easy_entity_reader\EntityWrapper;
8
use Drupal\Core\Entity\EntityTypeManagerInterface;
9
use Drupal\color_field\Plugin\Field\FieldType\ColorFieldType;
10
11
/**
12
 * Convert ColorFieldType class to value.
13
 *
14
 * Class ColorFieldConverter.
15
 */
16
class ColorFieldConverter implements ConverterInterface
17
{
18
    /**
19
     * @var EntityWrapper
20
     */
21
    private $entityWrapper;
22
23
    /**
24
     * @var EntityTypeManagerInterface
25
     */
26
    private $entityManager;
27
28
    /**
29
     * @param EntityWrapper              $entityWrapper
30
     * @param EntityTypeManagerInterface $entityManager
31
     */
32
    public function __construct(EntityWrapper $entityWrapper,
33
                            EntityTypeManagerInterface $entityManager)
34
    {
35
        $this->entityWrapper = $entityWrapper;
36
        $this->entityManager = $entityManager;
37
    }
38
39
    /**
40
     * @param FieldItemInterface $value
41
     */
42
    public function convert(FieldItemInterface $value)
43
    {
44
        return $value->getValue();
45
    }
46
47
    /**
48
     * Returns whether the FieldItemInterface can be converted or not.
49
     *
50
     * @param FieldItemInterface $value
51
     *
52
     * @return bool
53
     */
54
    public function canConvert(FieldItemInterface $value) : bool
55
    {
56
        return $value instanceof ColorFieldType;
57
    }
58
}
59