| 1 |
<?php |
| 2 |
namespace Elementor\Modules\AtomicWidgets\Widgets; |
| 3 |
|
| 4 |
use Elementor\Modules\AtomicWidgets\PropTypes\Classes_Prop_Type; |
| 5 |
use Elementor\Modules\AtomicWidgets\PropTypes\Image_Prop_Type; |
| 6 |
use Elementor\Utils; |
| 7 |
use Elementor\Modules\AtomicWidgets\Controls\Section; |
| 8 |
use Elementor\Modules\AtomicWidgets\Base\Atomic_Widget_Base; |
| 9 |
use Elementor\Modules\AtomicWidgets\Controls\Types\Image_Control; |
| 10 |
|
| 11 |
if ( ! defined( 'ABSPATH' ) ) { |
| 12 |
exit; // Exit if accessed directly. |
| 13 |
} |
| 14 |
|
| 15 |
class Atomic_Image extends Atomic_Widget_Base { |
| 16 |
public function get_name() { |
| 17 |
return 'a-image'; |
| 18 |
} |
| 19 |
|
| 20 |
public function get_title() { |
| 21 |
return esc_html__( 'Atomic Image', 'elementor' ); |
| 22 |
} |
| 23 |
|
| 24 |
public function get_icon() { |
| 25 |
return 'eicon-image'; |
| 26 |
} |
| 27 |
|
| 28 |
protected function render() { |
| 29 |
$settings = $this->get_atomic_settings(); |
| 30 |
|
| 31 |
if ( ! isset( $settings['image'] ) ) { |
| 32 |
return; |
| 33 |
} |
| 34 |
|
| 35 |
$attrs = array_filter( array_merge( |
| 36 |
$settings['image'], |
| 37 |
[ 'class' => $settings['classes'] ?? '' ] |
| 38 |
) ); |
| 39 |
|
| 40 |
$attrs['src'] = esc_url( $attrs['src'] ); |
| 41 |
|
| 42 |
Utils::print_wp_kses_extended( |
| 43 |
sprintf( |
| 44 |
'<img %1$s >', |
| 45 |
Utils::render_html_attributes( $attrs ) |
| 46 |
), |
| 47 |
[ 'image' ] |
| 48 |
); |
| 49 |
} |
| 50 |
|
| 51 |
protected function define_atomic_controls(): array { |
| 52 |
$content_section = Section::make() |
| 53 |
->set_label( esc_html__( 'Content', 'elementor' ) ) |
| 54 |
->set_items( [ |
| 55 |
Image_Control::bind_to( 'image' ), |
| 56 |
] ); |
| 57 |
|
| 58 |
return [ |
| 59 |
$content_section, |
| 60 |
]; |
| 61 |
} |
| 62 |
|
| 63 |
protected static function define_props_schema(): array { |
| 64 |
return [ |
| 65 |
'classes' => Classes_Prop_Type::make() |
| 66 |
->default( [] ), |
| 67 |
|
| 68 |
'image' => Image_Prop_Type::make() |
| 69 |
->default_url( Utils::get_placeholder_image_src() ) |
| 70 |
->default_size( 'full' ), |
| 71 |
]; |
| 72 |
} |
| 73 |
} |
| 74 |
|