Completed
Branch EDTR/master (83b47e)
by
unknown
25:37 queued 16:41
created

GutenbergEditor::matchesCurrentRequest()   A

Complexity

Conditions 5
Paths 7

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
nc 7
nop 0
dl 0
loc 13
rs 9.5222
c 0
b 0
f 0
1
<?php
2
3
namespace EventEspresso\core\domain\entities\routing\handlers\admin;
4
5
use EE_Dependency_Map;
6
use EventEspresso\core\domain\entities\editor\CoreBlocksAssetManager;
7
use EventEspresso\core\domain\entities\routing\data_nodes\domains\EventEditor;
8
use EventEspresso\core\domain\entities\routing\data_nodes\EventEspressoData;
9
use EventEspresso\core\domain\services\assets\EspressoCoreAppAssetManager;
10
11
/**
12
 * Class GutenbergEditor
13
 * detects and executes logic for the WP Gutenberg Editor
14
 *
15
 * @package EventEspresso\core\domain\entities\routing\admin
16
 * @author  Brent Christensen
17
 * @since   $VID:$
18
 */
19
class GutenbergEditor extends AdminRoute
20
{
21
22
    /**
23
     * returns true if the current request matches this route
24
     *
25
     * @return bool
26
     * @since   $VID:$
27
     */
28
    public function matchesCurrentRequest()
29
    {
30
        global $pagenow;
31
        return parent::matchesCurrentRequest()
32
               && $pagenow
33
               && (
34
                   $pagenow === 'post-new.php'
35
                   || (
36
                       $pagenow === 'post.php'
37
                       && $this->request->getRequestParam('action') === 'edit'
38
                   )
39
               );
40
    }
41
42
43
    /**
44
     * @since $VID:$
45
     */
46
    protected function registerDependencies()
47
    {
48
        $this->dependency_map->registerDependencies(
49
            'EventEspresso\core\domain\entities\routing\data_nodes\domains\GutenbergEditorData',
50
            [
51
                'EventEspresso\core\services\json\JsonDataNodeValidator' => EE_Dependency_Map::load_from_cache,
52
            ]
53
        );
54
        $this->dependency_map->registerDependencies(
55
            'EventEspresso\core\domain\entities\editor\CoreBlocksAssetManager',
56
            [
57
                'EventEspresso\core\domain\Domain'                   => EE_Dependency_Map::load_from_cache,
58
                'EventEspresso\core\services\assets\AssetCollection' => EE_Dependency_Map::load_from_cache,
59
                'EventEspresso\core\services\assets\Registry'        => EE_Dependency_Map::load_from_cache,
60
            ]
61
        );
62
        /** @var EventEspressoData $primary_data_node */
63
        $primary_data_node = $this->loader->getShared(
64
            'EventEspresso\core\domain\entities\routing\data_nodes\EventEspressoData'
65
        );
66
        $primary_data_node->setTargetScript(CoreBlocksAssetManager::JS_HANDLE_CORE_BLOCKS);
67
        /** @var EventEditor $data_node */
68
        $data_node = $this->loader->getShared(
69
            'EventEspresso\core\domain\entities\routing\data_nodes\domains\GutenbergEditorData'
70
        );
71
        $this->setDataNode($data_node);
72
    }
73
74
75
    /**
76
     * implements logic required to run during request
77
     *
78
     * @return bool
79
     * @since   $VID:$
80
     */
81
    protected function requestHandler()
82
    {
83
        $this->asset_manager = $this->loader->getShared(
84
            'EventEspresso\core\domain\entities\editor\CoreBlocksAssetManager'
85
        );
86
        add_action('admin_enqueue_scripts', [$this->asset_manager, 'enqueueBrowserAssets'], 100);
87
        return true;
88
    }
89
}
90