Completed
Branch Gutenberg/master (13c832)
by
unknown
150:46 queued 136:30
created
core/services/editor/BlockRegistrationManager.php 1 patch
Indentation   +140 added lines, -140 removed lines patch added patch discarded remove patch
@@ -36,144 +36,144 @@
 block discarded – undo
36 36
 class BlockRegistrationManager extends BlockManager
37 37
 {
38 38
 
39
-    /**
40
-     * @var BlockAssetManagerCollection $block_asset_manager_collection
41
-     */
42
-    protected $block_asset_manager_collection;
43
-
44
-
45
-    /**
46
-     * BlockRegistrationManager constructor.
47
-     *
48
-     * @param BlockAssetManagerCollection $block_asset_manager_collection
49
-     * @param BlockCollection             $blocks
50
-     * @param RequestInterface            $request
51
-     */
52
-    public function __construct(
53
-        BlockAssetManagerCollection $block_asset_manager_collection,
54
-        BlockCollection $blocks,
55
-        RequestInterface $request
56
-    ) {
57
-        $this->block_asset_manager_collection = $block_asset_manager_collection;
58
-        parent::__construct($blocks, $request);
59
-    }
60
-
61
-
62
-    /**
63
-     *  Returns the name of a hookpoint to be used to call initialize()
64
-     *
65
-     * @return string
66
-     */
67
-    public function initHook()
68
-    {
69
-        return 'AHEE__EE_System__core_loaded_and_ready';
70
-    }
71
-
72
-
73
-    /**
74
-     * Perform any early setup required for block editors to functions
75
-     *
76
-     * @return void
77
-     * @throws Exception
78
-     */
79
-    public function initialize()
80
-    {
81
-        $this->initializeBlocks();
82
-        add_action('AHEE__EE_System__initialize', array($this, 'registerBlocks'));
83
-    }
84
-
85
-
86
-    /**
87
-     * @return CollectionInterface|BlockInterface[]
88
-     * @throws ReflectionException
89
-     * @throws InvalidArgumentException
90
-     * @throws EE_Error
91
-     * @throws InvalidClassException
92
-     * @throws InvalidDataTypeException
93
-     * @throws InvalidEntityException
94
-     * @throws InvalidFilePathException
95
-     * @throws InvalidIdentifierException
96
-     * @throws InvalidInterfaceException
97
-     */
98
-    protected function populateBlockCollection()
99
-    {
100
-        $loader = new CollectionLoader(
101
-            new CollectionDetails(
102
-                // collection name
103
-                'shortcodes',
104
-                // collection interface
105
-                'EventEspresso\core\domain\entities\editor\BlockInterface',
106
-                // FQCNs for classes to add (all classes within each namespace will be loaded)
107
-                apply_filters(
108
-                    'FHEE__EventEspresso_core_services_editor_BlockManager__populateBlockCollection__collection_FQCNs',
109
-                    array(
110
-                        // 'EventEspresso\core\domain\entities\editor\blocks\common',
111
-                        // 'EventEspresso\core\domain\entities\editor\blocks\editor',
112
-                        // 'EventEspresso\core\domain\entities\editor\blocks\widgets',
113
-                    )
114
-                ),
115
-                // filepaths to classes to add
116
-                array(),
117
-                // file mask to use if parsing folder for files to add
118
-                '',
119
-                // what to use as identifier for collection entities
120
-                // using CLASS NAME prevents duplicates (works like a singleton)
121
-                CollectionDetails::ID_CLASS_NAME
122
-            ),
123
-            $this->blocks
124
-        );
125
-        return $loader->getCollection();
126
-    }
127
-
128
-
129
-    /**
130
-     * populates the BlockCollection and calls initialize() on all installed blocks
131
-     *
132
-     * @return void
133
-     * @throws Exception
134
-     */
135
-    public function initializeBlocks()
136
-    {
137
-        try {
138
-            $this->populateBlockCollection();
139
-            // cycle thru block loaders and initialize each loader
140
-            foreach ($this->blocks as $block) {
141
-                $block->initialize();
142
-                if (! $this->block_asset_manager_collection->has($block->assetManager())) {
143
-                    $this->block_asset_manager_collection->add($block->assetManager());
144
-                    $block->assetManager()->setAssetHandles();
145
-                }
146
-            }
147
-        } catch (Exception $exception) {
148
-            new ExceptionStackTraceDisplay($exception);
149
-        }
150
-    }
151
-
152
-
153
-    /**
154
-     * calls registerBlock() and load assets for all installed blocks
155
-     *
156
-     * @return void
157
-     * @throws Exception
158
-     */
159
-    public function registerBlocks()
160
-    {
161
-        try {
162
-            // cycle thru block loader folders
163
-            foreach ($this->blocks as $block) {
164
-                // perform any setup required for the block
165
-                $block_type = $block->registerBlock();
166
-                if (! $block_type instanceof WP_Block_Type) {
167
-                    throw new InvalidEntityException($block_type, 'WP_Block_Type');
168
-                }
169
-                do_action(
170
-                    'FHEE__EventEspresso_core_services_editor_BlockManager__registerBlocks__block_type_registered',
171
-                    $block,
172
-                    $block_type
173
-                );
174
-            }
175
-        } catch (Exception $exception) {
176
-            new ExceptionStackTraceDisplay($exception);
177
-        }
178
-    }
39
+	/**
40
+	 * @var BlockAssetManagerCollection $block_asset_manager_collection
41
+	 */
42
+	protected $block_asset_manager_collection;
43
+
44
+
45
+	/**
46
+	 * BlockRegistrationManager constructor.
47
+	 *
48
+	 * @param BlockAssetManagerCollection $block_asset_manager_collection
49
+	 * @param BlockCollection             $blocks
50
+	 * @param RequestInterface            $request
51
+	 */
52
+	public function __construct(
53
+		BlockAssetManagerCollection $block_asset_manager_collection,
54
+		BlockCollection $blocks,
55
+		RequestInterface $request
56
+	) {
57
+		$this->block_asset_manager_collection = $block_asset_manager_collection;
58
+		parent::__construct($blocks, $request);
59
+	}
60
+
61
+
62
+	/**
63
+	 *  Returns the name of a hookpoint to be used to call initialize()
64
+	 *
65
+	 * @return string
66
+	 */
67
+	public function initHook()
68
+	{
69
+		return 'AHEE__EE_System__core_loaded_and_ready';
70
+	}
71
+
72
+
73
+	/**
74
+	 * Perform any early setup required for block editors to functions
75
+	 *
76
+	 * @return void
77
+	 * @throws Exception
78
+	 */
79
+	public function initialize()
80
+	{
81
+		$this->initializeBlocks();
82
+		add_action('AHEE__EE_System__initialize', array($this, 'registerBlocks'));
83
+	}
84
+
85
+
86
+	/**
87
+	 * @return CollectionInterface|BlockInterface[]
88
+	 * @throws ReflectionException
89
+	 * @throws InvalidArgumentException
90
+	 * @throws EE_Error
91
+	 * @throws InvalidClassException
92
+	 * @throws InvalidDataTypeException
93
+	 * @throws InvalidEntityException
94
+	 * @throws InvalidFilePathException
95
+	 * @throws InvalidIdentifierException
96
+	 * @throws InvalidInterfaceException
97
+	 */
98
+	protected function populateBlockCollection()
99
+	{
100
+		$loader = new CollectionLoader(
101
+			new CollectionDetails(
102
+				// collection name
103
+				'shortcodes',
104
+				// collection interface
105
+				'EventEspresso\core\domain\entities\editor\BlockInterface',
106
+				// FQCNs for classes to add (all classes within each namespace will be loaded)
107
+				apply_filters(
108
+					'FHEE__EventEspresso_core_services_editor_BlockManager__populateBlockCollection__collection_FQCNs',
109
+					array(
110
+						// 'EventEspresso\core\domain\entities\editor\blocks\common',
111
+						// 'EventEspresso\core\domain\entities\editor\blocks\editor',
112
+						// 'EventEspresso\core\domain\entities\editor\blocks\widgets',
113
+					)
114
+				),
115
+				// filepaths to classes to add
116
+				array(),
117
+				// file mask to use if parsing folder for files to add
118
+				'',
119
+				// what to use as identifier for collection entities
120
+				// using CLASS NAME prevents duplicates (works like a singleton)
121
+				CollectionDetails::ID_CLASS_NAME
122
+			),
123
+			$this->blocks
124
+		);
125
+		return $loader->getCollection();
126
+	}
127
+
128
+
129
+	/**
130
+	 * populates the BlockCollection and calls initialize() on all installed blocks
131
+	 *
132
+	 * @return void
133
+	 * @throws Exception
134
+	 */
135
+	public function initializeBlocks()
136
+	{
137
+		try {
138
+			$this->populateBlockCollection();
139
+			// cycle thru block loaders and initialize each loader
140
+			foreach ($this->blocks as $block) {
141
+				$block->initialize();
142
+				if (! $this->block_asset_manager_collection->has($block->assetManager())) {
143
+					$this->block_asset_manager_collection->add($block->assetManager());
144
+					$block->assetManager()->setAssetHandles();
145
+				}
146
+			}
147
+		} catch (Exception $exception) {
148
+			new ExceptionStackTraceDisplay($exception);
149
+		}
150
+	}
151
+
152
+
153
+	/**
154
+	 * calls registerBlock() and load assets for all installed blocks
155
+	 *
156
+	 * @return void
157
+	 * @throws Exception
158
+	 */
159
+	public function registerBlocks()
160
+	{
161
+		try {
162
+			// cycle thru block loader folders
163
+			foreach ($this->blocks as $block) {
164
+				// perform any setup required for the block
165
+				$block_type = $block->registerBlock();
166
+				if (! $block_type instanceof WP_Block_Type) {
167
+					throw new InvalidEntityException($block_type, 'WP_Block_Type');
168
+				}
169
+				do_action(
170
+					'FHEE__EventEspresso_core_services_editor_BlockManager__registerBlocks__block_type_registered',
171
+					$block,
172
+					$block_type
173
+				);
174
+			}
175
+		} catch (Exception $exception) {
176
+			new ExceptionStackTraceDisplay($exception);
177
+		}
178
+	}
179 179
 }
