| 1 |
<?php // phpcs:ignore SlevomatCodingStandard.TypeHints.DeclareStrictTypes.DeclareStrictTypesMissing |
| 2 |
|
| 3 |
namespace MailPoet\PostEditorBlocks; |
| 4 |
|
| 5 |
if (!defined('ABSPATH')) exit; |
| 6 |
|
| 7 |
|
| 8 |
use MailPoet\Config\Env; |
| 9 |
use MailPoet\Config\Renderer; |
| 10 |
use MailPoet\WP\Functions as WPFunctions; |
| 11 |
|
| 12 |
class PostEditorBlock { |
| 13 |
/** @var Renderer */ |
| 14 |
private $renderer; |
| 15 |
|
| 16 |
/** @var WPFunctions */ |
| 17 |
private $wp; |
| 18 |
|
| 19 |
/** @var SubscriptionFormBlock */ |
| 20 |
private $subscriptionFormBlock; |
| 21 |
|
| 22 |
public function __construct( |
| 23 |
Renderer $renderer, |
| 24 |
WPFunctions $wp, |
| 25 |
SubscriptionFormBlock $subscriptionFormBlock |
| 26 |
) { |
| 27 |
$this->renderer = $renderer; |
| 28 |
$this->wp = $wp; |
| 29 |
$this->subscriptionFormBlock = $subscriptionFormBlock; |
| 30 |
} |
| 31 |
|
| 32 |
public function init() { |
| 33 |
$this->subscriptionFormBlock->init(); |
| 34 |
|
| 35 |
if (is_admin()) { |
| 36 |
$this->initAdmin(); |
| 37 |
} else { |
| 38 |
$this->initFrontend(); |
| 39 |
} |
| 40 |
} |
| 41 |
|
| 42 |
private function initAdmin() { |
| 43 |
$this->wp->addAction('enqueue_block_editor_assets', [$this, 'enqueueAssets']); |
| 44 |
$this->subscriptionFormBlock->initAdmin(); |
| 45 |
} |
| 46 |
|
| 47 |
public function enqueueAssets() { |
| 48 |
$this->wp->wpEnqueueScript( |
| 49 |
'mailpoet-block-form-block-js', |
| 50 |
Env::$assetsUrl . '/dist/js/' . $this->renderer->getJsAsset('post_editor_block.js'), |
| 51 |
['wp-blocks', 'wp-components', 'wp-server-side-render', 'wp-block-editor'], |
| 52 |
Env::$version, |
| 53 |
true |
| 54 |
); |
| 55 |
|
| 56 |
$this->wp->wpEnqueueStyle( |
| 57 |
'mailpoetblock-form-block-css', |
| 58 |
Env::$assetsUrl . '/dist/css/' . $this->renderer->getCssAsset('mailpoet-post-editor-block.css'), |
| 59 |
['wp-edit-blocks'], |
| 60 |
Env::$version |
| 61 |
); |
| 62 |
} |
| 63 |
|
| 64 |
private function initFrontend() { |
| 65 |
$this->subscriptionFormBlock->initFrontend(); |
| 66 |
} |
| 67 |
} |
| 68 |
|