| 1 |
<?php |
| 2 |
namespace HelloPlus\Modules\Content\Classes\Render; |
| 3 |
|
| 4 |
if ( ! defined( 'ABSPATH' ) ) { |
| 5 |
exit; // Exit if accessed directly. |
| 6 |
} |
| 7 |
|
| 8 |
use Elementor\Utils; |
| 9 |
use HelloPlus\Modules\Content\Widgets\Hero; |
| 10 |
use HelloPlus\Classes\{ |
| 11 |
Ehp_Button, |
| 12 |
Ehp_Image, |
| 13 |
}; |
| 14 |
|
| 15 |
class Widget_Hero_Render { |
| 16 |
protected Hero $widget; |
| 17 |
const LAYOUT_CLASSNAME = 'ehp-hero'; |
| 18 |
const TEXT_CONTAINER_CLASSNAME = 'ehp-hero__text-container'; |
| 19 |
const BUTTON_CLASSNAME = 'ehp-hero__button'; |
| 20 |
const IMAGE_CLASSNAME = 'ehp-hero__image'; |
| 21 |
|
| 22 |
protected array $settings; |
| 23 |
|
| 24 |
public function __construct( Hero $widget ) { |
| 25 |
$this->widget = $widget; |
| 26 |
$this->settings = $widget->get_settings_for_display(); |
| 27 |
} |
| 28 |
|
| 29 |
public function render(): void { |
| 30 |
$layout_classnames = self::LAYOUT_CLASSNAME; |
| 31 |
$layout_full_height_controls = $this->settings['box_full_screen_height_controls'] ?? ''; |
| 32 |
|
| 33 |
if ( ! empty( $layout_full_height_controls ) ) { |
| 34 |
foreach ( $layout_full_height_controls as $breakpoint ) { |
| 35 |
$layout_classnames .= ' is-full-height-' . $breakpoint; |
| 36 |
} |
| 37 |
} |
| 38 |
|
| 39 |
$this->widget->add_render_attribute( 'layout', [ |
| 40 |
'class' => $layout_classnames, |
| 41 |
] ); |
| 42 |
?> |
| 43 |
<div <?php $this->widget->print_render_attribute_string( 'layout' ); ?>> |
| 44 |
<?php |
| 45 |
$this->render_text_container(); |
| 46 |
$this->render_cta_button(); |
| 47 |
$this->render_image_container(); |
| 48 |
?> |
| 49 |
</div> |
| 50 |
<?php |
| 51 |
} |
| 52 |
|
| 53 |
public function render_text_container() { |
| 54 |
$heading_text = $this->settings['heading_text']; |
| 55 |
$heading_tag = $this->settings['heading_tag']; |
| 56 |
$has_heading = '' !== $heading_text; |
| 57 |
|
| 58 |
$subheading_text = $this->settings['subheading_text']; |
| 59 |
$subheading_tag = $this->settings['subheading_tag']; |
| 60 |
$has_subheading = '' !== $subheading_text; |
| 61 |
|
| 62 |
$text_container_classnames = self::TEXT_CONTAINER_CLASSNAME; |
| 63 |
|
| 64 |
$this->widget->add_render_attribute( 'text-container', [ |
| 65 |
'class' => $text_container_classnames, |
| 66 |
] ); |
| 67 |
?> |
| 68 |
<div <?php $this->widget->print_render_attribute_string( 'text-container' ); ?>> |
| 69 |
<?php if ( $has_heading ) { |
| 70 |
$heading_output = sprintf( '<%1$s %2$s>%3$s</%1$s>', Utils::validate_html_tag( $heading_tag ), 'class="ehp-hero__heading"', esc_html( $heading_text ) ); |
| 71 |
// Escaped above |
| 72 |
Utils::print_unescaped_internal_string( $heading_output ); |
| 73 |
} ?> |
| 74 |
<?php if ( $has_subheading ) { |
| 75 |
$subheading_output = sprintf( '<%1$s %2$s>%3$s</%1$s>', Utils::validate_html_tag( $subheading_tag ), 'class="ehp-hero__subheading"', esc_html( $subheading_text ) ); |
| 76 |
// Escaped above |
| 77 |
Utils::print_unescaped_internal_string( $subheading_output ); |
| 78 |
} ?> |
| 79 |
</div> |
| 80 |
<?php |
| 81 |
} |
| 82 |
|
| 83 |
public function render_cta_button() { |
| 84 |
$button = new Ehp_Button( $this->widget, [ |
| 85 |
'type' => 'primary', |
| 86 |
'widget_name' => $this->widget->get_name(), |
| 87 |
] ); |
| 88 |
?> |
| 89 |
<div class="ehp-hero__button-container"> |
| 90 |
<?php $button->render(); ?> |
| 91 |
</div> |
| 92 |
<?php |
| 93 |
} |
| 94 |
|
| 95 |
protected function render_image_container() { |
| 96 |
$image = new Ehp_Image( $this->widget, [ |
| 97 |
'widget_name' => $this->widget->get_name(), |
| 98 |
] ); |
| 99 |
$image->render(); |
| 100 |
} |
| 101 |
} |
| 102 |
|