11<?php
22namespace Automattic \WooCommerce \Blocks \BlockTypes ;
33
4+ use Automattic \WooCommerce \Blocks \Utils \AttributesUtils ;
5+
6+
47/**
58 * ProductCategories class.
69 */
710class ProductCategories extends AbstractDynamicBlock {
811
12+
913 /**
1014 * Block name.
1115 *
@@ -42,6 +46,11 @@ protected function get_block_type_attributes() {
4246 'hasEmpty ' => $ this ->get_schema_boolean ( false ),
4347 'isDropdown ' => $ this ->get_schema_boolean ( false ),
4448 'isHierarchical ' => $ this ->get_schema_boolean ( true ),
49+ 'textColor ' => $ this ->get_schema_string (),
50+ 'fontSize ' => $ this ->get_schema_string (),
51+ 'lineHeight ' => $ this ->get_schema_string (),
52+ 'style ' => array ( 'type ' => 'object ' ),
53+
4554 )
4655 );
4756 }
@@ -77,9 +86,11 @@ protected function render( $attributes, $content ) {
7786 }
7887 }
7988
80- $ classes = $ this ->get_container_classes ( $ attributes );
89+ $ classes_and_styles = $ this ->get_container_classes ( $ attributes );
90+ $ classes = $ classes_and_styles [0 ];
91+ $ styles = $ classes_and_styles [1 ];
8192
82- $ output = '<div class=" ' . esc_attr ( $ classes ) . '"> ' ;
93+ $ output = '<div class=" ' . esc_attr ( $ classes ) . '" style=" ' . $ styles . ' " > ' ;
8394 $ output .= ! empty ( $ attributes ['isDropdown ' ] ) ? $ this ->renderDropdown ( $ categories , $ attributes , $ uid ) : $ this ->renderList ( $ categories , $ attributes , $ uid );
8495 $ output .= '</div> ' ;
8596
@@ -93,6 +104,7 @@ protected function render( $attributes, $content ) {
93104 * @return string space-separated list of classes.
94105 */
95106 protected function get_container_classes ( $ attributes = array () ) {
107+
96108 $ classes = array ( 'wc-block-product-categories ' );
97109
98110 if ( isset ( $ attributes ['align ' ] ) ) {
@@ -109,9 +121,31 @@ protected function get_container_classes( $attributes = array() ) {
109121 $ classes [] = 'is-list ' ;
110122 }
111123
112- return implode ( ' ' , $ classes );
124+ $ line_height_class_and_style = AttributesUtils::get_line_height_class_and_style ( $ attributes );
125+ $ text_color_class_and_style = AttributesUtils::get_text_color_class_and_style ( $ attributes );
126+ $ font_size_class_and_style = AttributesUtils::get_font_size_class_and_style ( $ attributes );
127+
128+ $ classes = array_filter (
129+ [ $ line_height_class_and_style ['class ' ], $ text_color_class_and_style ['class ' ], $ font_size_class_and_style ['class ' ] ],
130+ function ( $ var ) {
131+ return ! is_null ( $ var );
132+ }
133+ );
134+ $ styles = array_filter (
135+ [ $ line_height_class_and_style ['style ' ], $ text_color_class_and_style ['style ' ], $ font_size_class_and_style ['style ' ] ],
136+ function ( $ var ) {
137+ return ! is_null ( $ var );
138+ }
139+ );
140+
141+ $ string_classes = implode ( ' ' , $ classes );
142+ $ string_styles = implode ( ' ' , $ styles );
143+
144+ return array ( $ string_classes , $ string_styles );
113145 }
114146
147+
148+
115149 /**
116150 * Get categories (terms) from the db.
117151 *
@@ -301,10 +335,12 @@ protected function renderList( $categories, $attributes, $uid, $depth = 0 ) {
301335 protected function renderListItems ( $ categories , $ attributes , $ uid , $ depth = 0 ) {
302336 $ output = '' ;
303337
338+ $ link_color_class_and_style = AttributesUtils::get_link_color_class_and_style ( $ attributes );
339+
304340 foreach ( $ categories as $ category ) {
305341 $ output .= '
306342 <li class="wc-block-product-categories-list-item">
307- <a href=" ' . esc_attr ( get_term_link ( $ category ->term_id , 'product_cat ' ) ) . '"> ' . $ this ->get_image_html ( $ category , $ attributes ) . esc_html ( $ category ->name ) . '</a>
343+ <a style=" ' . $ link_color_class_and_style [ ' style ' ] . ' " class=" ' . $ link_color_class_and_style [ ' class ' ] . ' " href=" ' . esc_attr ( get_term_link ( $ category ->term_id , 'product_cat ' ) ) . '"> ' . $ this ->get_image_html ( $ category , $ attributes ) . esc_html ( $ category ->name ) . '</a>
308344 ' . $ this ->getCount ( $ category , $ attributes ) . '
309345 ' . ( ! empty ( $ category ->children ) ? $ this ->renderList ( $ category ->children , $ attributes , $ uid , $ depth + 1 ) : '' ) . '
310346 </li>
0 commit comments