Please login to merge, or discard this patch.
core/domain/entities/editor/Block.php 2 patches
Indentation   +212 added lines, -212 removed lines patch added patch discarded remove patch
@@ -20,216 +20,216 @@
 block discarded – undo
20 20
 abstract class Block implements BlockInterface
21 21
 {
22 22
 
23
-    /**
24
-     * BlockAssetManager that this editor block uses for asset registration
25
-     *
26
-     * @var BlockAssetManagerInterface $block_asset_manager
27
-     */
28
-    protected $block_asset_manager;
29
-
30
-    /**
31
-     * @var array $attributes
32
-     */
33
-    private $attributes;
34
-
35
-    /**
36
-     * If set to true, then the block will render its content client side
37
-     * If false, then the block will render its content server side using the renderBlock() method
38
-     *
39
-     * @var bool $dynamic
40
-     */
41
-    private $dynamic = false;
42
-
43
-    /**
44
-     * @var string $block_type
45
-     */
46
-    private $block_type;
47
-
48
-    /**
49
-     * @var array $supported_post_types
50
-     */
51
-    private $supported_post_types;
52
-
53
-    /**
54
-     * @var WP_Block_Type $wp_block_type
55
-     */
56
-    private $wp_block_type;
57
-
58
-
59
-    /**
60
-     * BlockLoader constructor.
61
-     *
62
-     * @param BlockAssetManagerInterface $block_asset_manager
63
-     */
64
-    public function __construct(BlockAssetManagerInterface $block_asset_manager)
65
-    {
66
-        $this->block_asset_manager = $block_asset_manager;
67
-    }
68
-
69
-
70
-    /**
71
-     * @return string
72
-     */
73
-    public function blockType()
74
-    {
75
-        return $this->block_type;
76
-    }
77
-
78
-
79
-    /**
80
-     * @return string
81
-     */
82
-    public function namespacedBlockType()
83
-    {
84
-        return self::NAME_SPACE . '/' . $this->block_type;
85
-    }
86
-
87
-
88
-    /**
89
-     * @param string $block_type
90
-     */
91
-    protected function setBlockType($block_type)
92
-    {
93
-        $this->block_type = $block_type;
94
-    }
95
-
96
-
97
-    /**
98
-     * BlockAssetManager that this editor block uses for asset registration
99
-     *
100
-     * @return BlockAssetManagerInterface
101
-     */
102
-    public function assetManager()
103
-    {
104
-        return $this->block_asset_manager;
105
-    }
106
-
107
-
108
-    /**
109
-     * @param WP_Block_Type $wp_block_type
110
-     */
111
-    protected function setWpBlockType($wp_block_type)
112
-    {
113
-        $this->wp_block_type = $wp_block_type;
114
-    }
115
-
116
-
117
-    /**
118
-     * @param array $supported_post_types
119
-     */
120
-    protected function setSupportedPostTypes(array $supported_post_types)
121
-    {
122
-        $this->supported_post_types = $supported_post_types;
123
-    }
124
-
125
-
126
-    /**
127
-     * @return array
128
-     */
129
-    public function attributes()
130
-    {
131
-        return $this->attributes;
132
-    }
133
-
134
-
135
-    /**
136
-     * @param array $attributes
137
-     */
138
-    public function setAttributes(array $attributes)
139
-    {
140
-        $this->attributes = $attributes;
141
-    }
142
-
143
-
144
-    /**
145
-     * @return bool
146
-     */
147
-    public function isDynamic()
148
-    {
149
-        return $this->dynamic;
150
-    }
151
-
152
-
153
-    /**
154
-     * @param bool $dynamic
155
-     */
156
-    public function setDynamic($dynamic = true)
157
-    {
158
-        $this->dynamic = filter_var($dynamic, FILTER_VALIDATE_BOOLEAN);
159
-    }
160
-
161
-
162
-    /**
163
-     * Registers the Editor Block with WP core;
164
-     * Returns the registered block type on success, or false on failure.
165
-     *
166
-     * @return WP_Block_Type|false
167
-     */
168
-    public function registerBlock()
169
-    {
170
-        $args = array(
171
-            'attributes'    => $this->attributes(),
172
-            'editor_script' => $this->block_asset_manager->getEditorScriptHandle(),
173
-            'editor_style'  => $this->block_asset_manager->getEditorStyleHandle(),
174
-            'script'        => $this->block_asset_manager->getScriptHandle(),
175
-            'style'         => $this->block_asset_manager->getStyleHandle(),
176
-        );
177
-        if (! $this->isDynamic()) {
178
-            $args['render_callback'] = $this->renderBlock();
179
-        }
180
-        $wp_block_type = register_block_type(
181
-            new WP_Block_Type(
182
-                $this->namespacedBlockType(),
183
-                $args
184
-            )
185
-        );
186
-        $this->setWpBlockType($wp_block_type);
187
-        return $wp_block_type;
188
-    }
189
-
190
-
191
-    /**
192
-     * @return WP_Block_Type|false The registered block type on success, or false on failure.
193
-     */
194
-    public function unRegisterBlock()
195
-    {
196
-        return unregister_block_type($this->namespacedBlockType());
197
-    }
198
-
199
-
200
-    /**
201
-     * returns true if the block type applies for the supplied post type
202
-     * and should be added to that post type's editor
203
-     *
204
-     * @param string $post_type
205
-     * @return boolean
206
-     */
207
-    public function appliesToPostType($post_type)
208
-    {
209
-        return in_array($post_type, $this->supported_post_types, true);
210
-    }
211
-
212
-
213
-    /**
214
-     * @return array
215
-     */
216
-    public function getEditorContainer()
217
-    {
218
-        return array(
219
-            $this->namespacedBlockType(),
220
-            array(),
221
-        );
222
-    }
223
-
224
-
225
-    /**
226
-     * returns the rendered HTML for the block
227
-     *
228
-     * @param array $attributes
229
-     * @return string
230
-     */
231
-    public function renderBlock(array $attributes = array())
232
-    {
233
-        return '';
234
-    }
23
+	/**
24
+	 * BlockAssetManager that this editor block uses for asset registration
25
+	 *
26
+	 * @var BlockAssetManagerInterface $block_asset_manager
27
+	 */
28
+	protected $block_asset_manager;
29
+
30
+	/**
31
+	 * @var array $attributes
32
+	 */
33
+	private $attributes;
34
+
35
+	/**
36
+	 * If set to true, then the block will render its content client side
37
+	 * If false, then the block will render its content server side using the renderBlock() method
38
+	 *
39
+	 * @var bool $dynamic
40
+	 */
41
+	private $dynamic = false;
42
+
43
+	/**
44
+	 * @var string $block_type
45
+	 */
46
+	private $block_type;
47
+
48
+	/**
49
+	 * @var array $supported_post_types
50
+	 */
51
+	private $supported_post_types;
52
+
53
+	/**
54
+	 * @var WP_Block_Type $wp_block_type
55
+	 */
56
+	private $wp_block_type;
57
+
58
+
59
+	/**
60
+	 * BlockLoader constructor.
61
+	 *
62
+	 * @param BlockAssetManagerInterface $block_asset_manager
63
+	 */
64
+	public function __construct(BlockAssetManagerInterface $block_asset_manager)
65
+	{
66
+		$this->block_asset_manager = $block_asset_manager;
67
+	}
68
+
69
+
70
+	/**
71
+	 * @return string
72
+	 */
73
+	public function blockType()
74
+	{
75
+		return $this->block_type;
76
+	}
77
+
78
+
79
+	/**
80
+	 * @return string
81
+	 */
82
+	public function namespacedBlockType()
83
+	{
84
+		return self::NAME_SPACE . '/' . $this->block_type;
85
+	}
86
+
87
+
88
+	/**
89
+	 * @param string $block_type
90
+	 */
91
+	protected function setBlockType($block_type)
92
+	{
93
+		$this->block_type = $block_type;
94
+	}
95
+
96
+
97
+	/**
98
+	 * BlockAssetManager that this editor block uses for asset registration
99
+	 *
100
+	 * @return BlockAssetManagerInterface
101
+	 */
102
+	public function assetManager()
103
+	{
104
+		return $this->block_asset_manager;
105
+	}
106
+
107
+
108
+	/**
109
+	 * @param WP_Block_Type $wp_block_type
110
+	 */
111
+	protected function setWpBlockType($wp_block_type)
112
+	{
113
+		$this->wp_block_type = $wp_block_type;
114
+	}
115
+
116
+
117
+	/**
118
+	 * @param array $supported_post_types
119
+	 */
120
+	protected function setSupportedPostTypes(array $supported_post_types)
121
+	{
122
+		$this->supported_post_types = $supported_post_types;
123
+	}
124
+
125
+
126
+	/**
127
+	 * @return array
128
+	 */
129
+	public function attributes()
130
+	{
131
+		return $this->attributes;
132
+	}
133
+
134
+
135
+	/**
136
+	 * @param array $attributes
137
+	 */
138
+	public function setAttributes(array $attributes)
139
+	{
140
+		$this->attributes = $attributes;
141
+	}
142
+
143
+
144
+	/**
145
+	 * @return bool
146
+	 */
147
+	public function isDynamic()
148
+	{
149
+		return $this->dynamic;
150
+	}
151
+
152
+
153
+	/**
154
+	 * @param bool $dynamic
155
+	 */
156
+	public function setDynamic($dynamic = true)
157
+	{
158
+		$this->dynamic = filter_var($dynamic, FILTER_VALIDATE_BOOLEAN);
159
+	}
160
+
161
+
162
+	/**
163
+	 * Registers the Editor Block with WP core;
164
+	 * Returns the registered block type on success, or false on failure.
165
+	 *
166
+	 * @return WP_Block_Type|false
167
+	 */
168
+	public function registerBlock()
169
+	{
170
+		$args = array(
171
+			'attributes'    => $this->attributes(),
172
+			'editor_script' => $this->block_asset_manager->getEditorScriptHandle(),
173
+			'editor_style'  => $this->block_asset_manager->getEditorStyleHandle(),
174
+			'script'        => $this->block_asset_manager->getScriptHandle(),
175
+			'style'         => $this->block_asset_manager->getStyleHandle(),
176
+		);
177
+		if (! $this->isDynamic()) {
178
+			$args['render_callback'] = $this->renderBlock();
179
+		}
180
+		$wp_block_type = register_block_type(
181
+			new WP_Block_Type(
182
+				$this->namespacedBlockType(),
183
+				$args
184
+			)
185
+		);
186
+		$this->setWpBlockType($wp_block_type);
187
+		return $wp_block_type;
188
+	}
189
+
190
+
191
+	/**
192
+	 * @return WP_Block_Type|false The registered block type on success, or false on failure.
193
+	 */
194
+	public function unRegisterBlock()
195
+	{
196
+		return unregister_block_type($this->namespacedBlockType());
197
+	}
198
+
199
+
200
+	/**
201
+	 * returns true if the block type applies for the supplied post type
202
+	 * and should be added to that post type's editor
203
+	 *
204
+	 * @param string $post_type
205
+	 * @return boolean
206
+	 */
207
+	public function appliesToPostType($post_type)
208
+	{
209
+		return in_array($post_type, $this->supported_post_types, true);
210
+	}
211
+
212
+
213
+	/**
214
+	 * @return array
215
+	 */
216
+	public function getEditorContainer()
217
+	{
218
+		return array(
219
+			$this->namespacedBlockType(),
220
+			array(),
221
+		);
222
+	}
223
+
224
+
225
+	/**
226
+	 * returns the rendered HTML for the block
227
+	 *
228
+	 * @param array $attributes
229
+	 * @return string
230
+	 */
231
+	public function renderBlock(array $attributes = array())
232
+	{
233
+		return '';
234
+	}
235 235
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -81,7 +81,7 @@  discard block
 block discarded – undo
81 81
      */
82 82
     public function namespacedBlockType()
83 83
     {
84
-        return self::NAME_SPACE . '/' . $this->block_type;
84
+        return self::NAME_SPACE.'/'.$this->block_type;
85 85
     }
86 86
 
87 87
 
@@ -174,7 +174,7 @@  discard block
 block discarded – undo
174 174
             'script'        => $this->block_asset_manager->getScriptHandle(),
175 175
             'style'         => $this->block_asset_manager->getStyleHandle(),
176 176
         );
