Passed
Push — trunk ( 024f41...cfd10b )
by Christian
15:08 queued 13s
created

sw-inline-snippet.mixin.ts ➔ getInlineSnippet   B

Complexity

Conditions 6

Size

Total Lines 23
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
eloc 17
dl 0
loc 23
rs 8.6166
c 0
b 0
f 0
1
/**
2
 * @package admin
3
 */
4
5
/* @private */
6
export {};
7
8
/**
9
 * @deprecated tag:v6.6.0 - Will be private
10
 */
11
Shopware.Mixin.register('sw-inline-snippet', {
12
    computed: {
13
        swInlineSnippetLocale(): string {
14
            return Shopware.State.get('session').currentLocale as unknown as string;
15
        },
16
        swInlineSnippetFallbackLocale(): string {
17
            return Shopware.Context.app.fallbackLocale as unknown as string;
18
        },
19
    },
20
21
    methods: {
22
        getInlineSnippet(value: {
23
            [key: string]: string;
24
        }) {
25
            if (Shopware.Utils.types.isEmpty(value)) {
26
                return '';
27
            }
28
            if (value[this.swInlineSnippetLocale]) {
29
                return value[this.swInlineSnippetLocale];
30
            }
31
            if (value[this.swInlineSnippetFallbackLocale]) {
32
                return value[this.swInlineSnippetFallbackLocale];
33
            }
34
            if (Shopware.Utils.types.isObject(value)) {
35
                const locale = Object.keys(value).find((key) => {
36
                    return value[key] !== '';
37
                });
38
39
                if (locale !== undefined) {
40
                    return value[locale];
41
                }
42
            }
43
44
            return value;
45
        },
46
    },
47
});
48