PluginProbe
Hello Plus / 1.2.0
Hello Plus v1.2.0
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-hero-render.php

widget-hero-render.php in Hello Plus 1.2.0, at modules/content/classes/render/widget-hero-render.php

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