← All changes
|
modules/atomic-widgets/elements/atomic-image/atomic-image.php
+35
-45
4.2.0-beta2
→
3.30.1
View file →
| @@ -1,21 +1,22 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | namespace Elementor\Modules\AtomicWidgets\Elements\Atomic_Image; |
| 3 | 3 | |
| 4 | 4 | use Elementor\Modules\AtomicWidgets\Controls\Types\Link_Control; |
| 5 | -use Elementor\Modules\AtomicWidgets\Elements\Base\Has_Template; | |
| 5 | +use Elementor\Modules\AtomicWidgets\Controls\Types\Text_Control; | |
| 6 | +use Elementor\Modules\AtomicWidgets\Elements\Has_Template; | |
| 7 | +use Elementor\Modules\AtomicWidgets\Module; | |
| 6 | 8 | use Elementor\Modules\AtomicWidgets\PropTypes\Classes_Prop_Type; |
| 7 | 9 | use Elementor\Modules\AtomicWidgets\PropTypes\Image_Prop_Type; |
| 8 | 10 | use Elementor\Modules\AtomicWidgets\PropTypes\Link_Prop_Type; |
| 9 | 11 | use Elementor\Modules\AtomicWidgets\Controls\Section; |
| 10 | -use Elementor\Modules\AtomicWidgets\Elements\Base\Atomic_Widget_Base; | |
| 11 | -use Elementor\Modules\AtomicWidgets\PropTypes\Attributes_Prop_Type; | |
| 12 | +use Elementor\Modules\AtomicWidgets\Elements\Atomic_Widget_Base; | |
| 12 | 13 | use Elementor\Modules\AtomicWidgets\Controls\Types\Image_Control; |
| 13 | -use Elementor\Modules\AtomicWidgets\Utils\Image\Placeholder_Image; | |
| 14 | +use Elementor\Modules\AtomicWidgets\Image\Placeholder_Image; | |
| 15 | +use Elementor\Modules\AtomicWidgets\PropTypes\Primitives\String_Prop_Type; | |
| 14 | 16 | use Elementor\Modules\AtomicWidgets\Styles\Style_Definition; |
| 15 | 17 | use Elementor\Modules\AtomicWidgets\Styles\Style_Variant; |
| 16 | -use Elementor\Modules\AtomicWidgets\Controls\Types\Text_Control; | |
| 17 | -use Elementor\Modules\Components\PropTypes\Overridable_Prop_Type; | |
| 18 | +use Elementor\Plugin; | |
| 18 | 19 | |
| 19 | 20 | if ( ! defined( 'ABSPATH' ) ) { |
| 20 | 21 | exit; // Exit if accessed directly. |
| 21 | 22 | } |
| @@ -22,10 +23,8 @@ | ||
| 22 | 23 | |
| 23 | 24 | class Atomic_Image extends Atomic_Widget_Base { |
| 24 | 25 | use Has_Template; |
| 25 | 26 | |
| 26 | - public static $widget_description = 'Display an image with customizable styles and link options.'; | |
| 27 | - | |
| 28 | 27 | const LINK_BASE_STYLE_KEY = 'link-base'; |
| 29 | 28 | const BASE_STYLE_KEY = 'base'; |
| 30 | 29 | |
| 31 | 30 | public static function get_element_type(): string { |
| @@ -53,39 +52,45 @@ | ||
| 53 | 52 | ->default_url( Placeholder_Image::get_placeholder_image() ) |
| 54 | 53 | ->default_size( 'full' ), |
| 55 | 54 | |
| 56 | 55 | 'link' => Link_Prop_Type::make(), |
| 56 | + ]; | |
| 57 | 57 | |
| 58 | - 'attributes' => Attributes_Prop_Type::make()->meta( Overridable_Prop_Type::ignore() ), | |
| 59 | - ]; | |
| 58 | + if ( Plugin::$instance->experiments->is_feature_active( Module::EXPERIMENT_VERSION_3_30 ) ) { | |
| 59 | + $props['_cssid'] = String_Prop_Type::make(); | |
| 60 | + } | |
| 60 | 61 | |
| 61 | 62 | return $props; |
| 62 | 63 | } |
| 63 | 64 | |
| 64 | 65 | protected function define_atomic_controls(): array { |
| 65 | - return [ | |
| 66 | - Section::make() | |
| 67 | - ->set_label( esc_html__( 'Content', 'elementor' ) ) | |
| 68 | - ->set_id( 'content' ) | |
| 69 | - ->set_items( [ | |
| 70 | - Image_Control::bind_to( 'image' ) | |
| 71 | - ->set_label( __( 'Image', 'elementor' ) ), | |
| 72 | - ] ), | |
| 73 | - Section::make() | |
| 74 | - ->set_label( __( 'Settings', 'elementor' ) ) | |
| 75 | - ->set_id( 'settings' ) | |
| 76 | - ->set_items( $this->get_settings_controls() ), | |
| 66 | + $content_section = Section::make() | |
| 67 | + ->set_label( esc_html__( 'Content', 'elementor' ) ) | |
| 68 | + ->set_items( [ | |
| 69 | + Image_Control::bind_to( 'image' ) | |
| 70 | + ->set_show_mode( 'media' ), | |
| 71 | + ] ); | |
| 72 | + | |
| 73 | + $settings_section_items = [ | |
| 74 | + Image_Control::bind_to( 'image' ) | |
| 75 | + ->set_show_mode( 'sizes' ), | |
| 76 | + Link_Control::bind_to( 'link' )->set_meta( [ | |
| 77 | + 'topDivider' => true, | |
| 78 | + ] ), | |
| 77 | 79 | ]; |
| 78 | - } | |
| 79 | 80 | |
| 80 | - protected function get_settings_controls(): array { | |
| 81 | + if ( Plugin::$instance->experiments->is_feature_active( Module::EXPERIMENT_VERSION_3_30 ) ) { | |
| 82 | + $settings_section_items[] = Text_Control::bind_to( '_cssid' )->set_label( __( 'ID', 'elementor' ) )->set_meta( [ | |
| 83 | + 'layout' => 'two-columns', | |
| 84 | + 'topDivider' => true, | |
| 85 | + ] ); | |
| 86 | + } | |
| 87 | + | |
| 81 | 88 | return [ |
| 82 | - Link_Control::bind_to( 'link' ) | |
| 83 | - ->set_placeholder( __( 'Type or paste your URL', 'elementor' ) ) | |
| 84 | - ->set_label( __( 'Link', 'elementor' ) ), | |
| 85 | - Text_Control::bind_to( '_cssid' ) | |
| 86 | - ->set_label( __( 'ID', 'elementor' ) ) | |
| 87 | - ->set_meta( $this->get_css_id_control_meta() ), | |
| 89 | + $content_section, | |
| 90 | + Section::make() | |
| 91 | + ->set_label( esc_html__( 'Settings', 'elementor' ) ) | |
| 92 | + ->set_items( $settings_section_items ), | |
| 88 | 93 | ]; |
| 89 | 94 | } |
| 90 | 95 | |
| 91 | 96 | protected function define_base_styles(): array { |
| @@ -92,12 +97,10 @@ | ||
| 92 | 97 | return [ |
| 93 | 98 | self::LINK_BASE_STYLE_KEY => Style_Definition::make() |
| 94 | 99 | ->add_variant( |
| 95 | 100 | Style_Variant::make() |
| 96 | - ->add_prop( 'all', 'unset' ) | |
| 97 | 101 | ->add_prop( 'display', 'inherit' ) |
| 98 | 102 | ->add_prop( 'width', 'fit-content' ) |
| 99 | - ->add_prop( 'cursor', 'pointer' ) | |
| 100 | 103 | ), |
| 101 | 104 | self::BASE_STYLE_KEY => Style_Definition::make() |
| 102 | 105 | ->add_variant( |
| 103 | 106 | Style_Variant::make() |
| @@ -109,19 +112,6 @@ | ||
| 109 | 112 | protected function get_templates(): array { |
| 110 | 113 | return [ |
| 111 | 114 | 'elementor/elements/atomic-image' => __DIR__ . '/atomic-image.html.twig', |
| 112 | 115 | ]; |
| 113 | - } | |
| 114 | - | |
| 115 | - public function render_markdown(): string { | |
| 116 | - $settings = $this->get_atomic_settings(); | |
| 117 | - $src = $settings['image']['src'] ?? ''; | |
| 118 | - | |
| 119 | - if ( empty( $src ) ) { | |
| 120 | - return ''; | |
| 121 | - } | |
| 122 | - | |
| 123 | - $alt = $settings['image']['alt'] ?? ''; | |
| 124 | - | |
| 125 | - return ' . ')'; | |
| 126 | 116 | } |
| 127 | 117 | } |