ElementList::init()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 26

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 26
ccs 0
cts 22
cp 0
rs 9.504
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
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;
10
11
use Craft;
12
use craft\base\Plugin;
13
use craft\events\RegisterComponentTypesEvent;
14
use craft\events\RegisterTemplateRootsEvent;
15
use craft\services\Fields;
16
use craft\web\View;
17
use flipbox\craft\element\lists\fields\AssetList;
18
use flipbox\craft\element\lists\fields\CategoryList;
19
use flipbox\craft\element\lists\fields\EntryList;
20
use flipbox\craft\ember\modules\LoggerTrait;
21
use flipbox\craft\element\lists\fields\UserList;
22
use yii\base\Event;
23
24
/**
25
 * @author Flipbox Factory <[email protected]>
26
 * @since 1.0.0
27
 */
28
class ElementList extends Plugin
29
{
30
    use LoggerTrait;
31
32
    /**
33
     * This module's logger category
34
     *
35
     * @var string
36
     */
37
    protected static $category = 'element-lists';
38
39
    /**
40
     * @inheritdoc
41
     */
42
    public function init()
43
    {
44
        parent::init();
45
46
        // Register our fields
47
        Event::on(
48
            Fields::class,
49
            Fields::EVENT_REGISTER_FIELD_TYPES,
50
            function (RegisterComponentTypesEvent $event) {
51
                $event->types[] = AssetList::class;
52
                $event->types[] = CategoryList::class;
53
                $event->types[] = EntryList::class;
54
                $event->types[] = UserList::class;
55
            }
56
        );
57
58
        // Base template directory
59
        Event::on(
60
            View::class,
61
            View::EVENT_REGISTER_CP_TEMPLATE_ROOTS,
62
            function (RegisterTemplateRootsEvent $e) {
63
                $e->roots['nested-element-index'] = Craft::$app->getPath()->getVendorPath() .
64
                    '/flipboxfactory/craft-elements-nested-index/src/templates';
65
            }
66
        );
67
    }
68
69
70
    /*******************************************
71
     * TRANSLATE
72
     *******************************************/
73
74
    /**
75
     * Translates a message to the specified language.
76
     *
77
     * This is a shortcut method of [[\Craft::t()]].
78
     *     *
79
     * @param string $message the message to be translated.
80
     * @param array $params the parameters that will be used to replace the corresponding placeholders in the message.
81
     * @param string $language the language code (e.g. `en-US`, `en`). If this is null, the current
82
     * [[\yii\base\Application::language|application language]] will be used.
83
     * @return string the translated message.
84
     */
85
    public static function t($message, $params = [], $language = null)
86
    {
87
        return Craft::t(static::$category, $message, $params, $language);
88
    }
89
}
90