From a31857ffeec51abe15b62d1c99dcdcc53c2b0f0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Lys=C3=BD?= Date: Thu, 17 Oct 2024 12:12:59 +0200 Subject: [PATCH] Migrate email editor template-preview class to WP Coding Standard [MAILPOET-6240] --- .../Templates/class-template-preview.php | 80 ++++++++++++++----- 1 file changed, 58 insertions(+), 22 deletions(-) diff --git a/packages/php/email-editor/src/Engine/Templates/class-template-preview.php b/packages/php/email-editor/src/Engine/Templates/class-template-preview.php index 3da900172d..1f253b597f 100644 --- a/packages/php/email-editor/src/Engine/Templates/class-template-preview.php +++ b/packages/php/email-editor/src/Engine/Templates/class-template-preview.php @@ -1,5 +1,11 @@ -themeController = $themeController; - $this->settingsController = $settingsController; - $this->templates = $templates; + $this->theme_controller = $theme_controller; + $this->settings_controller = $settings_controller; + $this->templates = $templates; } + /** + * Initializes the class. + */ public function initialize(): void { register_rest_field( 'wp_template', 'email_theme_css', array( - 'get_callback' => array( $this, 'getEmailThemePreviewCss' ), + 'get_callback' => array( $this, 'get_email_theme_preview_css' ), 'update_callback' => null, 'schema' => Builder::string()->toArray(), ) @@ -37,21 +71,23 @@ class Template_Preview { /** * Generates CSS for preview of email theme * They are applied in the preview BLockPreview in template selection + * + * @param array $template Template data. */ - public function getEmailThemePreviewCss( $template ): string { - $editorTheme = clone $this->themeController->get_theme(); - $templateTheme = $this->templates->getBlockTemplateTheme( $template['id'], $template['wp_id'] ); - if ( is_array( $templateTheme ) ) { - $editorTheme->merge( new WP_Theme_JSON( $templateTheme, 'custom' ) ); + public function get_email_theme_preview_css( $template ): string { + $editor_theme = clone $this->theme_controller->get_theme(); + $template_theme = $this->templates->getBlockTemplateTheme( $template['id'], $template['wp_id'] ); + if ( is_array( $template_theme ) ) { + $editor_theme->merge( new WP_Theme_JSON( $template_theme, 'custom' ) ); } - $editorSettings = $this->settingsController->get_settings(); - $additionalCSS = ''; - foreach ( $editorSettings['styles'] as $style ) { - $additionalCSS .= $style['css']; + $editor_settings = $this->settings_controller->get_settings(); + $additional_css = ''; + foreach ( $editor_settings['styles'] as $style ) { + $additional_css .= $style['css']; } - // Set proper content width for previews - $layoutSettings = $this->themeController->get_layout_settings(); - $additionalCSS .= ".is-root-container { width: {$layoutSettings['contentSize']}; margin: 0 auto; }"; - return $editorTheme->get_stylesheet() . $additionalCSS; + // Set proper content width for previews. + $layout_settings = $this->theme_controller->get_layout_settings(); + $additional_css .= ".is-root-container { width: {$layout_settings['contentSize']}; margin: 0 auto; }"; + return $editor_theme->get_stylesheet() . $additional_css; } }