Use AssetsLoader for enqueue css in formEditor

[MAILPOET-3556]
This commit is contained in:
Jan Lysý
2021-04-20 11:05:07 +02:00
committed by Veljko V
parent e79ff273fe
commit 5347714bbe
4 changed files with 58 additions and 23 deletions

View File

@ -0,0 +1,33 @@
<?php
namespace MailPoet\Config;
use MailPoet\WP\Functions as WPFunctions;
class AssetsLoader {
/** @var Renderer */
private $renderer;
/** @var WPFunctions */
private $wp;
public function __construct(RendererFactory $rendererFactory, WPFunctions $wp) {
$this->renderer = $rendererFactory->getRenderer();
$this->wp = $wp;
}
public function loadStyles(): void {
if (isset($_GET['page']) && $_GET['page'] === 'mailpoet-form-editor') {
$this->enqueueStyle('mailpoet-form-editor');
$this->enqueueStyle('mailpoet-public');
}
}
private function enqueueStyle(string $name): void {
$this->wp->wpEnqueueStyle(
$name,
Env::$assetsUrl . '/dist/css/' . $this->renderer->getCssAsset("{$name}.css")
);
}
}