| 1 |
<?php |
| 2 |
namespace HelloPlus\Modules\Content\Classes\Render; |
| 3 |
|
| 4 |
if ( ! defined( 'ABSPATH' ) ) { |
| 5 |
exit; // Exit if accessed directly. |
| 6 |
} |
| 7 |
|
| 8 |
use HelloPlus\Classes\Widget_Utils; |
| 9 |
use HelloPlus\Modules\Content\Widgets\Flex_Hero; |
| 10 |
use HelloPlus\Classes\{ |
| 11 |
Ehp_Button, |
| 12 |
Ehp_Column_Structure, |
| 13 |
Ehp_Full_Height, |
| 14 |
Ehp_Image, |
| 15 |
Ehp_Shapes, |
| 16 |
}; |
| 17 |
|
| 18 |
class Widget_Flex_Hero_Render { |
| 19 |
protected Flex_Hero $widget; |
| 20 |
const LAYOUT_CLASSNAME = 'ehp-flex-hero'; |
| 21 |
|
| 22 |
protected array $settings; |
| 23 |
|
| 24 |
public function __construct( Flex_Hero $widget ) { |
| 25 |
$this->widget = $widget; |
| 26 |
$this->settings = $widget->get_settings_for_display(); |
| 27 |
} |
| 28 |
|
| 29 |
public function maybe_add_layout_responsive_classes( &$layout_classes ) { |
| 30 |
$layout_image_position_mobile = $this->settings['layout_image_position_mobile']; |
| 31 |
$layout_image_position_tablet = $this->settings['layout_image_position_tablet']; |
| 32 |
|
| 33 |
if ( ! empty( $layout_image_position_mobile ) ) { |
| 34 |
$layout_classes[] = 'has-image-position-sm-' . $layout_image_position_mobile; |
| 35 |
} |
| 36 |
|
| 37 |
if ( ! empty( $layout_image_position_tablet ) ) { |
| 38 |
$layout_classes[] = 'has-image-position-md-' . $layout_image_position_tablet; |
| 39 |
} |
| 40 |
} |
| 41 |
|
| 42 |
public function render(): void { |
| 43 |
$layout_classnames = [ self::LAYOUT_CLASSNAME ]; |
| 44 |
$layout_preset = $this->settings['layout_preset']; |
| 45 |
$image_stretch = $this->settings['image_stretch']; |
| 46 |
$layout_image_position = $this->settings['layout_image_position']; |
| 47 |
$has_border = $this->settings['show_box_border']; |
| 48 |
|
| 49 |
if ( ! empty( $layout_preset ) ) { |
| 50 |
$layout_classnames[] = 'has-layout-preset-' . $layout_preset; |
| 51 |
} |
| 52 |
|
| 53 |
if ( 'yes' === $image_stretch ) { |
| 54 |
$layout_classnames[] = 'has-image-stretch'; |
| 55 |
} |
| 56 |
|
| 57 |
if ( 'yes' === $has_border ) { |
| 58 |
$layout_classnames[] = 'has-border'; |
| 59 |
} |
| 60 |
|
| 61 |
if ( ! empty( $layout_image_position ) ) { |
| 62 |
$layout_classnames[] = 'has-image-position-' . $layout_image_position; |
| 63 |
|
| 64 |
// pass by reference: |
| 65 |
$this->maybe_add_layout_responsive_classes( $layout_classnames ); |
| 66 |
} |
| 67 |
|
| 68 |
$shapes = new Ehp_Shapes( $this->widget, [ |
| 69 |
'container_prefix' => 'box', |
| 70 |
'render_attribute' => 'layout', |
| 71 |
'widget_name' => $this->widget->get_name(), |
| 72 |
] ); |
| 73 |
$shapes->add_shape_attributes(); |
| 74 |
|
| 75 |
$ehp_full_height = new Ehp_Full_Height( $this->widget ); |
| 76 |
$ehp_full_height->add_full_height_attributes(); |
| 77 |
|
| 78 |
$column_structure = new Ehp_Column_Structure( $this->widget, [ |
| 79 |
'render_attribute' => 'layout', |
| 80 |
] ); |
| 81 |
$column_structure->add_column_structure_attributes(); |
| 82 |
|
| 83 |
$this->widget->add_render_attribute( 'layout', [ |
| 84 |
'class' => $layout_classnames, |
| 85 |
] ); |
| 86 |
?> |
| 87 |
<div <?php $this->widget->print_render_attribute_string( 'layout' ); ?>> |
| 88 |
<?php |
| 89 |
$this->render_content_container(); |
| 90 |
$this->render_image_container(); |
| 91 |
?> |
| 92 |
</div> |
| 93 |
<?php |
| 94 |
} |
| 95 |
|
| 96 |
public function render_content_container() { |
| 97 |
$this->widget->add_render_attribute( 'content-container', 'class', self::LAYOUT_CLASSNAME . '__content-container' ); |
| 98 |
$this->widget->add_render_attribute( 'overlay', 'class', self::LAYOUT_CLASSNAME . '__overlay' ); |
| 99 |
?> |
| 100 |
<div <?php $this->widget->print_render_attribute_string( 'overlay' ); ?>></div> |
| 101 |
<div <?php $this->widget->print_render_attribute_string( 'content-container' ); ?>> |
| 102 |
<?php |
| 103 |
$this->render_text_container(); |
| 104 |
$this->render_ctas_container(); |
| 105 |
?> |
| 106 |
</div> |
| 107 |
<?php |
| 108 |
} |
| 109 |
|
| 110 |
public function render_text_container() { |
| 111 |
$intro_classname = self::LAYOUT_CLASSNAME . '__intro'; |
| 112 |
$heading_classname = self::LAYOUT_CLASSNAME . '__heading'; |
| 113 |
$subheading_classname = self::LAYOUT_CLASSNAME . '__subheading'; |
| 114 |
|
| 115 |
Widget_Utils::maybe_render_text_html( $this->widget, 'intro_text', $intro_classname, $this->settings['intro_text'], $this->settings['intro_tag'] ); |
| 116 |
Widget_Utils::maybe_render_text_html( $this->widget, 'heading_text', $heading_classname, $this->settings['heading_text'], $this->settings['heading_tag'] ); |
| 117 |
Widget_Utils::maybe_render_text_html( $this->widget, 'subheading_text', $subheading_classname, $this->settings['subheading_text'], $this->settings['subheading_tag'] ); |
| 118 |
} |
| 119 |
|
| 120 |
protected function render_ctas_container() { |
| 121 |
$primary_cta_button_text = $this->settings['primary_cta_button_text']; |
| 122 |
$secondary_cta_button_text = $this->settings['secondary_cta_button_text']; |
| 123 |
$has_primary_button = ! empty( $primary_cta_button_text ); |
| 124 |
$has_secondary_button = ! empty( $secondary_cta_button_text ); |
| 125 |
|
| 126 |
$ctas_container_classnames = [ self::LAYOUT_CLASSNAME . '__ctas-container' ]; |
| 127 |
|
| 128 |
$this->widget->add_render_attribute( 'ctas-container', [ |
| 129 |
'class' => $ctas_container_classnames, |
| 130 |
] ); |
| 131 |
?> |
| 132 |
<div <?php $this->widget->print_render_attribute_string( 'ctas-container' ); ?>> |
| 133 |
<?php if ( $has_primary_button ) { |
| 134 |
$this->render_button( 'primary' ); |
| 135 |
} ?> |
| 136 |
<?php if ( $has_secondary_button ) { |
| 137 |
$this->render_button( 'secondary' ); |
| 138 |
} ?> |
| 139 |
</div> |
| 140 |
<?php |
| 141 |
} |
| 142 |
|
| 143 |
protected function render_button( $type ) { |
| 144 |
$button = new Ehp_Button( $this->widget, [ |
| 145 |
'type' => $type, |
| 146 |
'widget_name' => $this->widget->get_name(), |
| 147 |
] ); |
| 148 |
$button->render(); |
| 149 |
} |
| 150 |
|
| 151 |
protected function render_image_container() { |
| 152 |
$this->widget->add_render_attribute( 'image-wrapper', 'class', self::LAYOUT_CLASSNAME . '__image-wrapper' ); |
| 153 |
?> |
| 154 |
<div <?php $this->widget->print_render_attribute_string( 'image-wrapper' ); ?>> |
| 155 |
<?php |
| 156 |
$image = new Ehp_Image( $this->widget, [ |
| 157 |
'widget_name' => $this->widget->get_name(), |
| 158 |
] ); |
| 159 |
$image->render(); |
| 160 |
?> |
| 161 |
</div> |
| 162 |
<?php |
| 163 |
} |
| 164 |
} |
| 165 |
|