PluginProbe
Hello Plus / trunk
Hello Plus vtrunk
trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.2.1 1.3.0 1.4.0 1.4.1 1.5.0 1.5.1 1.5.2 1.5.3 1.6.0 1.6.1 1.6.2 1.7.0 1.7.1 1.7.2 1.7.3 All 30 releases
hello-plus / modules / content / classes / render / widget-cta-render.php

widget-cta-render.php in Hello Plus trunk, at modules/content/classes/render/widget-cta-render.php

186 lines 5.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace HelloPlus\Modules\Content\Classes\Render;
3
4 use HelloPlus\Classes\Widget_Utils;
5 use HelloPlus\Modules\Content\Widgets\CTA;
6 use HelloPlus\Classes\{
7 Ehp_Button,
8 Ehp_Column_Structure,
9 Ehp_Full_Height,
10 Ehp_Image,
11 Ehp_Shapes,
12 };
13
14 if ( ! defined( 'ABSPATH' ) ) {
15 exit; // Exit if accessed directly.
16 }
17
18 class Widget_CTA_Render {
19 protected CTA $widget;
20 const LAYOUT_CLASSNAME = 'ehp-cta';
21
22 protected array $settings;
23
24 public function __construct( CTA $widget ) {
25 $this->widget = $widget;
26 $this->settings = $widget->get_settings_for_display();
27 }
28
29 public function render(): void {
30 $layout_classnames = [
31 self::LAYOUT_CLASSNAME,
32 'has-preset-' . $this->settings['layout_preset'],
33 ];
34
35 $show_image = 'storytelling' === $this->settings['layout_preset'] || 'showcase' === $this->settings['layout_preset'];
36 $image_stretch = $this->settings['image_stretch'];
37 $has_border = $this->settings['show_box_border'];
38
39 if ( 'yes' === $image_stretch ) {
40 $layout_classnames[] = 'has-image-stretch';
41 }
42
43 if ( 'yes' === $has_border ) {
44 $layout_classnames[] = 'has-border';
45 }
46
47 $shapes = new Ehp_Shapes( $this->widget, [
48 'container_prefix' => 'box',
49 'render_attribute' => 'layout',
50 'widget_name' => $this->widget->get_name(),
51 ] );
52 $shapes->add_shape_attributes();
53
54 $ehp_full_height = new Ehp_Full_Height( $this->widget );
55 $ehp_full_height->add_full_height_attributes();
56
57 $this->widget->add_render_attribute( 'layout', [
58 'class' => $layout_classnames,
59 ] );
60
61 $elements_container_classnames = [
62 self::LAYOUT_CLASSNAME . '__elements-container',
63 ];
64 $image_position = $this->settings['image_horizontal_position'];
65 $image_position_tablet = $this->settings['image_horizontal_position_tablet'];
66 $image_position_mobile = $this->settings['image_horizontal_position_mobile'];
67
68 if ( ! empty( $image_position ) ) {
69 $elements_container_classnames[] = 'has-image-position-' . $image_position;
70
71 if ( ! empty( $image_position_tablet ) ) {
72 $elements_container_classnames[] = 'has-image-position-md-' . $image_position_tablet;
73 }
74
75 if ( ! empty( $image_position_mobile ) ) {
76 $elements_container_classnames[] = 'has-image-position-sm-' . $image_position_mobile;
77 }
78 }
79
80 $column_structure = new Ehp_Column_Structure( $this->widget, [
81 'render_attribute' => 'elements-container',
82 ] );
83 $column_structure->add_column_structure_attributes();
84
85 $this->widget->add_render_attribute( 'elements-container', [
86 'class' => $elements_container_classnames,
87 ] );
88
89 $this->widget->add_render_attribute( 'overlay', 'class', self::LAYOUT_CLASSNAME . '__overlay' );
90 ?>
91 <div <?php $this->widget->print_render_attribute_string( 'layout' ); ?>>
92 <div <?php $this->widget->print_render_attribute_string( 'overlay' ); ?>></div>
93 <div <?php $this->widget->print_render_attribute_string( 'elements-container' ); ?>>
94 <?php
95 if ( $show_image ) {
96 $this->render_image_container();
97 }
98 $this->render_text_container();
99
100 if ( 'showcase' !== $this->settings['layout_preset'] ) {
101 $this->render_ctas_container();
102 }
103 ?>
104 </div>
105 </div>
106 <?php
107 }
108
109 protected function render_image_container() {
110 $image = new Ehp_Image( $this->widget, [
111 'widget_name' => $this->widget->get_name(),
112 ] );
113 $image->render();
114 }
115
116 protected function render_text_container() {
117 $heading_classname = self::LAYOUT_CLASSNAME . '__heading';
118 $description_classname = self::LAYOUT_CLASSNAME . '__description';
119
120 $this->widget->add_render_attribute( 'text-container', [
121 'class' => self::LAYOUT_CLASSNAME . '__text-container',
122 ] );
123 ?>
124 <div <?php $this->widget->print_render_attribute_string( 'text-container' ); ?>>
125 <?php
126 Widget_Utils::maybe_render_text_html( $this->widget, 'heading_text', $heading_classname, $this->settings['heading_text'], $this->settings['heading_tag'] );
127 Widget_Utils::maybe_render_text_html( $this->widget, 'description_text', $description_classname, $this->settings['description_text'], $this->settings['description_tag'] );
128
129 if ( 'showcase' === $this->settings['layout_preset'] ) {
130 $this->render_ctas_container();
131 } ?>
132 </div>
133 <?php
134 }
135
136 protected function render_ctas_container() {
137 $buttons_width = $this->settings['cta_width'];
138 $buttons_width_tablet = $this->settings['cta_width_tablet'];
139 $buttons_width_mobile = $this->settings['cta_width_mobile'];
140
141 $buttons_wrapper_classnames = [ self::LAYOUT_CLASSNAME . '__buttons-wrapper' ];
142
143 $this->widget->add_render_attribute( 'buttons-wrapper', [
144 'class' => $buttons_wrapper_classnames,
145 ] );
146
147 $ctas_container_wrapper = [ self::LAYOUT_CLASSNAME . '__ctas-container' ];
148
149 if ( $buttons_width ) {
150 $ctas_container_wrapper[] = 'has-cta-width-' . $buttons_width;
151
152 if ( $buttons_width_tablet ) {
153 $ctas_container_wrapper[] = 'has-cta-width-md-' . $buttons_width_tablet;
154 }
155
156 if ( $buttons_width_mobile ) {
157 $ctas_container_wrapper[] = 'has-cta-width-sm-' . $buttons_width_mobile;
158 }
159 }
160
161 $this->widget->add_render_attribute( 'ctas-container', [
162 'class' => $ctas_container_wrapper,
163 ] );
164 ?>
165 <div <?php $this->widget->print_render_attribute_string( 'ctas-container' ); ?>>
166 <div <?php $this->widget->print_render_attribute_string( 'buttons-wrapper' ); ?>>
167 <?php if ( ! empty( $this->settings['primary_cta_button_text'] ) ) {
168 $this->render_button( 'primary' );
169 } ?>
170 <?php if ( ! empty( $this->settings['secondary_cta_button_text'] ) ) {
171 $this->render_button( 'secondary' );
172 } ?>
173 </div>
174 </div>
175 <?php
176 }
177
178 public function render_button( $type ) {
179 $button = new Ehp_Button( $this->widget, [
180 'type' => $type,
181 'widget_name' => $this->widget->get_name(),
182 ] );
183 $button->render();
184 }
185 }
186