177
-        if (! $this->isDynamic()) {
177
+        if ( ! $this->isDynamic()) {
178 178
             $args['render_callback'] = $this->renderBlock();
179 179
         }
180 180
         $wp_block_type = register_block_type(
Please login to merge, or discard this patch.
core/domain/entities/editor/BlockInterface.php 1 patch
Indentation   +66 added lines, -66 removed lines patch added patch discarded remove patch
@@ -22,70 +22,70 @@
 block discarded – undo
22 22
 interface BlockInterface
23 23
 {
24 24
 
25
-    const NAME_SPACE = 'eventespresso';
26
-
27
-    /**
28
-     * Perform any early setup required by the block
29
-     * including setting the block type and supported post types
30
-     *
31
-     * @return void
32
-     */
33
-    public function initialize();
34
-
35
-
36
-    /**
37
-     * @return string
38
-     */
39
-    public function blockType();
40
-
41
-
42
-    /**
43
-     * AssetRegister that this editor block uses for asset registration
44
-     *
45
-     * @return BlockAssetManagerInterface
46
-     */
47
-    public function assetManager();
48
-
49
-
50
-    /**
51
-     * Registers the Editor Block with WP core;
52
-     * Returns the registered block type on success, or false on failure.
53
-     *
54
-     * @return WP_Block_Type|false
55
-     */
56
-    public function registerBlock();
57
-
58
-
59
-    /**
60
-     * Un-registers the Editor Block with WP core;
61
-     * Returns the registered block type on success, or false on failure.
62
-     *
63
-     * @return WP_Block_Type|false
64
-     */
65
-    public function unRegisterBlock();
66
-
67
-
68
-    /**
69
-     * returns true if the block type applies for the supplied post type
70
-     * and should be added to that post type's editor
71
-     *
72
-     * @param string $post_type
73
-     * @return boolean
74
-     */
75
-    public function appliesToPostType($post_type);
76
-
77
-
78
-    /**
79
-     * @return array
80
-     */
81
-    public function getEditorContainer();
82
-
83
-
84
-    /**
85
-     * returns the rendered HTML for the block
86
-     *
87
-     * @param array $attributes
88
-     * @return string
89
-     */
90
-    public function renderBlock(array $attributes = array());
25
+	const NAME_SPACE = 'eventespresso';
26
+
27
+	/**
28
+	 * Perform any early setup required by the block
29
+	 * including setting the block type and supported post types
30
+	 *
31
+	 * @return void
32
+	 */
33
+	public function initialize();
34
+
35
+
36
+	/**
37
+	 * @return string
38
+	 */
39
+	public function blockType();
40
+
41
+
42
+	/**
43
+	 * AssetRegister that this editor block uses for asset registration
44
+	 *
45
+	 * @return BlockAssetManagerInterface
46
+	 */
47
+	public function assetManager();
48
+
49
+
50
+	/**
51
+	 * Registers the Editor Block with WP core;
52
+	 * Returns the registered block type on success, or false on failure.
53
+	 *
54
+	 * @return WP_Block_Type|false
55
+	 */
56
+	public function registerBlock();
57
+
58
+
59
+	/**
60
+	 * Un-registers the Editor Block with WP core;
61
+	 * Returns the registered block type on success, or false on failure.
62
+	 *
63
+	 * @return WP_Block_Type|false
64
+	 */
65
+	public function unRegisterBlock();
66
+
67
+
68
+	/**
69
+	 * returns true if the block type applies for the supplied post type
70
+	 * and should be added to that post type's editor
71
+	 *
72
+	 * @param string $post_type
73
+	 * @return boolean
74
+	 */
75
+	public function appliesToPostType($post_type);
76
+
77
+
78
+	/**
79
+	 * @return array
80
+	 */
81
+	public function getEditorContainer();
82
+
83
+
84
+	/**
85
+	 * returns the rendered HTML for the block
86
+	 *
87
+	 * @param array $attributes
88
+	 * @return string
89
+	 */
90
+	public function renderBlock(array $attributes = array());
91 91
 }
Please login to merge, or discard this patch.
core/services/assets/BlockAssetManager.php 2 patches
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -57,8 +57,8 @@  discard block
 block discarded – undo
57 57
      */
58 58
     public function setEditorScriptHandle($editor_script_handle)
59 59
     {
60
-        if(strpos($editor_script_handle, BlockInterface::NAME_SPACE . '-') !== 0) {
61
-            $editor_script_handle = BlockInterface::NAME_SPACE . '-' . $editor_script_handle;
60
+        if (strpos($editor_script_handle, BlockInterface::NAME_SPACE.'-') !== 0) {
61
+            $editor_script_handle = BlockInterface::NAME_SPACE.'-'.$editor_script_handle;
62 62
         }
63 63
         $this->editor_script_handle = $editor_script_handle;
64 64
     }
@@ -78,8 +78,8 @@  discard block
 block discarded – undo
78 78
      */
79 79
     public function setEditorStyleHandle($editor_style_handle)
80 80
     {
81
-        if (strpos($editor_style_handle, BlockInterface::NAME_SPACE . '-') !== 0) {
82
-            $editor_style_handle = BlockInterface::NAME_SPACE . '-' . $editor_style_handle;
81
+        if (strpos($editor_style_handle, BlockInterface::NAME_SPACE.'-') !== 0) {
82
+            $editor_style_handle = BlockInterface::NAME_SPACE.'-'.$editor_style_handle;
83 83
         }
84 84
         $this->editor_style_handle = $editor_style_handle;
85 85
     }
@@ -99,8 +99,8 @@  discard block
 block discarded – undo
99 99
      */
100 100
     public function setScriptHandle($script_handle)
101 101
     {
102
-        if (strpos($script_handle, BlockInterface::NAME_SPACE . '-') !== 0) {
103
-            $script_handle = BlockInterface::NAME_SPACE . '-' . $script_handle;
102
+        if (strpos($script_handle, BlockInterface::NAME_SPACE.'-') !== 0) {
103
+            $script_handle = BlockInterface::NAME_SPACE.'-'.$script_handle;
104 104
         }
105 105
         $this->script_handle = $script_handle;
106 106
     }
@@ -120,8 +120,8 @@  discard block
 block discarded – undo
120 120
      */
121 121
     public function setStyleHandle($style_handle)
122 122
     {
123
-        if (strpos($style_handle, BlockInterface::NAME_SPACE . '-') !== 0) {
124
-            $style_handle = BlockInterface::NAME_SPACE . '-' . $style_handle;
123
+        if (strpos($style_handle, BlockInterface::NAME_SPACE.'-') !== 0) {
124
+            $style_handle = BlockInterface::NAME_SPACE.'-'.$style_handle;
125 125
         }
126 126
         $this->style_handle = $style_handle;
127 127
     }
@@ -152,7 +152,7 @@  discard block
 block discarded – undo
152 152
      */
153 153
     public function addEditorScript($handle, array $dependencies = array())
154 154
     {
155
-        if($this->assets->has($handle)){
155
+        if ($this->assets->has($handle)) {
156 156
             return $this->assets->get($handle);
157 157
         }
158 158
         return parent::addJavascript(
@@ -251,9 +251,9 @@  discard block
 block discarded – undo
251 251
     {
252 252
         $dependencies += array(
253 253
                 CoreAssetManager::JS_HANDLE_EE_JS_CORE,
254
-                'wp-blocks',    // Provides useful functions and components for extending the editor
255
-                'wp-i18n',      // Provides localization functions
256
-                'wp-element',   // Provides React.Component
254
+                'wp-blocks', // Provides useful functions and components for extending the editor
255
+                'wp-i18n', // Provides localization functions
256
+                'wp-element', // Provides React.Component
257 257
                 'wp-components' // Provides many prebuilt components and controls
258 258
             );
259 259
         return $dependencies;
Please login to merge, or discard this patch.
Indentation   +305 added lines, -305 removed lines patch added patch discarded remove patch
@@ -22,310 +22,310 @@
 block discarded – undo
22 22
 abstract class BlockAssetManager extends AssetManager implements BlockAssetManagerInterface
23 23
 {
24 24
 
25
-    /**
26
-     * @var string $editor_script_handle
27
-     */
28
-    private $editor_script_handle;
29
-
30
-    /**
31
-     * @var string $editor_style_handle
32
-     */
33
-    private $editor_style_handle;
34
-
35
-    /**
36
-     * @var string $script_handle
37
-     */
38
-    private $script_handle;
39
-
40
-    /**
41
-     * @var string $style_handle
42
-     */
43
-    private $style_handle;
44
-
45
-
46
-    /**
47
-     * @return string
48
-     */
49
-    public function getEditorScriptHandle()
50
-    {
51
-        return $this->editor_script_handle;
52
-    }
53
-
54
-
55
-    /**
56
-     * @param string $editor_script_handle
57
-     */
58
-    public function setEditorScriptHandle($editor_script_handle)
59
-    {
60
-        if(strpos($editor_script_handle, BlockInterface::NAME_SPACE . '-') !== 0) {
61
-            $editor_script_handle = BlockInterface::NAME_SPACE . '-' . $editor_script_handle;
62
-        }
63
-        $this->editor_script_handle = $editor_script_handle;
64
-    }
65
-
66
-
67
-    /**
68
-     * @return string
69
-     */
70
-    public function getEditorStyleHandle()
71
-    {
72
-        return $this->editor_style_handle;
73
-    }
74
-
75
-
76
-    /**
77
-     * @param string $editor_style_handle
78
-     */
79
-    public function setEditorStyleHandle($editor_style_handle)
80
-    {
81
-        if (strpos($editor_style_handle, BlockInterface::NAME_SPACE . '-') !== 0) {
82
-            $editor_style_handle = BlockInterface::NAME_SPACE . '-' . $editor_style_handle;
83
-        }
84
-        $this->editor_style_handle = $editor_style_handle;
85
-    }
86
-
87
-
88
-    /**
89
-     * @return string
90
-     */
91
-    public function getScriptHandle()
92
-    {
93
-        return $this->script_handle;
94
-    }
95
-
96
-
97
-    /**
98
-     * @param string $script_handle
99
-     */
100
-    public function setScriptHandle($script_handle)
101
-    {
102
-        if (strpos($script_handle, BlockInterface::NAME_SPACE . '-') !== 0) {
103
-            $script_handle = BlockInterface::NAME_SPACE . '-' . $script_handle;
104
-        }
105
-        $this->script_handle = $script_handle;
106
-    }
107
-
108
-
109
-    /**
110
-     * @return string
111
-     */
112
-    public function getStyleHandle()
113
-    {
114
-        return $this->style_handle;
115
-    }
116
-
117
-
118
-    /**
119
-     * @param string $style_handle
120
-     */
121
-    public function setStyleHandle($style_handle)
122
-    {
123
-        if (strpos($style_handle, BlockInterface::NAME_SPACE . '-') !== 0) {
124
-            $style_handle = BlockInterface::NAME_SPACE . '-' . $style_handle;
125
-        }
126
-        $this->style_handle = $style_handle;
127
-    }
128
-
129
-    /**
130
-     * @since $VID:$
131
-     * @throws InvalidDataTypeException
132
-     * @throws InvalidEntityException
133
-     * @throws DuplicateCollectionIdentifierException
134
-     */
135
-    public function addAssets()
136
-    {
137
-        $this->addEditorScript($this->getEditorScriptHandle());
138
-        $this->addEditorStyle($this->getEditorStyleHandle());
139
-        $this->setScriptHandle($this->getScriptHandle());
140
-        $this->setStyleHandle($this->getStyleHandle());
141
-    }
142
-
143
-
144
-    /**
145
-     * @param       $handle
146
-     * @param array $dependencies
147
-     * @since $VID:$
148
-     * @return JavascriptAsset
149
-     * @throws InvalidDataTypeException
150
-     * @throws InvalidEntityException
151
-     * @throws DuplicateCollectionIdentifierException
152
-     */
153
-    public function addEditorScript($handle, array $dependencies = array())
154
-    {
155
-        if($this->assets->has($handle)){
156
-            return $this->assets->get($handle);
157
-        }
158
-        return parent::addJavascript(
159
-            $handle,
160
-            $this->registry->getJsUrl(
161
-                $this->domain->assetNamespace(),
162
-                $handle
163
-            ),
164
-            $this->addDefaultBlockScriptDependencies($dependencies)
165
-        )
166
-        ->setRequiresTranslation();
167
-    }
168
-
169
-
170
-    /**
171
-     * @param        $handle
172
-     * @param array  $dependencies
173
-     * @since $VID:$
174
-     * @return StylesheetAsset
175
-     * @throws InvalidDataTypeException
176
-     * @throws InvalidEntityException
177
-     * @throws DuplicateCollectionIdentifierException
178
-     */
179
-    public function addEditorStyle($handle, array $dependencies = array())
180
-    {
181
-        if ($this->assets->has($handle)) {
182
-            return $this->assets->get($handle);
183
-        }
184
-        return parent::addStylesheet(
185
-            $handle,
186
-            $this->registry->getCssUrl(
187
-                $this->domain->assetNamespace(),
188
-                $handle
189
-            ),
190
-            $dependencies
191
-        );
192
-    }
193
-
194
-
195
-    /**
196
-     * @param       $handle
197
-     * @param array $dependencies
198
-     * @since $VID:$
199
-     * @return JavascriptAsset
200
-     * @throws InvalidDataTypeException
201
-     * @throws InvalidEntityException
202
-     * @throws DuplicateCollectionIdentifierException
203
-     */
204
-    public function addScript($handle, array $dependencies = array())
205
-    {
206
-        if ($this->assets->has($handle)) {
207
-            return $this->assets->get($handle);
208
-        }
209
-        return parent::addJavascript(
210
-            $handle,
211
-            $this->registry->getJsUrl(
212
-                $this->domain->assetNamespace(),
213
-                $handle
214
-            ),
215
-            $this->addDefaultBlockScriptDependencies($dependencies)
216
-        )
217
-        ->setRequiresTranslation();
218
-    }
219
-
220
-
221
-    /**
222
-     * @param        $handle
223
-     * @param array  $dependencies
224
-     * @since $VID:$
225
-     * @return StylesheetAsset
226
-     * @throws InvalidDataTypeException
227
-     * @throws InvalidEntityException
228
-     * @throws DuplicateCollectionIdentifierException
229
-     */
230
-    public function addStyle($handle, array $dependencies = array())
231
-    {
232
-        if ($this->assets->has($handle)) {
233
-            return $this->assets->get($handle);
234
-        }
235
-        return parent::addStylesheet(
236
-            $handle,
237
-            $this->registry->getCssUrl(
238
-                $this->domain->assetNamespace(),
239
-                $handle
240
-            ),
241
-            $dependencies
242
-        );
243
-    }
244
-
245
-
246
-    /**
247
-     * @param array $dependencies
248
-     * @return array
249
-     */
250
-    protected function addDefaultBlockScriptDependencies(array $dependencies)
251
-    {
252
-        $dependencies += array(
253
-                CoreAssetManager::JS_HANDLE_EE_JS_CORE,
254
-                'wp-blocks',    // Provides useful functions and components for extending the editor
255
-                'wp-i18n',      // Provides localization functions
256
-                'wp-element',   // Provides React.Component
257
-                'wp-components' // Provides many prebuilt components and controls
258
-            );
259
-        return $dependencies;
260
-    }
261
-
262
-
263
-    /**
264
-     * @param string $handle
265
-     * @since $VID:$
266
-     * @return mixed|null
267
-     */
268
-    public function getAsset($handle)
269
-    {
270
-        if ($this->assets->has($handle)) {
271
-            return $this->assets->get($handle);
272
-        }
273
-        return null;
274
-    }
275
-
276
-
277
-    /**
278
-     * @return JavascriptAsset|null
279
-     */
280
-    public function getEditorScript()
281
-    {
282
-        return $this->getAsset($this->editor_script_handle);
283
-    }
284
-
285
-
286
-    /**
287
-     * @return StylesheetAsset|null
288
-     */
289
-    public function getEditorStyle()
290
-    {
291
-        return $this->getAsset($this->editor_style_handle);
292
-    }
293
-
294
-
295
-    /**
296
-     * @return JavascriptAsset|null
297
-     */
298
-    public function getScript()
299
-    {
300
-        return $this->getAsset($this->script_handle);
301
-    }
302
-
303
-
304
-    /**
305
-     * @return StylesheetAsset|null
306
-     */
307
-    public function getStyle()
308
-    {
309
-        return $this->getAsset($this->style_handle);
310
-    }
311
-
312
-
313
-    /**
314
-     * @return  void
315
-     */
316
-    public function enqueueAssets()
317
-    {
318
-        $assets = array(
319
-            $this->getEditorScript(),
320
-            $this->getEditorStyle(),
321
-            $this->getScript(),
322
-            $this->getStyle(),
323
-        );
324
-        foreach ($assets as $asset) {
325
-            if ($asset instanceof BrowserAsset && $asset->isRegistered()) {
326
-                $asset->enqueueAsset();
327
-            }
328
-        }
329
-    }
25
+	/**
26
+	 * @var string $editor_script_handle
27
+	 */
28
+	private $editor_script_handle;
29
+
30
+	/**
31
+	 * @var string $editor_style_handle
32
+	 */
33
+	private $editor_style_handle;
34
+
35
+	/**
36
+	 * @var string $script_handle
37
+	 */
38
+	private $script_handle;
39
+
40
+	/**
41
+	 * @var string $style_handle
42
+	 */
43
+	private $style_handle;
44
+
45
+
46
+	/**
47
+	 * @return string
48
+	 */
49
+	public function getEditorScriptHandle()
50
+	{
51
+		return $this->editor_script_handle;
52
+	}
53
+
54
+
55
+	/**
56
+	 * @param string $editor_script_handle
57
+	 */
58
+	public function setEditorScriptHandle($editor_script_handle)
59
+	{
60
+		if(strpos($editor_script_handle, BlockInterface::NAME_SPACE . '-') !== 0) {
61
+			$editor_script_handle = BlockInterface::NAME_SPACE . '-' . $editor_script_handle;
62
+		}
63
+		$this->editor_script_handle = $editor_script_handle;
64
+	}
65
+
66
+
67
+	/**
68
+	 * @return string
69
+	 */
70
+	public function getEditorStyleHandle()
71
+	{
72
+		return $this->editor_style_handle;
73
+	}
74
+
75
+
76
+	/**
77
+	 * @param string $editor_style_handle
78
+	 */
79
+	public function setEditorStyleHandle($editor_style_handle)
80
+	{
81
+		if (strpos($editor_style_handle, BlockInterface::NAME_SPACE . '-') !== 0) {
82
+			$editor_style_handle = BlockInterface::NAME_SPACE . '-' . $editor_style_handle;
83
+		}
84
+		$this->editor_style_handle = $editor_style_handle;
85
+	}
86
+
87
+
88
+	/**
89
+	 * @return string
90
+	 */
91
+	public function getScriptHandle()
92
+	{
93
+		return $this->script_handle;
94
+	}
95
+
96
+
97
+	/**
98
+	 * @param string $script_handle
99
+	 */
100
+	public function setScriptHandle($script_handle)
101
+	{
102
+		if (strpos($script_handle, BlockInterface::NAME_SPACE . '-') !== 0) {
103
+			$script_handle = BlockInterface::NAME_SPACE . '-' . $script_handle;
104
+		}
105
+		$this->script_handle = $script_handle;
106
+	}
107
+
108
+
109
+	/**
110
+	 * @return string
111
+	 */
112
+	public function getStyleHandle()
113
+	{
114
+		return $this->style_handle;
115
+	}
116
+
117
+
118
+	/**
119
+	 * @param string $style_handle
120
+	 */
121
+	public function setStyleHandle($style_handle)
122
+	{
123
+		if (strpos($style_handle, BlockInterface::NAME_SPACE . '-') !== 0) {
124
+			$style_handle = BlockInterface::NAME_SPACE . '-' . $style_handle;
125
+		}
126
+		$this->style_handle = $style_handle;
127
+	}
128
+
129
+	/**
130
+	 * @since $VID:$
131
+	 * @throws InvalidDataTypeException
132
+	 * @throws InvalidEntityException
133
+	 * @throws DuplicateCollectionIdentifierException
134
+	 */
135
+	public function addAssets()
136
+	{
137
+		$this->addEditorScript($this->getEditorScriptHandle());
138
+		$this->addEditorStyle($this->getEditorStyleHandle());
139
+		$this->setScriptHandle($this->getScriptHandle());
140
+		$this->setStyleHandle($this->getStyleHandle());
141
+	}
142
+
143
+
144
+	/**
145
+	 * @param       $handle
146
+	 * @param array $dependencies
147
+	 * @since $VID:$
148
+	 * @return JavascriptAsset
149
+	 * @throws InvalidDataTypeException
150
+	 * @throws InvalidEntityException
151
+	 * @throws DuplicateCollectionIdentifierException
152
+	 */
153
+	public function addEditorScript($handle, array $dependencies = array())
154
+	{
155
+		if($this->assets->has($handle)){
156
+			return $this->assets->get($handle);
157
+		}
158
+		return parent::addJavascript(
159
+			$handle,
160
+			$this->registry->getJsUrl(
161
+				$this->domain->assetNamespace(),
162
+				$handle
163
+			),
164
+			$this->addDefaultBlockScriptDependencies($dependencies)
165
+		)
166
+		->setRequiresTranslation();
167
+	}
168
+
169
+
170
+	/**
171
+	 * @param        $handle
172
+	 * @param array  $dependencies
173
+	 * @since $VID:$
174
+	 * @return StylesheetAsset
175
+	 * @throws InvalidDataTypeException
176
+	 * @throws InvalidEntityException
177
+	 * @throws DuplicateCollectionIdentifierException
178
+	 */
179
+	public function addEditorStyle($handle, array $dependencies = array())
180
+	{
181
+		if ($this->assets->has($handle)) {
182
+			return $this->assets->get($handle);
183
+		}
184
+		return parent::addStylesheet(
185
+			$handle,
186
+			$this->registry->getCssUrl(
187
+				$this->domain->assetNamespace(),
188
+				$handle
189
+			),
190
+			$dependencies
191
+		);
192
+	}
193
+
194
+
195
+	/**
196
+	 * @param       $handle
197
+	 * @param array $dependencies
198
+	 * @since $VID:$
199
+	 * @return JavascriptAsset
200
+	 * @throws InvalidDataTypeException
201
+	 * @throws InvalidEntityException
202
+	 * @throws DuplicateCollectionIdentifierException
203
+	 */
204
+	public function addScript($handle, array $dependencies = array())
205
+	{
206
+		if ($this->assets->has($handle)) {
207
+			return $this->assets->get($handle);
208
+		}
209
+		return parent::addJavascript(
210
+			$handle,
211
+			$this->registry->getJsUrl(
212
+				$this->domain->assetNamespace(),
213
+				$handle
214
+			),
215
+			$this->addDefaultBlockScriptDependencies($dependencies)
216
+		)
217
+		->setRequiresTranslation();
218
+	}
219
+
220
+
221
+	/**
222
+	 * @param        $handle
223
+	 * @param array  $dependencies
224
+	 * @since $VID:$
225
+	 * @return StylesheetAsset
226
+	 * @throws InvalidDataTypeException
227
+	 * @throws InvalidEntityException
228
+	 * @throws DuplicateCollectionIdentifierException
229
+	 */
230
+	public function addStyle($handle, array $dependencies = array())
231
+	{
232
+		if ($this->assets->has($handle)) {
233
+			return $this->assets->get($handle);
234
+		}
235
+		return parent::addStylesheet(
236
+			$handle,
237
+			$this->registry->getCssUrl(
238
+				$this->domain->assetNamespace(),
239
+				$handle
240
+			),
241
+			$dependencies
242
+		);
243
+	}
244
+
245
+
246
+	/**
247
+	 * @param array $dependencies
248
+	 * @return array
249
+	 */
250
+	protected function addDefaultBlockScriptDependencies(array $dependencies)
251
+	{
252
+		$dependencies += array(
253
+				CoreAssetManager::JS_HANDLE_EE_JS_CORE,
254
+				'wp-blocks',    // Provides useful functions and components for extending the editor
255
+				'wp-i18n',      // Provides localization functions
256
+				'wp-element',   // Provides React.Component
257
+				'wp-components' // Provides many prebuilt components and controls
258
+			);
259
+		return $dependencies;
260
+	}
261
+
262
+
263
+	/**
264
+	 * @param string $handle
265
+	 * @since $VID:$
266
+	 * @return mixed|null
267
+	 */
268
+	public function getAsset($handle)
269
+	{
270
+		if ($this->assets->has($handle)) {
271
+			return $this->assets->get($handle);
272
+		}
273
+		return null;
274
+	}
275
+
276
+
277
+	/**
278
+	 * @return JavascriptAsset|null
279
+	 */
280
+	public function getEditorScript()
281
+	{
282
+		return $this->getAsset($this->editor_script_handle);
283
+	}
284
+
285
+
286
+	/**
287
+	 * @return StylesheetAsset|null
288
+	 */
289
+	public function getEditorStyle()
290
+	{
291
+		return $this->getAsset($this->editor_style_handle);
292
+	}
293
+
294
+
295
+	/**
296
+	 * @return JavascriptAsset|null
297
+	 */
298
+	public function getScript()
299
+	{
300
+		return $this->getAsset($this->script_handle);
301
+	}
302
+
303
+
304
+	/**
305
+	 * @return StylesheetAsset|null
306
+	 */
307
+	public function getStyle()
308
+	{
309
+		return $this->getAsset($this->style_handle);
310
+	}
311
+
312
+
313
+	/**
314
+	 * @return  void
315
+	 */
316
+	public function enqueueAssets()
317
+	{
318
+		$assets = array(
319
+			$this->getEditorScript(),
320
+			$this->getEditorStyle(),
321
+			$this->getScript(),
322
+			$this->getStyle(),
323
+		);
324
+		foreach ($assets as $asset) {
325
+			if ($asset instanceof BrowserAsset && $asset->isRegistered()) {
326
+				$asset->enqueueAsset();
327
+			}
328
+		}
329
+	}
330 330
 
331 331
 }
Please login to merge, or discard this patch.