Completed
Branch develop (17e8cf)
by Nate
10:01
created

ElementList   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 6
dl 0
loc 61
ccs 0
cts 25
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A init() 0 25 1
A t() 0 4 1
1
<?php
2
3
/**
4
 * @copyright  Copyright (c) Flipbox Digital Limited
5
 * @license    https://www.flipboxfactory.com/software/element-lists/license
6
 * @link       https://www.flipboxfactory.com/software/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\ember\modules\LoggerTrait;
20
use flipbox\craft\element\lists\fields\UserList;
21
use yii\base\Event;
22
23
/**
24
 * @author Flipbox Factory <[email protected]>
25
 * @since 1.0.0
26
 */
27
class ElementList extends Plugin
28
{
29
    use LoggerTrait;
30
31
    /**
32
     * This module's logger category
33
     *
34
     * @var string
35
     */
36
    protected static $category = 'element-lists';
37
38
    /**
39
     * @inheritdoc
40
     */
41
    public function init()
42
    {
43
        parent::init();
44
45
        // Register our fields
46
        Event::on(
47
            Fields::class,
48
            Fields::EVENT_REGISTER_FIELD_TYPES,
49
            function (RegisterComponentTypesEvent $event) {
50
                $event->types[] = UserList::class;
51
                $event->types[] = CategoryList::class;
52
                $event->types[] = AssetList::class;
53
            }
54
        );
55
56
        // Base template directory
57
        Event::on(
58
            View::class,
59
            View::EVENT_REGISTER_CP_TEMPLATE_ROOTS,
60
            function (RegisterTemplateRootsEvent $e) {
61
                $e->roots['nested-element-index'] = Craft::$app->getPath()->getVendorPath() .
62
                    '/flipboxfactory/craft-elements-nested-index/src/templates';
63
            }
64
        );
65
    }
66
67
68
    /*******************************************
69
     * TRANSLATE
70
     *******************************************/
71
72
    /**
73
     * Translates a message to the specified language.
74
     *
75
     * This is a shortcut method of [[\Craft::t()]].
76
     *     *
77
     * @param string $message the message to be translated.
78
     * @param array $params the parameters that will be used to replace the corresponding placeholders in the message.
79
     * @param string $language the language code (e.g. `en-US`, `en`). If this is null, the current
80
     * [[\yii\base\Application::language|application language]] will be used.
81
     * @return string the translated message.
82
     */
83
    public static function t($message, $params = [], $language = null)
84
    {
85
        return Craft::t(static::$category, $message, $params, $language);
86
    }
87
}
88