| 1 |
<?php |
| 2 |
namespace Elementor\Modules\Components\Widgets; |
| 3 |
|
| 4 |
use Elementor\Modules\AtomicWidgets\Elements\Atomic_Widget_Base; |
| 5 |
use Elementor\Modules\AtomicWidgets\PropTypes\Primitives\Number_Prop_Type; |
| 6 |
use Elementor\Plugin; |
| 7 |
|
| 8 |
if ( ! defined( 'ABSPATH' ) ) { |
| 9 |
exit; // Exit if accessed directly. |
| 10 |
} |
| 11 |
|
| 12 |
class Component extends Atomic_Widget_Base { |
| 13 |
|
| 14 |
public static function get_element_type(): string { |
| 15 |
return 'e-component'; |
| 16 |
} |
| 17 |
|
| 18 |
public function show_in_panel() { |
| 19 |
return false; |
| 20 |
} |
| 21 |
|
| 22 |
public function get_title() { |
| 23 |
$title = esc_html__( 'Component', 'elementor' ); |
| 24 |
|
| 25 |
if ( isset( $this->get_settings ) && null !== $this->get_settings( 'component_id' ) ) { |
| 26 |
$post_id = $this->get_settings( 'component_id' )['value']; |
| 27 |
$title = Plugin::$instance->documents->get( $post_id )->get_title(); |
| 28 |
} |
| 29 |
|
| 30 |
return $title; |
| 31 |
} |
| 32 |
|
| 33 |
public function get_keywords() { |
| 34 |
return [ 'component' ]; |
| 35 |
} |
| 36 |
|
| 37 |
public function get_icon() { |
| 38 |
return 'eicon-star'; |
| 39 |
} |
| 40 |
|
| 41 |
protected static function define_props_schema(): array { |
| 42 |
return [ |
| 43 |
'component_id' => Number_Prop_Type::make(), |
| 44 |
]; |
| 45 |
} |
| 46 |
|
| 47 |
protected function define_atomic_controls(): array { |
| 48 |
return []; |
| 49 |
} |
| 50 |
|
| 51 |
protected function get_settings_controls(): array { |
| 52 |
return []; |
| 53 |
} |
| 54 |
|
| 55 |
protected function render(): void { |
| 56 |
if ( null === $this->get_settings( 'component_id' ) ) { |
| 57 |
return; |
| 58 |
} |
| 59 |
|
| 60 |
$post_id = $this->get_settings( 'component_id' )['value']; |
| 61 |
$content = Plugin::$instance->frontend->get_builder_content( $post_id ); |
| 62 |
$html = sprintf( '<div class="e-component">%s</div>', $content ); |
| 63 |
|
| 64 |
// PHPCS - should not be escaped. |
| 65 |
echo $html; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 66 |
} |
| 67 |
} |
| 68 |
|