Move the template_id construction logic to Templates class
[MAILPOET-6356]
This commit is contained in:
committed by
Rostislav Wolný
parent
a5db2564c8
commit
9b9187bb3e
@ -72,9 +72,9 @@ class Renderer {
|
||||
* @return array
|
||||
*/
|
||||
public function render( \WP_Post $post, string $subject, string $pre_header, string $language, $meta_robots = '' ): array { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed
|
||||
$template_id = get_stylesheet() . '//' . ( get_page_template_slug( $post ) ? get_page_template_slug( $post ) : 'email-general' );
|
||||
$template_slug = get_page_template_slug( $post ) ? get_page_template_slug( $post ) : 'email-general';
|
||||
/** @var \WP_Block_Template $template */ // phpcs:ignore Generic.Commenting.DocComment.MissingShort -- used for phpstan
|
||||
$template = $this->templates->get_block_template( $template_id );
|
||||
$template = $this->templates->get_block_template( $template_slug );
|
||||
|
||||
$email_styles = $this->theme_controller->get_styles();
|
||||
$template_html = $this->content_renderer->render( $post, $template );
|
||||
|
@ -51,10 +51,12 @@ class Templates {
|
||||
/**
|
||||
* Get a block template by ID.
|
||||
*
|
||||
* @param string $template_id The template ID.
|
||||
* @param string $template_slug The template slug.
|
||||
* @return WP_Block_Template|null
|
||||
*/
|
||||
public function get_block_template( $template_id ) {
|
||||
public function get_block_template( $template_slug ) {
|
||||
// Template id is always prefixed by active theme and get_stylesheet returns the active theme slug.
|
||||
$template_id = get_stylesheet() . '//' . $template_slug;
|
||||
return get_block_template( $template_id );
|
||||
}
|
||||
|
||||
|
@ -35,12 +35,11 @@ class Templates_Test extends \MailPoetTest {
|
||||
* @return void
|
||||
*/
|
||||
public function testItCanFetchBlockTemplate(): void {
|
||||
$template_id = get_stylesheet() . '//email-general'; // Templates id is prefixed with the theme name.
|
||||
$template = $this->templates->get_block_template( $template_id );
|
||||
$template = $this->templates->get_block_template( 'email-general' );
|
||||
|
||||
self::assertInstanceOf( \WP_Block_Template::class, $template );
|
||||
verify( $template->slug )->equals( 'email-general' );
|
||||
verify( $template->id )->equals( $template_id );
|
||||
verify( $template->id )->stringContainsString( 'email-general' );
|
||||
verify( $template->title )->equals( 'General Email' );
|
||||
verify( $template->description )->equals( 'A general template for emails.' );
|
||||
}
|
||||
|
Reference in New Issue
Block a user