Accordion
1 year ago
AddToCartWithOptions
1 week ago
OrderConfirmation
2 months ago
ProductCollection
3 weeks ago
Reviews
2 months ago
AbstractBlock.php
4 weeks ago
AbstractDynamicBlock.php
2 years ago
AbstractInnerBlock.php
1 year ago
AbstractProductGrid.php
3 months ago
ActiveFilters.php
2 years ago
AddToCartForm.php
4 weeks ago
AddToWishlistButton.php
4 weeks ago
AllProducts.php
2 years ago
AllReviews.php
2 years ago
AtomicBlock.php
2 years ago
AttributeFilter.php
1 year ago
Breadcrumbs.php
1 year ago
Cart.php
2 months ago
CartAcceptedPaymentMethodsBlock.php
2 years ago
CartCrossSellsBlock.php
2 years ago
CartCrossSellsProductsBlock.php
2 years ago
CartExpressPaymentBlock.php
1 year ago
CartItemsBlock.php
2 years ago
CartLineItemsBlock.php
2 years ago
CartLink.php
2 months ago
CartOrderSummaryBlock.php
2 years ago
CartOrderSummaryCouponFormBlock.php
2 years ago
CartOrderSummaryDiscountBlock.php
2 years ago
CartOrderSummaryFeeBlock.php
2 years ago
CartOrderSummaryHeadingBlock.php
2 years ago
CartOrderSummaryShippingBlock.php
2 years ago
CartOrderSummarySubtotalBlock.php
2 years ago
CartOrderSummaryTaxesBlock.php
2 years ago
CartOrderSummaryTotalsBlock.php
2 years ago
CartTotalsBlock.php
2 years ago
CatalogSorting.php
4 weeks ago
CategoryDescription.php
2 months ago
CategoryTitle.php
2 months ago
Checkout.php
2 months ago
CheckoutActionsBlock.php
1 year ago
CheckoutAdditionalInformationBlock.php
2 years ago
CheckoutBillingAddressBlock.php
2 years ago
CheckoutContactInformationBlock.php
2 years ago
CheckoutExpressPaymentBlock.php
9 months ago
CheckoutFieldsBlock.php
2 years ago
CheckoutOrderNoteBlock.php
2 years ago
CheckoutOrderSummaryBlock.php
2 years ago
CheckoutOrderSummaryCartItemsBlock.php
2 years ago
CheckoutOrderSummaryCouponFormBlock.php
2 years ago
CheckoutOrderSummaryDiscountBlock.php
2 years ago
CheckoutOrderSummaryFeeBlock.php
2 years ago
CheckoutOrderSummaryShippingBlock.php
2 years ago
CheckoutOrderSummarySubtotalBlock.php
2 years ago
CheckoutOrderSummaryTaxesBlock.php
2 years ago
CheckoutOrderSummaryTotalsBlock.php
2 years ago
CheckoutPaymentBlock.php
2 years ago
CheckoutPickupOptionsBlock.php
2 years ago
CheckoutShippingAddressBlock.php
2 years ago
CheckoutShippingMethodBlock.php
2 years ago
CheckoutShippingMethodsBlock.php
2 years ago
CheckoutTermsBlock.php
2 years ago
CheckoutTotalsBlock.php
2 years ago
ClassicShortcode.php
1 year ago
ClassicTemplate.php
4 months ago
ComingSoon.php
1 year ago
CouponCode.php
2 months ago
CustomerAccount.php
3 months ago
Dropdown.php
4 weeks ago
EmailContent.php
5 months ago
EmptyCartBlock.php
2 years ago
EmptyMiniCartContentsBlock.php
11 months ago
EnableBlockJsonAssetsTrait.php
1 year ago
FeaturedCategory.php
7 months ago
FeaturedItem.php
7 months ago
FeaturedProduct.php
7 months ago
FilledCartBlock.php
2 years ago
FilledMiniCartContentsBlock.php
4 months ago
FilterWrapper.php
2 years ago
HandpickedProducts.php
1 year ago
MiniCart.php
4 weeks ago
MiniCartCartButtonBlock.php
11 months ago
MiniCartCheckoutButtonBlock.php
11 months ago
MiniCartContents.php
3 months ago
MiniCartFooterBlock.php
4 weeks ago
MiniCartItemsBlock.php
11 months ago
MiniCartProductsTableBlock.php
4 weeks ago
MiniCartShoppingButtonBlock.php
9 months ago
MiniCartTitleBlock.php
11 months ago
MiniCartTitleItemsCounterBlock.php
11 months ago
MiniCartTitleLabelBlock.php
11 months ago
NextPreviousButtons.php
5 months ago
PageContentWrapper.php
2 years ago
PaymentMethodIcons.php
11 months ago
PriceFilter.php
1 year ago
ProceedToCheckoutBlock.php
2 years ago
ProductAverageRating.php
1 year ago
ProductBestSellers.php
2 years ago
ProductButton.php
2 months ago
ProductCategories.php
4 weeks ago
ProductCategory.php
2 years ago
ProductDescription.php
9 months ago
ProductDetails.php
5 months ago
ProductFilterActive.php
4 weeks ago
ProductFilterAttribute.php
4 weeks ago
ProductFilterCheckboxList.php
4 weeks ago
ProductFilterChips.php
4 weeks ago
ProductFilterClearButton.php
4 weeks ago
ProductFilterPrice.php
4 weeks ago
ProductFilterPriceSlider.php
4 weeks ago
ProductFilterRating.php
4 weeks ago
ProductFilterRemovableChips.php
4 weeks ago
ProductFilterStatus.php
4 weeks ago
ProductFilterTaxonomy.php
4 weeks ago
ProductFilters.php
3 weeks ago
ProductGallery.php
4 weeks ago
ProductGalleryLargeImage.php
4 weeks ago
ProductGalleryThumbnails.php
4 weeks ago
ProductImage.php
4 weeks ago
ProductImageGallery.php
7 months ago
ProductMeta.php
1 year ago
ProductNew.php
2 years ago
ProductOnSale.php
2 years ago
ProductPrice.php
2 months ago
ProductQuery.php
4 weeks ago
ProductRating.php
1 year ago
ProductRatingCounter.php
1 year ago
ProductRatingStars.php
1 year ago
ProductResultsCount.php
2 months ago
ProductSKU.php
2 months ago
ProductSaleBadge.php
1 year ago
ProductSearch.php
10 months ago
ProductSpecifications.php
2 months ago
ProductStockIndicator.php
2 months ago
ProductSummary.php
7 months ago
ProductTag.php
2 years ago
ProductTemplate.php
2 months ago
ProductTitle.php
1 year ago
ProductTopRated.php
2 years ago
ProductsByAttribute.php
2 years ago
RatingFilter.php
2 years ago
RelatedProducts.php
3 months ago
ReviewsByCategory.php
2 years ago
ReviewsByProduct.php
2 years ago
SavedForLater.php
4 weeks ago
SingleProduct.php
2 months ago
StockFilter.php
2 years ago
StoreNotices.php
1 year ago
Wishlist.php
4 weeks ago
EmailContent.php
103 lines
| 1 | <?php // phpcs:ignore Generic.PHP.RequireStrictTypes.MissingDeclaration |
| 2 | |
| 3 | namespace Automattic\WooCommerce\Blocks\BlockTypes; |
| 4 | |
| 5 | use Automattic\WooCommerce\Blocks\BlockTypes\AbstractBlock; |
| 6 | use Automattic\WooCommerce\Internal\EmailEditor\BlockEmailRenderer; |
| 7 | use Automattic\WooCommerce\Internal\Admin\EmailPreview\EmailPreview; |
| 8 | use Automattic\WooCommerce\Internal\EmailEditor\WCTransactionalEmails\WCTransactionalEmailPostsManager; |
| 9 | |
| 10 | /** |
| 11 | * EmailContent class. |
| 12 | */ |
| 13 | class EmailContent extends AbstractBlock { |
| 14 | /** |
| 15 | * Block name. |
| 16 | * |
| 17 | * @var string |
| 18 | */ |
| 19 | protected $block_name = 'email-content'; |
| 20 | |
| 21 | /** |
| 22 | * Get the frontend style handle for this block type. |
| 23 | * |
| 24 | * @return null |
| 25 | */ |
| 26 | protected function get_block_type_style() { |
| 27 | return null; |
| 28 | } |
| 29 | |
| 30 | /** |
| 31 | * Get the editor script handle for this block type. |
| 32 | * |
| 33 | * @param string $key Data to get, or default to everything. |
| 34 | * @return array|string |
| 35 | */ |
| 36 | protected function get_block_type_editor_script( $key = null ) { |
| 37 | $script = [ |
| 38 | 'handle' => 'wc-' . $this->block_name . '-block', |
| 39 | 'path' => $this->asset_api->get_block_asset_build_path( $this->block_name ), |
| 40 | 'dependencies' => [ 'wc-blocks' ], |
| 41 | ]; |
| 42 | return $key ? $script[ $key ] : $script; |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * Get the frontend script handle for this block type. |
| 47 | * |
| 48 | * @param string $key Data to get, or default to everything. |
| 49 | */ |
| 50 | protected function get_block_type_script( $key = null ) { |
| 51 | return null; |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * Renders the block preview for the editor. |
| 56 | * |
| 57 | * @param array $attributes Block attributes. |
| 58 | * @return string Rendered block output. |
| 59 | */ |
| 60 | protected function render_preview( $attributes ) { |
| 61 | /** |
| 62 | * Email preview instance for rendering dummy content. |
| 63 | * |
| 64 | * @var EmailPreview $email_preview - email preview instance |
| 65 | */ |
| 66 | $email_preview = wc_get_container()->get( EmailPreview::class ); |
| 67 | |
| 68 | $type_param = EmailPreview::DEFAULT_EMAIL_TYPE; |
| 69 | |
| 70 | if ( isset( $attributes['postId'] ) ) { |
| 71 | $email_type_class_name = WCTransactionalEmailPostsManager::get_instance()->get_email_type_class_name_from_post_id( $attributes['postId'] ); |
| 72 | $type_param = ! empty( $email_type_class_name ) ? $email_type_class_name : $type_param; |
| 73 | } elseif ( isset( $attributes['emailType'] ) ) { |
| 74 | $type_param = sanitize_text_field( wp_unslash( $attributes['emailType'] ) ); |
| 75 | } |
| 76 | |
| 77 | try { |
| 78 | return $email_preview->generate_placeholder_content( $type_param ); |
| 79 | } catch ( \Exception $e ) { |
| 80 | // Catch other potential errors during content generation. |
| 81 | return esc_html__( 'There was an error rendering the email preview.', 'woocommerce' ); |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | /** |
| 86 | * Renders Woo content placeholder to be replaced by content during sending. |
| 87 | * |
| 88 | * @param array $attributes Block attributes. |
| 89 | * @param string $content Block content. |
| 90 | * @param \WP_Block $block Block instance. |
| 91 | * @return string Rendered block output. |
| 92 | */ |
| 93 | protected function render( $attributes, $content, $block ) { |
| 94 | // phpcs:disable WordPress.Security.NonceVerification.Recommended |
| 95 | if ( defined( 'REST_REQUEST' ) && REST_REQUEST && isset( $_GET['context'] ) && 'edit' === sanitize_text_field( wp_unslash( $_GET['context'] ) ) ) { |
| 96 | // Block is being rendered for ServerSideRender editor preview. |
| 97 | return $this->render_preview( $attributes ); |
| 98 | } |
| 99 | |
| 100 | return BlockEmailRenderer::WOO_EMAIL_CONTENT_PLACEHOLDER; |
| 101 | } |
| 102 | } |
| 103 |