@@ -22,310 +22,310 @@ |
||
| 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 | - ->setHasLocalizedData(); |
|
| 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 | - ->setHasLocalizedData(); |
|
| 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 | + ->setHasLocalizedData(); |
|
| 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 | + ->setHasLocalizedData(); |
|
| 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 | } |
@@ -57,8 +57,8 @@ discard block |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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; |