Move simple-light template from the engine/package to the free plugin
The additional templates are registered by integrators. This way, we will be able to use assets like images from MailPoet's CDN and also various services from the plugins (e.g. CdnAssetsController) [MAILPOET-6356]
This commit is contained in:
committed by
Rostislav Wolný
parent
6eca06780f
commit
2c3932bdd3
@@ -368,6 +368,7 @@ class ContainerConfigurator implements IContainerConfigurator {
|
|||||||
$container->autowire(\MailPoet\EmailEditor\Integrations\MailPoet\PersonalizationTags\Site::class)->setPublic(true);
|
$container->autowire(\MailPoet\EmailEditor\Integrations\MailPoet\PersonalizationTags\Site::class)->setPublic(true);
|
||||||
$container->autowire(\MailPoet\EmailEditor\Integrations\MailPoet\PersonalizationTags\Subscriber::class)->setPublic(true);
|
$container->autowire(\MailPoet\EmailEditor\Integrations\MailPoet\PersonalizationTags\Subscriber::class)->setPublic(true);
|
||||||
$container->autowire(\MailPoet\EmailEditor\Integrations\MailPoet\PersonalizationTagManager::class)->setPublic(true);
|
$container->autowire(\MailPoet\EmailEditor\Integrations\MailPoet\PersonalizationTagManager::class)->setPublic(true);
|
||||||
|
$container->autowire(\MailPoet\EmailEditor\Integrations\MailPoet\Templates\TemplatesController::class)->setPublic(true);
|
||||||
// Features
|
// Features
|
||||||
$container->autowire(\MailPoet\Features\FeaturesController::class)->setPublic(true);
|
$container->autowire(\MailPoet\Features\FeaturesController::class)->setPublic(true);
|
||||||
$container->autowire(\MailPoet\Features\FeatureFlagsController::class)->setPublic(true);
|
$container->autowire(\MailPoet\Features\FeatureFlagsController::class)->setPublic(true);
|
||||||
|
@@ -3,6 +3,7 @@
|
|||||||
namespace MailPoet\EmailEditor\Integrations\MailPoet;
|
namespace MailPoet\EmailEditor\Integrations\MailPoet;
|
||||||
|
|
||||||
use MailPoet\EmailEditor\Integrations\MailPoet\Patterns\PatternsController;
|
use MailPoet\EmailEditor\Integrations\MailPoet\Patterns\PatternsController;
|
||||||
|
use MailPoet\EmailEditor\Integrations\MailPoet\Templates\TemplatesController;
|
||||||
use MailPoet\Features\FeaturesController;
|
use MailPoet\Features\FeaturesController;
|
||||||
use MailPoet\WP\Functions as WPFunctions;
|
use MailPoet\WP\Functions as WPFunctions;
|
||||||
|
|
||||||
@@ -25,6 +26,8 @@ class EmailEditor {
|
|||||||
|
|
||||||
private PersonalizationTagManager $personalizationTagManager;
|
private PersonalizationTagManager $personalizationTagManager;
|
||||||
|
|
||||||
|
private TemplatesController $templatesController;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
WPFunctions $wp,
|
WPFunctions $wp,
|
||||||
FeaturesController $featuresController,
|
FeaturesController $featuresController,
|
||||||
@@ -32,6 +35,7 @@ class EmailEditor {
|
|||||||
EditorPageRenderer $editorPageRenderer,
|
EditorPageRenderer $editorPageRenderer,
|
||||||
EmailEditorPreviewEmail $emailEditorPreviewEmail,
|
EmailEditorPreviewEmail $emailEditorPreviewEmail,
|
||||||
PatternsController $patternsController,
|
PatternsController $patternsController,
|
||||||
|
TemplatesController $templatesController,
|
||||||
Cli $cli,
|
Cli $cli,
|
||||||
PersonalizationTagManager $personalizationTagManager
|
PersonalizationTagManager $personalizationTagManager
|
||||||
) {
|
) {
|
||||||
@@ -40,6 +44,7 @@ class EmailEditor {
|
|||||||
$this->emailApiController = $emailApiController;
|
$this->emailApiController = $emailApiController;
|
||||||
$this->editorPageRenderer = $editorPageRenderer;
|
$this->editorPageRenderer = $editorPageRenderer;
|
||||||
$this->patternsController = $patternsController;
|
$this->patternsController = $patternsController;
|
||||||
|
$this->templatesController = $templatesController;
|
||||||
$this->cli = $cli;
|
$this->cli = $cli;
|
||||||
$this->emailEditorPreviewEmail = $emailEditorPreviewEmail;
|
$this->emailEditorPreviewEmail = $emailEditorPreviewEmail;
|
||||||
$this->personalizationTagManager = $personalizationTagManager;
|
$this->personalizationTagManager = $personalizationTagManager;
|
||||||
@@ -56,6 +61,7 @@ class EmailEditor {
|
|||||||
$this->wp->addFilter('replace_editor', [$this, 'replaceEditor'], 10, 2);
|
$this->wp->addFilter('replace_editor', [$this, 'replaceEditor'], 10, 2);
|
||||||
$this->wp->addFilter('mailpoet_email_editor_send_preview_email', [$this->emailEditorPreviewEmail, 'sendPreviewEmail'], 10, 1);
|
$this->wp->addFilter('mailpoet_email_editor_send_preview_email', [$this->emailEditorPreviewEmail, 'sendPreviewEmail'], 10, 1);
|
||||||
$this->patternsController->registerPatterns();
|
$this->patternsController->registerPatterns();
|
||||||
|
$this->templatesController->initialize();
|
||||||
$this->extendEmailPostApi();
|
$this->extendEmailPostApi();
|
||||||
$this->personalizationTagManager->initialize();
|
$this->personalizationTagManager->initialize();
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,39 @@
|
|||||||
|
<?php declare(strict_types = 1);
|
||||||
|
|
||||||
|
namespace MailPoet\EmailEditor\Integrations\MailPoet\Templates;
|
||||||
|
|
||||||
|
use MailPoet\EmailEditor\Integrations\MailPoet\EmailEditor;
|
||||||
|
use MailPoet\WP\Functions as WPFunctions;
|
||||||
|
|
||||||
|
class TemplatesController {
|
||||||
|
private string $templatePrefix = 'mailpoet';
|
||||||
|
private WPFunctions $wp;
|
||||||
|
|
||||||
|
public function __construct(
|
||||||
|
WPFunctions $wp
|
||||||
|
) {
|
||||||
|
$this->wp = $wp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function initialize() {
|
||||||
|
$this->wp->addAction('mailpoet_email_editor_register_templates', [$this, 'registerTemplates'], 10, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function registerTemplates() {
|
||||||
|
$simpleLight = [
|
||||||
|
'title' => __('Simple Light', 'mailpoet'),
|
||||||
|
'description' => __('A basic template with header and footer.', 'mailpoet'),
|
||||||
|
'slug' => 'simple-light',
|
||||||
|
'filename' => 'simple-light.html',
|
||||||
|
];
|
||||||
|
register_block_template(
|
||||||
|
$this->templatePrefix . '//' . $simpleLight['slug'],
|
||||||
|
[
|
||||||
|
'title' => $simpleLight['title'],
|
||||||
|
'description' => $simpleLight['description'],
|
||||||
|
'content' => (string)file_get_contents(__DIR__ . '/' . $simpleLight['filename']),
|
||||||
|
'post_types' => [EmailEditor::MAILPOET_EMAIL_POST_TYPE],
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@@ -33,12 +33,6 @@ class Templates {
|
|||||||
* @var string $template_directory
|
* @var string $template_directory
|
||||||
*/
|
*/
|
||||||
private string $template_directory = __DIR__ . DIRECTORY_SEPARATOR;
|
private string $template_directory = __DIR__ . DIRECTORY_SEPARATOR;
|
||||||
/**
|
|
||||||
* The templates.
|
|
||||||
*
|
|
||||||
* @var array $templates
|
|
||||||
*/
|
|
||||||
private array $templates = array();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes the class.
|
* Initializes the class.
|
||||||
@@ -69,27 +63,24 @@ class Templates {
|
|||||||
if ( ! function_exists( 'register_block_template' ) ) {
|
if ( ! function_exists( 'register_block_template' ) ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$this->templates['email-general'] = array(
|
// Register basic blank template.
|
||||||
|
$general_email = array(
|
||||||
'title' => __( 'General Email', 'mailpoet' ),
|
'title' => __( 'General Email', 'mailpoet' ),
|
||||||
'description' => __( 'A general template for emails.', 'mailpoet' ),
|
'description' => __( 'A general template for emails.', 'mailpoet' ),
|
||||||
|
'slug' => 'email-general',
|
||||||
);
|
);
|
||||||
$this->templates['simple-light'] = array(
|
$template_filename = $general_email['slug'] . '.html';
|
||||||
'title' => __( 'Simple Light', 'mailpoet' ),
|
|
||||||
'description' => __( 'A basic template with header and footer.', 'mailpoet' ),
|
|
||||||
);
|
|
||||||
|
|
||||||
foreach ( $this->templates as $template_slug => $template ) {
|
|
||||||
$template_filename = $template_slug . '.html';
|
|
||||||
register_block_template(
|
register_block_template(
|
||||||
$this->template_prefix . '//' . $template_slug,
|
$this->template_prefix . '//' . $general_email['slug'],
|
||||||
array(
|
array(
|
||||||
'title' => $template['title'],
|
'title' => $general_email['title'],
|
||||||
'description' => $template['description'],
|
'description' => $general_email['description'],
|
||||||
'content' => (string) file_get_contents( $this->template_directory . $template_filename ),
|
'content' => (string) file_get_contents( $this->template_directory . $template_filename ),
|
||||||
'post_types' => array( $this->post_type ),
|
'post_types' => array( $this->post_type ),
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
|
||||||
do_action( 'mailpoet_email_editor_register_templates' );
|
do_action( 'mailpoet_email_editor_register_templates' );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user