Completed
Push — develop ( bb979b...2f50d2 )
by Nate
09:37
created

CategoryList::resolveElement()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 0
cts 7
cp 0
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 6
1
<?php
2
3
/**
4
 * @copyright  Copyright (c) Flipbox Digital Limited
5
 * @license    https://github.com/flipboxfactory/craft-element-lists/LICENSE
6
 * @link       https://github.com/flipboxfactory/craft-element-lists/
7
 */
8
9
namespace flipbox\craft\element\lists\fields;
10
11
use craft\elements\Category;
12
use craft\fields\Categories;
13
use flipbox\craft\element\lists\ElementList;
14
15
/**
16
 * @author Flipbox Factory <[email protected]>
17
 * @since 1.0.0
18
 */
19
class CategoryList extends Categories implements SortableInterface, RelationalInterface
20
{
21
    use ElementListTrait;
22
23
    /**
24
     * @inheritdoc
25
     */
26
    public function init()
27
    {
28
        parent::init();
29
30
        $this->settingsTemplate = 'element-lists/_components/fieldtypes/settings';
31
        $this->inputTemplate = 'element-lists/_components/fieldtypes/input';
32
        $this->inputJsClass = 'Craft.NestedElementIndexSelectInput';
33
    }
34
35
    /**
36
     * @inheritdoc
37
     */
38
    public static function displayName(): string
39
    {
40
        return ElementList::t('Category List');
41
    }
42
43
    /**
44
     * @inheritdoc
45
     */
46
    public function settingsAttributes(): array
47
    {
48
        return array_merge(
49
            parent::settingsAttributes(),
50
            [
51
                'sortable'
52
            ]
53
        );
54
    }
55
56
    /**
57
     * @inheritDoc
58
     * @return Category|null
59
     */
60
    public function resolveElement($element)
61
    {
62
        if (is_numeric($element)) {
63
            return \Craft::$app->getCategories()->getCategoryById($element);
64
        }
65
66
        return Category::findOne($element);
0 ignored issues
show
Bug Compatibility introduced by
The expression \craft\elements\Category::findOne($element); of type craft\base\Element|null|craft\base\Element[] adds the type craft\base\Element[] to the return on line 66 which is incompatible with the return type declared by the interface flipbox\craft\element\li...terface::resolveElement of type craft\base\ElementInterface|null.
Loading history...
67
    }
68
}
69