Completed
Pull Request — FET/Gutenberg/11400/block-mana... (#317)
by
unknown
13:28
created
core/domain/entities/editor/EditorBlock.php 2 patches
Indentation   +248 added lines, -248 removed lines patch added patch discarded remove patch
@@ -29,252 +29,252 @@
 block discarded – undo
29 29
 abstract class EditorBlock implements EditorBlockInterface
30 30
 {
31 31
 
32
-    const NS = 'event-espresso/';
33
-
34
-    /**
35
-     * @var DomainInterface $domain
36
-     */
37
-    protected $domain;
38
-
39
-    /**
40
-     * @var LoaderInterface $loader
41
-     */
42
-    protected $loader;
43
-
44
-    /**
45
-     * @var Registry
46
-     */
47
-    protected $registry;
48
-
49
-    /**
50
-     * @var string $editor_block_type
51
-     */
52
-    private $editor_block_type;
53
-
54
-    /**
55
-     * AssetRegister that this editor block uses for asset registration
56
-     *
57
-     * @var AssetRegisterInterface $asset_register_fqcn
58
-     */
59
-    private $asset_register;
60
-
61
-    /**
62
-     * @var WP_Block_Type $wp_block_type
63
-     */
64
-    private $wp_block_type;
65
-
66
-    /**
67
-     * @var array $supported_post_types
68
-     */
69
-    private $supported_post_types;
70
-
71
-    /**
72
-     * @var array $attributes
73
-     */
74
-    private $attributes;
75
-
76
-    /**
77
-     * If set to true, then the block will render its content client side
78
-     * If false, then the block will render its content server side using the renderBlock() method
79
-     *
80
-     * @var bool $dynamic
81
-     */
82
-    private $dynamic = false;
83
-
84
-
85
-    /**
86
-     * EditorBlockLoader constructor.
87
-     *
88
-     * @param DomainInterface $domain
89
-     * @param LoaderInterface $loader
90
-     * @param Registry        $assets_registry
91
-     */
92
-    public function __construct(
93
-        DomainInterface $domain,
94
-        LoaderInterface $loader,
95
-        Registry $assets_registry
96
-    ) {
97
-        $this->domain   = $domain;
98
-        $this->loader   = $loader;
99
-        $this->registry = $assets_registry;
100
-    }
101
-
102
-
103
-    /**
104
-     * @return string
105
-     */
106
-    public function editorBlockType()
107
-    {
108
-        return $this->editor_block_type;
109
-    }
110
-
111
-
112
-    /**
113
-     * @return string
114
-     */
115
-    public function namespacedEditorBlockType()
116
-    {
117
-        return EditorBlock::NS . $this->editor_block_type;
118
-    }
119
-
120
-
121
-    /**
122
-     * @param string $editor_block_type
123
-     */
124
-    protected function setEditorBlockType($editor_block_type)
125
-    {
126
-        $this->editor_block_type = $editor_block_type;
127
-    }
128
-
129
-
130
-    /**
131
-     * AssetRegister that this editor block uses for asset registration
132
-     *
133
-     * @return AssetRegisterInterface
134
-     */
135
-    public function assetRegister()
136
-    {
137
-        return $this->asset_register;
138
-    }
139
-
140
-
141
-    /**
142
-     * @param string asset_register_fqcn
143
-     */
144
-    protected function setAssetRegisterFqcn($asset_register_fqcn)
145
-    {
146
-        $this->asset_register = $this->loader->getShared($asset_register_fqcn);
147
-    }
148
-
149
-
150
-    /**
151
-     * @param WP_Block_Type $wp_block_type
152
-     */
153
-    protected function setWpBlockType($wp_block_type)
154
-    {
155
-        $this->wp_block_type = $wp_block_type;
156
-    }
157
-
158
-
159
-    /**
160
-     * @param array $supported_post_types
161
-     */
162
-    protected function setSupportedPostTypes(array $supported_post_types)
163
-    {
164
-        $this->supported_post_types = $supported_post_types;
165
-    }
166
-
167
-
168
-    /**
169
-     * @return array
170
-     */
171
-    public function attributes()
172
-    {
173
-        return $this->attributes;
174
-    }
175
-
176
-
177
-    /**
178
-     * @param array $attributes
179
-     */
180
-    public function setAttributes(array $attributes)
181
-    {
182
-        $this->attributes = $attributes;
183
-    }
184
-
185
-
186
-    /**
187
-     * @return bool
188
-     */
189
-    public function isDynamic()
190
-    {
191
-        return $this->dynamic;
192
-    }
193
-
194
-
195
-    /**
196
-     * @param bool $dynamic
197
-     */
198
-    public function setDynamic($dynamic = true)
199
-    {
200
-        $this->dynamic = filter_var($dynamic, FILTER_VALIDATE_BOOLEAN);
201
-    }
202
-
203
-
204
-    /**
205
-     * Registers the Editor Block with WP core;
206
-     * Returns the registered block type on success, or false on failure.
207
-     *
208
-     * @return WP_Block_Type|false
209
-     */
210
-    public function registerBlock()
211
-    {
212
-        $context ='core';
213
-        // todo add route detection (ie inject route) and change context based on route
214
-        $args          = array(
215
-            'attributes'      => $this->attributes(),
216
-            'editor_script'   => "{$context}-blocks",
217
-            'editor_style'    => "{$context}-blocks",
218
-            'script'          => "{$context}-blocks",
219
-            'style'           => "{$context}-blocks",
220
-        );
221
-        if(! $this->isDynamic()) {
222
-            $args['render_callback'] = $this->renderBlock();
223
-        }
224
-        $wp_block_type = register_block_type(
225
-            new WP_Block_Type(
226
-                $this->namespacedEditorBlockType(),
227
-                $args
228
-            )
229
-        );
230
-        $this->setWpBlockType($wp_block_type);
231
-        return $wp_block_type;
232
-    }
233
-
234
-
235
-    /**
236
-     * @return WP_Block_Type|false The registered block type on success, or false on failure.
237
-     */
238
-    public function unRegisterBlock()
239
-    {
240
-        return unregister_block_type($this->namespacedEditorBlockType());
241
-    }
242
-
243
-
244
-    /**
245
-     * returns true if the block type applies for the supplied post type
246
-     * and should be added to that post type's editor
247
-     *
248
-     * @param string $post_type
249
-     * @return boolean
250
-     */
251
-    public function appliesToPostType($post_type)
252
-    {
253
-        return in_array($post_type, $this->supported_post_types, true);
254
-    }
255
-
256
-
257
-    /**
258
-     * @return array
259
-     */
260
-    public function getEditorContainer()
261
-    {
262
-        return array(
263
-            $this->namespacedEditorBlockType(),
264
-            array()
265
-        );
266
-    }
267
-
268
-
269
-
270
-    /**
271
-     * returns the rendered HTML for the block
272
-     *
273
-     * @param array $attributes
274
-     * @return string
275
-     */
276
-    public function renderBlock(array $attributes = array())
277
-    {
278
-        return '';
279
-    }
32
+	const NS = 'event-espresso/';
33
+
34
+	/**
35
+	 * @var DomainInterface $domain
36
+	 */
37
+	protected $domain;
38
+
39
+	/**
40
+	 * @var LoaderInterface $loader
41
+	 */
42
+	protected $loader;
43
+
44
+	/**
45
+	 * @var Registry
46
+	 */
47
+	protected $registry;
48
+
49
+	/**
50
+	 * @var string $editor_block_type
51
+	 */
52
+	private $editor_block_type;
53
+
54
+	/**
55
+	 * AssetRegister that this editor block uses for asset registration
56
+	 *
57
+	 * @var AssetRegisterInterface $asset_register_fqcn
58
+	 */
59
+	private $asset_register;
60
+
61
+	/**
62
+	 * @var WP_Block_Type $wp_block_type
63
+	 */
64
+	private $wp_block_type;
65
+
66
+	/**
67
+	 * @var array $supported_post_types
68
+	 */
69
+	private $supported_post_types;
70
+
71
+	/**
72
+	 * @var array $attributes
73
+	 */
74
+	private $attributes;
75
+
76
+	/**
77
+	 * If set to true, then the block will render its content client side
78
+	 * If false, then the block will render its content server side using the renderBlock() method
79
+	 *
80
+	 * @var bool $dynamic
81
+	 */
82
+	private $dynamic = false;
83
+
84
+
85
+	/**
86
+	 * EditorBlockLoader constructor.
87
+	 *
88
+	 * @param DomainInterface $domain
89
+	 * @param LoaderInterface $loader
90
+	 * @param Registry        $assets_registry
91
+	 */
92
+	public function __construct(
93
+		DomainInterface $domain,
94
+		LoaderInterface $loader,
95
+		Registry $assets_registry
96
+	) {
97
+		$this->domain   = $domain;
98
+		$this->loader   = $loader;
99
+		$this->registry = $assets_registry;
100
+	}
101
+
102
+
103
+	/**
104
+	 * @return string
105
+	 */
106
+	public function editorBlockType()
107
+	{
108
+		return $this->editor_block_type;
109
+	}
110
+
111
+
112
+	/**
113
+	 * @return string
114
+	 */
115
+	public function namespacedEditorBlockType()
116
+	{
117
+		return EditorBlock::NS . $this->editor_block_type;
118
+	}
119
+
120
+
121
+	/**
122
+	 * @param string $editor_block_type
123
+	 */
124
+	protected function setEditorBlockType($editor_block_type)
125
+	{
126
+		$this->editor_block_type = $editor_block_type;
127
+	}
128
+
129
+
130
+	/**
131
+	 * AssetRegister that this editor block uses for asset registration
132
+	 *
133
+	 * @return AssetRegisterInterface
134
+	 */
135
+	public function assetRegister()
136
+	{
137
+		return $this->asset_register;
138
+	}
139
+
140
+
141
+	/**
142
+	 * @param string asset_register_fqcn
143
+	 */
144
+	protected function setAssetRegisterFqcn($asset_register_fqcn)
145
+	{
146
+		$this->asset_register = $this->loader->getShared($asset_register_fqcn);
147
+	}
148
+
149
+
150
+	/**
151
+	 * @param WP_Block_Type $wp_block_type
152
+	 */
153
+	protected function setWpBlockType($wp_block_type)
154
+	{
155
+		$this->wp_block_type = $wp_block_type;
156
+	}
157
+
158
+
159
+	/**
160
+	 * @param array $supported_post_types
161
+	 */
162
+	protected function setSupportedPostTypes(array $supported_post_types)
163
+	{
164
+		$this->supported_post_types = $supported_post_types;
165
+	}
166
+
167
+
168
+	/**
169
+	 * @return array
170
+	 */
171
+	public function attributes()
172
+	{
173
+		return $this->attributes;
174
+	}
175
+
176
+
177
+	/**
178
+	 * @param array $attributes
179
+	 */
180
+	public function setAttributes(array $attributes)
181
+	{
182
+		$this->attributes = $attributes;
183
+	}
184
+
185
+
186
+	/**
187
+	 * @return bool
188
+	 */
189
+	public function isDynamic()
190
+	{
191
+		return $this->dynamic;
192
+	}
193
+
194
+
195
+	/**
196
+	 * @param bool $dynamic
197
+	 */
198
+	public function setDynamic($dynamic = true)
199
+	{
200
+		$this->dynamic = filter_var($dynamic, FILTER_VALIDATE_BOOLEAN);
201
+	}
202
+
203
+
204
+	/**
205
+	 * Registers the Editor Block with WP core;
206
+	 * Returns the registered block type on success, or false on failure.
207
+	 *
208
+	 * @return WP_Block_Type|false
209
+	 */
210
+	public function registerBlock()
211
+	{
212
+		$context ='core';
213
+		// todo add route detection (ie inject route) and change context based on route
214
+		$args          = array(
215
+			'attributes'      => $this->attributes(),
216
+			'editor_script'   => "{$context}-blocks",
217
+			'editor_style'    => "{$context}-blocks",
218
+			'script'          => "{$context}-blocks",
219
+			'style'           => "{$context}-blocks",
220
+		);
221
+		if(! $this->isDynamic()) {
222
+			$args['render_callback'] = $this->renderBlock();
223
+		}
224
+		$wp_block_type = register_block_type(
225
+			new WP_Block_Type(
226
+				$this->namespacedEditorBlockType(),
227
+				$args
228
+			)
229
+		);
230
+		$this->setWpBlockType($wp_block_type);
231
+		return $wp_block_type;
232
+	}
233
+
234
+
235
+	/**
236
+	 * @return WP_Block_Type|false The registered block type on success, or false on failure.
237
+	 */
238
+	public function unRegisterBlock()
239
+	{
240
+		return unregister_block_type($this->namespacedEditorBlockType());
241
+	}
242
+
243
+
244
+	/**
245
+	 * returns true if the block type applies for the supplied post type
246
+	 * and should be added to that post type's editor
247
+	 *
248
+	 * @param string $post_type
249
+	 * @return boolean
250
+	 */
251
+	public function appliesToPostType($post_type)
252
+	{
253
+		return in_array($post_type, $this->supported_post_types, true);
254
+	}
255
+
256
+
257
+	/**
258
+	 * @return array
259
+	 */
260
+	public function getEditorContainer()
261
+	{
262
+		return array(
263
+			$this->namespacedEditorBlockType(),
264
+			array()
265
+		);
266
+	}
267
+
268
+
269
+
270
+	/**
271
+	 * returns the rendered HTML for the block
272
+	 *
273
+	 * @param array $attributes
274
+	 * @return string
275
+	 */
276
+	public function renderBlock(array $attributes = array())
277
+	{
278
+		return '';
279
+	}
280 280
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -114,7 +114,7 @@  discard block
 block discarded – undo
114 114
      */
115 115
     public function namespacedEditorBlockType()
116 116
     {
117
-        return EditorBlock::NS . $this->editor_block_type;
117
+        return EditorBlock::NS.$this->editor_block_type;
118 118
     }
119 119
 
120 120
 
@@ -209,16 +209,16 @@  discard block
 block discarded – undo
209 209
      */
210 210
     public function registerBlock()
211 211
     {
212
-        $context ='core';
212
+        $context = 'core';
213 213
         // todo add route detection (ie inject route) and change context based on route
214
-        $args          = array(
214
+        $args = array(
215 215
             'attributes'      => $this->attributes(),
216 216
             'editor_script'   => "{$context}-blocks",
217 217
             'editor_style'    => "{$context}-blocks",
218 218
             'script'          => "{$context}-blocks",
219 219
             'style'           => "{$context}-blocks",
220 220
         );
221
-        if(! $this->isDynamic()) {
221
+        if ( ! $this->isDynamic()) {
222 222
             $args['render_callback'] = $this->renderBlock();
223 223
         }
224 224
         $wp_block_type = register_block_type(
Please login to merge, or discard this patch.