1: <?php
2: /**
3: * Elementor Property Heading Widget
4: *
5: * @package EPL
6: * @subpackage PageBuilders/Elementor/Widgets/Elements
7: * @since 3.6.0
8: */
9:
10: // Exit if accessed directly.
11: if ( ! defined( 'ABSPATH' ) ) {
12: exit;
13: }
14:
15: /**
16: * EPL_Elementor_Property_Heading Class
17: *
18: * Displays property heading (headline/tagline).
19: *
20: * @since 3.6.0
21: */
22: class EPL_Elementor_Property_Heading extends \Elementor\Widget_Base {
23: use EPL_Elementor_Dynamic_Widget;
24:
25: /**
26: * Get widget name.
27: *
28: * @return string
29: * @since 3.6.0 New: Elementor widgets (beta).
30: */
31: public function get_name() {
32: return 'epl-property-heading';
33: }
34:
35: /**
36: * Get widget title.
37: *
38: * @return string
39: * @since 3.6.0 New: Elementor widgets (beta).
40: */
41: public function get_title() {
42: return esc_html__( 'Heading', 'easy-property-listings' );
43: }
44:
45: /**
46: * Get widget icon.
47: *
48: * @return string
49: * @since 3.6.0 New: Elementor widgets (beta).
50: */
51: public function get_icon() {
52: return 'eicon-heading';
53: }
54:
55: /**
56: * Get widget categories.
57: *
58: * @return array
59: * @since 3.6.0 New: Elementor widgets (beta).
60: */
61: public function get_categories() {
62: return array( 'epl-elements' );
63: }
64:
65: /**
66: * Get widget keywords.
67: *
68: * @return array
69: * @since 3.6.0 New: Elementor widgets (beta).
70: */
71: public function get_keywords() {
72: return array( 'property', 'heading', 'headline', 'epl' );
73: }
74:
75: /**
76: * Register widget controls.
77: * @since 3.6.0 New: Elementor widgets (beta).
78: */
79: protected function register_controls() {
80:
81: $this->start_controls_section(
82: 'section_content',
83: array(
84: 'label' => esc_html__( 'Content', 'easy-property-listings' ),
85: 'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
86: )
87: );
88:
89: $this->add_control(
90: 'html_tag',
91: array(
92: 'label' => esc_html__( 'HTML Tag', 'easy-property-listings' ),
93: 'type' => \Elementor\Controls_Manager::SELECT,
94: 'options' => array(
95: 'h1' => 'H1',
96: 'h2' => 'H2',
97: 'h3' => 'H3',
98: 'h4' => 'H4',
99: 'h5' => 'H5',
100: 'h6' => 'H6',
101: 'div' => 'div',
102: 'span' => 'span',
103: 'p' => 'p',
104: ),
105: 'default' => 'h3',
106: )
107: );
108:
109: $this->end_controls_section();
110:
111: // Style Section.
112: $this->start_controls_section(
113: 'section_style',
114: array(
115: 'label' => esc_html__( 'Style', 'easy-property-listings' ),
116: 'tab' => \Elementor\Controls_Manager::TAB_STYLE,
117: )
118: );
119:
120: $this->add_control(
121: 'text_color',
122: array(
123: 'label' => esc_html__( 'Color', 'easy-property-listings' ),
124: 'type' => \Elementor\Controls_Manager::COLOR,
125: 'selectors' => array(
126: '{{WRAPPER}} .epl-property-heading' => 'color: {{VALUE}};',
127: ),
128: )
129: );
130:
131: $this->add_group_control(
132: \Elementor\Group_Control_Typography::get_type(),
133: array(
134: 'name' => 'typography',
135: 'selector' => '{{WRAPPER}} .epl-property-heading',
136: )
137: );
138:
139: $this->add_responsive_control(
140: 'text_align',
141: array(
142: 'label' => esc_html__( 'Alignment', 'easy-property-listings' ),
143: 'type' => \Elementor\Controls_Manager::CHOOSE,
144: 'options' => array(
145: 'left' => array(
146: 'title' => esc_html__( 'Left', 'easy-property-listings' ),
147: 'icon' => 'eicon-text-align-left',
148: ),
149: 'center' => array(
150: 'title' => esc_html__( 'Center', 'easy-property-listings' ),
151: 'icon' => 'eicon-text-align-center',
152: ),
153: 'right' => array(
154: 'title' => esc_html__( 'Right', 'easy-property-listings' ),
155: 'icon' => 'eicon-text-align-right',
156: ),
157: ),
158: 'selectors' => array(
159: '{{WRAPPER}} .epl-property-heading' => 'text-align: {{VALUE}};',
160: ),
161: )
162: );
163:
164: $this->end_controls_section();
165: }
166:
167: /**
168: * Render widget output.
169: * @since 3.6.0 New: Elementor widgets (beta).
170: */
171: protected function render() {
172: $property = EPL_Elementor::setup_listing_context();
173: $is_editor = \Elementor\Plugin::$instance->editor->is_edit_mode();
174:
175: if ( ! $property ) {
176: if ( $is_editor ) {
177: echo '<div class="epl-elementor-placeholder">' . esc_html__( 'Property Heading - No listings found.', 'easy-property-listings' ) . '</div>';
178: }
179: EPL_Elementor::restore_listing_context();
180: return;
181: }
182:
183: $settings = $this->get_settings_for_display();
184: $tag = \Elementor\Utils::validate_html_tag( $settings['html_tag'] );
185: $heading = $property->get_property_meta( 'property_heading' );
186:
187: // Match core behaviour: fall back to the post title when no heading is set.
188: if ( empty( $heading ) ) {
189: $heading = get_the_title( $property->post->ID );
190: }
191:
192: if ( empty( $heading ) ) {
193: EPL_Elementor::restore_listing_context();
194: return;
195: }
196:
197: echo '<' . esc_attr( $tag ) . ' class="epl-property-heading">';
198: echo esc_html( $heading );
199: echo '</' . esc_attr( $tag ) . '>';
200:
201: EPL_Elementor::restore_listing_context();
202: }
203: }
204: