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
Breadcrumbs.php
96 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Automattic\WooCommerce\Blocks\BlockTypes; |
| 4 | |
| 5 | use Automattic\WooCommerce\Blocks\Utils\StyleAttributesUtils; |
| 6 | |
| 7 | /** |
| 8 | * Breadcrumbs class. |
| 9 | */ |
| 10 | class Breadcrumbs extends AbstractBlock { |
| 11 | |
| 12 | /** |
| 13 | * Block name. |
| 14 | * |
| 15 | * @var string |
| 16 | */ |
| 17 | protected $block_name = 'breadcrumbs'; |
| 18 | |
| 19 | /** |
| 20 | * Render the block. |
| 21 | * |
| 22 | * @param array $attributes Block attributes. |
| 23 | * @param string $content Block content. |
| 24 | * @param WP_Block $block Block instance. |
| 25 | * |
| 26 | * @return string | void Rendered block output. |
| 27 | */ |
| 28 | protected function render( $attributes, $content, $block ) { |
| 29 | ob_start(); |
| 30 | woocommerce_breadcrumb(); |
| 31 | $breadcrumb = ob_get_clean(); |
| 32 | |
| 33 | if ( ! $breadcrumb ) { |
| 34 | return; |
| 35 | } |
| 36 | |
| 37 | $classes_and_styles = StyleAttributesUtils::get_classes_and_styles_by_attributes( $attributes, array(), array( 'font_size' ) ); |
| 38 | |
| 39 | $font_size_classes_and_styles = $this->get_font_size_classes_and_styles( $attributes ); |
| 40 | $classes_and_styles['classes'] = $classes_and_styles['classes'] . ' ' . $font_size_classes_and_styles['class'] . ' '; |
| 41 | $classes_and_styles['styles'] = $classes_and_styles['styles'] . ' ' . $font_size_classes_and_styles['style'] . ' '; |
| 42 | |
| 43 | return sprintf( |
| 44 | '<div class="woocommerce wp-block-breadcrumbs wc-block-breadcrumbs %1$s" style="%2$s">%3$s</div>', |
| 45 | esc_attr( $classes_and_styles['classes'] ), |
| 46 | esc_attr( $classes_and_styles['styles'] ), |
| 47 | $breadcrumb |
| 48 | ); |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * Get the frontend script handle for this block type. |
| 53 | * |
| 54 | * @param string $key Data to get, or default to everything. |
| 55 | */ |
| 56 | protected function get_block_type_script( $key = null ) { |
| 57 | return null; |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * Gets font size classes and styles for the breadcrumbs block. |
| 62 | * |
| 63 | * Note: This implementation intentionally avoids using StyleAttributesUtils::get_font_size_class_and_style() |
| 64 | * and get_block_wrapper_attributes() to ensure style attributes take precedence over the class attribute fontSize. |
| 65 | * This is needed because the block.json defines a default fontSize, which is considered an anti-pattern |
| 66 | * since styles should be defined by themes and plugins instead. |
| 67 | * |
| 68 | * @param array $attributes The block attributes. |
| 69 | * @return array The font size classes and styles. |
| 70 | */ |
| 71 | private function get_font_size_classes_and_styles( $attributes ) { |
| 72 | $font_size = $attributes['fontSize'] ?? ''; |
| 73 | |
| 74 | $custom_font_size = $attributes['style']['typography']['fontSize'] ?? ''; |
| 75 | |
| 76 | if ( ! $font_size && '' === $custom_font_size ) { |
| 77 | return array( |
| 78 | 'class' => null, |
| 79 | 'style' => null, |
| 80 | ); |
| 81 | } |
| 82 | |
| 83 | if ( '' !== $custom_font_size ) { |
| 84 | return array( |
| 85 | 'class' => null, |
| 86 | 'style' => sprintf( 'font-size: %s;', $custom_font_size ), |
| 87 | ); |
| 88 | } |
| 89 | |
| 90 | return array( |
| 91 | 'class' => sprintf( 'has-font-size has-%s-font-size', $font_size ), |
| 92 | 'style' => null, |
| 93 | ); |
| 94 | } |
| 95 | } |
| 96 |