Completed
Push — constructionplanless ( c6433a )
by Dominik
01:15
created

timber.php ➔ renderComponent()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 2
dl 0
loc 21
rs 9.584
c 0
b 0
f 0
1
<?php
2
3
use Flynt\Features\Components\Component;
4
use Flynt\Utils\Asset;
5
use function Flynt\Features\TimberLoader\renderTwigIndex;
6
7
add_filter('get_twig', function ($twig) {
8
    $twig->addFunction(new Twig_SimpleFunction('renderComponent', 'renderComponent'));
9
10
    $twig->addFunction(new Twig_SimpleFunction('renderFlexibleContent', function ($fcField) {
11
        return implode('', array_map(function ($field) {
12
            return renderComponent(ucfirst($field['acf_fc_layout']), $field);
13
        }, $fcField));
14
    }));
15
16
    return $twig;
17
});
18
19
add_action('after_setup_theme', function () {
20
    new Timber\Timber();
21
});
22
23
add_action('Flynt\afterRegisterFeatures', function () {
24
    Component::enqueueAssets('DocumentDefault', [
25
        [
26
          'name' => 'console-polyfill',
27
          'type' => 'script',
28
          'path' => 'vendor/console.js'
29
        ],
30
        [
31
          'name' => 'babel-polyfill',
32
          'type' => 'script',
33
          'path' => 'vendor/babel-polyfill.js'
34
        ],
35
        [
36
          'name' => 'document-register-element',
37
          'type' => 'script',
38
          'path' => 'vendor/document-register-element.js'
39
        ],
40
        [
41
          'name' => 'normalize',
42
          'path' => 'vendor/normalize.css',
43
          'type' => 'style'
44
        ]
45
    ]);
46
47
    // separately enqueued after components script.js to being able
48
    // to set global config variables before lazysizes is loaded
49
    Asset::enqueue([
50
        'name' => 'lazysizes',
51
        'type' => 'script',
52
        'path' => 'vendor/lazysizes.js'
53
    ]);
54
55
    Component::enqueueAssets('LayoutSinglePost');
56
    Component::enqueueAssets('LayoutMultiplePost');
57
});
58
59
function renderComponent ($name, $data = [])
60
{
61
    $data = apply_filters(
62
        'Flynt/addComponentData',
63
        $data,
64
        [],
65
        [
66
            'name' => $name,
67
        ]
68
    );
69
    $data = apply_filters(
70
        "Flynt/addComponentData?name={$name}",
71
        $data,
72
        [],
73
        [
74
            'name' => $name,
75
        ]
76
    );
77
78
    return renderTwigIndex(null, $name, $data, null);
79
};
80