diff --git a/mailpoet/lib/DI/ContainerConfigurator.php b/mailpoet/lib/DI/ContainerConfigurator.php index 1879fd65ca..d0cb0998df 100644 --- a/mailpoet/lib/DI/ContainerConfigurator.php +++ b/mailpoet/lib/DI/ContainerConfigurator.php @@ -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\Subscriber::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 $container->autowire(\MailPoet\Features\FeaturesController::class)->setPublic(true); $container->autowire(\MailPoet\Features\FeatureFlagsController::class)->setPublic(true); diff --git a/mailpoet/lib/EmailEditor/Integrations/MailPoet/EmailEditor.php b/mailpoet/lib/EmailEditor/Integrations/MailPoet/EmailEditor.php index be0c696ffd..ae97fffc5e 100644 --- a/mailpoet/lib/EmailEditor/Integrations/MailPoet/EmailEditor.php +++ b/mailpoet/lib/EmailEditor/Integrations/MailPoet/EmailEditor.php @@ -3,6 +3,7 @@ namespace MailPoet\EmailEditor\Integrations\MailPoet; use MailPoet\EmailEditor\Integrations\MailPoet\Patterns\PatternsController; +use MailPoet\EmailEditor\Integrations\MailPoet\Templates\TemplatesController; use MailPoet\Features\FeaturesController; use MailPoet\WP\Functions as WPFunctions; @@ -25,6 +26,8 @@ class EmailEditor { private PersonalizationTagManager $personalizationTagManager; + private TemplatesController $templatesController; + public function __construct( WPFunctions $wp, FeaturesController $featuresController, @@ -32,6 +35,7 @@ class EmailEditor { EditorPageRenderer $editorPageRenderer, EmailEditorPreviewEmail $emailEditorPreviewEmail, PatternsController $patternsController, + TemplatesController $templatesController, Cli $cli, PersonalizationTagManager $personalizationTagManager ) { @@ -40,6 +44,7 @@ class EmailEditor { $this->emailApiController = $emailApiController; $this->editorPageRenderer = $editorPageRenderer; $this->patternsController = $patternsController; + $this->templatesController = $templatesController; $this->cli = $cli; $this->emailEditorPreviewEmail = $emailEditorPreviewEmail; $this->personalizationTagManager = $personalizationTagManager; @@ -56,6 +61,7 @@ class EmailEditor { $this->wp->addFilter('replace_editor', [$this, 'replaceEditor'], 10, 2); $this->wp->addFilter('mailpoet_email_editor_send_preview_email', [$this->emailEditorPreviewEmail, 'sendPreviewEmail'], 10, 1); $this->patternsController->registerPatterns(); + $this->templatesController->initialize(); $this->extendEmailPostApi(); $this->personalizationTagManager->initialize(); } diff --git a/mailpoet/lib/EmailEditor/Integrations/MailPoet/Templates/TemplatesController.php b/mailpoet/lib/EmailEditor/Integrations/MailPoet/Templates/TemplatesController.php new file mode 100644 index 0000000000..0d3da4f5e5 --- /dev/null +++ b/mailpoet/lib/EmailEditor/Integrations/MailPoet/Templates/TemplatesController.php @@ -0,0 +1,39 @@ +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], + ] + ); + } +} diff --git a/packages/php/email-editor/src/Engine/Templates/simple-light.html b/mailpoet/lib/EmailEditor/Integrations/MailPoet/Templates/simple-light.html similarity index 100% rename from packages/php/email-editor/src/Engine/Templates/simple-light.html rename to mailpoet/lib/EmailEditor/Integrations/MailPoet/Templates/simple-light.html diff --git a/packages/php/email-editor/src/Engine/Templates/class-templates.php b/packages/php/email-editor/src/Engine/Templates/class-templates.php index 9411ff3c0a..eb5af54d3a 100644 --- a/packages/php/email-editor/src/Engine/Templates/class-templates.php +++ b/packages/php/email-editor/src/Engine/Templates/class-templates.php @@ -33,12 +33,6 @@ class Templates { * @var string $template_directory */ private string $template_directory = __DIR__ . DIRECTORY_SEPARATOR; - /** - * The templates. - * - * @var array $templates - */ - private array $templates = array(); /** * Initializes the class. @@ -69,27 +63,24 @@ class Templates { if ( ! function_exists( 'register_block_template' ) ) { return; } - $this->templates['email-general'] = array( + // Register basic blank template. + $general_email = array( 'title' => __( 'General Email', 'mailpoet' ), 'description' => __( 'A general template for emails.', 'mailpoet' ), + 'slug' => 'email-general', ); - $this->templates['simple-light'] = array( - 'title' => __( 'Simple Light', 'mailpoet' ), - 'description' => __( 'A basic template with header and footer.', 'mailpoet' ), + $template_filename = $general_email['slug'] . '.html'; + + register_block_template( + $this->template_prefix . '//' . $general_email['slug'], + array( + 'title' => $general_email['title'], + 'description' => $general_email['description'], + 'content' => (string) file_get_contents( $this->template_directory . $template_filename ), + 'post_types' => array( $this->post_type ), + ) ); - foreach ( $this->templates as $template_slug => $template ) { - $template_filename = $template_slug . '.html'; - register_block_template( - $this->template_prefix . '//' . $template_slug, - array( - 'title' => $template['title'], - 'description' => $template['description'], - 'content' => (string) file_get_contents( $this->template_directory . $template_filename ), - 'post_types' => array( $this->post_type ), - ) - ); - } do_action( 'mailpoet_email_editor_register_templates' ); }