| 1 |
<?php |
| 2 |
namespace Elementor\Modules\AtomicWidgets\Elements\Atomic_Youtube; |
| 3 |
|
| 4 |
use Elementor\Modules\AtomicWidgets\Controls\Section; |
| 5 |
use Elementor\Modules\AtomicWidgets\Controls\Types\Switch_Control; |
| 6 |
use Elementor\Modules\AtomicWidgets\Controls\Types\Text_Control; |
| 7 |
use Elementor\Modules\AtomicWidgets\DynamicTags\Dynamic_Prop_Type; |
| 8 |
use Elementor\Modules\AtomicWidgets\Elements\Base\Atomic_Widget_Base; |
| 9 |
use Elementor\Modules\AtomicWidgets\Elements\Base\Has_Template; |
| 10 |
use Elementor\Modules\AtomicWidgets\PropTypes\Classes_Prop_Type; |
| 11 |
use Elementor\Modules\AtomicWidgets\PropTypes\Attributes_Prop_Type; |
| 12 |
use Elementor\Modules\AtomicWidgets\PropTypes\Primitives\Boolean_Prop_Type; |
| 13 |
use Elementor\Modules\AtomicWidgets\PropTypes\Primitives\String_Prop_Type; |
| 14 |
use Elementor\Modules\AtomicWidgets\Styles\Style_Definition; |
| 15 |
use Elementor\Modules\AtomicWidgets\Styles\Style_Variant; |
| 16 |
use Elementor\Modules\AtomicWidgets\Elements\Loader\Frontend_Assets_Loader; |
| 17 |
use Elementor\Modules\Components\PropTypes\Overridable_Prop_Type; |
| 18 |
use Elementor\Utils; |
| 19 |
|
| 20 |
if ( ! defined( 'ABSPATH' ) ) { |
| 21 |
exit; // Exit if accessed directly. |
| 22 |
} |
| 23 |
|
| 24 |
class Atomic_Youtube extends Atomic_Widget_Base { |
| 25 |
use Has_Template; |
| 26 |
|
| 27 |
protected function get_css_id_control_meta(): array { |
| 28 |
return [ |
| 29 |
'layout' => 'two-columns', |
| 30 |
'topDivider' => false, |
| 31 |
]; |
| 32 |
} |
| 33 |
|
| 34 |
public static function get_element_type(): string { |
| 35 |
return 'e-youtube'; |
| 36 |
} |
| 37 |
|
| 38 |
public function get_title() { |
| 39 |
return esc_html__( 'YouTube', 'elementor' ); |
| 40 |
} |
| 41 |
|
| 42 |
public function get_keywords() { |
| 43 |
return [ 'ato', 'atom', 'atoms', 'atomic' ]; |
| 44 |
} |
| 45 |
|
| 46 |
public function get_icon() { |
| 47 |
return 'eicon-e-youtube'; |
| 48 |
} |
| 49 |
|
| 50 |
protected static function define_props_schema(): array { |
| 51 |
return [ |
| 52 |
'classes' => Classes_Prop_Type::make() |
| 53 |
->default( [] ), |
| 54 |
|
| 55 |
'source' => String_Prop_Type::make() |
| 56 |
->default( 'https://www.youtube.com/watch?v=XHOmBV4js_E' ), |
| 57 |
|
| 58 |
'start' => String_Prop_Type::make()->meta( Dynamic_Prop_Type::ignore() ), |
| 59 |
'end' => String_Prop_Type::make()->meta( Dynamic_Prop_Type::ignore() ), |
| 60 |
'autoplay' => Boolean_Prop_Type::make()->default( false ), |
| 61 |
'mute' => Boolean_Prop_Type::make()->default( false ), |
| 62 |
'loop' => Boolean_Prop_Type::make()->default( false ), |
| 63 |
'lazyload' => Boolean_Prop_Type::make()->default( false ), |
| 64 |
'player_controls' => Boolean_Prop_Type::make()->default( true ), |
| 65 |
'captions' => Boolean_Prop_Type::make()->default( false ), |
| 66 |
'privacy_mode' => Boolean_Prop_Type::make()->default( false ), |
| 67 |
'rel' => Boolean_Prop_Type::make()->default( true ), |
| 68 |
|
| 69 |
'attributes' => Attributes_Prop_Type::make()->meta( Overridable_Prop_Type::ignore() ), |
| 70 |
]; |
| 71 |
} |
| 72 |
|
| 73 |
protected function define_atomic_controls(): array { |
| 74 |
return [ |
| 75 |
Section::make() |
| 76 |
->set_label( __( 'Content', 'elementor' ) ) |
| 77 |
->set_items( [ |
| 78 |
Text_Control::bind_to( 'source' ) |
| 79 |
->set_placeholder( esc_html__( 'Type or paste your URL', 'elementor' ) ) |
| 80 |
->set_label( esc_html__( 'YouTube URL', 'elementor' ) ), |
| 81 |
|
| 82 |
Text_Control::bind_to( 'start' )->set_label( esc_html__( 'Start time', 'elementor' ) ), |
| 83 |
Text_Control::bind_to( 'end' )->set_label( esc_html__( 'End time', 'elementor' ) ), |
| 84 |
Switch_Control::bind_to( 'autoplay' )->set_label( esc_html__( 'Autoplay', 'elementor' ) ), |
| 85 |
Switch_Control::bind_to( 'mute' )->set_label( esc_html__( 'Mute', 'elementor' ) ), |
| 86 |
Switch_Control::bind_to( 'loop' )->set_label( esc_html__( 'Loop', 'elementor' ) ), |
| 87 |
Switch_Control::bind_to( 'lazyload' )->set_label( esc_html__( 'Lazy load', 'elementor' ) ), |
| 88 |
Switch_Control::bind_to( 'player_controls' )->set_label( esc_html__( 'Player controls', 'elementor' ) ), |
| 89 |
Switch_Control::bind_to( 'captions' )->set_label( esc_html__( 'Captions', 'elementor' ) ), |
| 90 |
Switch_Control::bind_to( 'privacy_mode' )->set_label( esc_html__( 'Privacy mode', 'elementor' ) ), |
| 91 |
Switch_Control::bind_to( 'rel' )->set_label( esc_html__( 'Related videos', 'elementor' ) ), |
| 92 |
] ), |
| 93 |
Section::make() |
| 94 |
->set_label( __( 'Settings', 'elementor' ) ) |
| 95 |
->set_id( 'settings' ) |
| 96 |
->set_items( $this->get_settings_controls() ), |
| 97 |
]; |
| 98 |
} |
| 99 |
|
| 100 |
protected function get_settings_controls(): array { |
| 101 |
return [ |
| 102 |
Text_Control::bind_to( '_cssid' ) |
| 103 |
->set_label( __( 'ID', 'elementor' ) ) |
| 104 |
->set_meta( $this->get_css_id_control_meta() ), |
| 105 |
]; |
| 106 |
} |
| 107 |
|
| 108 |
protected function define_base_styles(): array { |
| 109 |
return [ |
| 110 |
'base' => Style_Definition::make() |
| 111 |
->add_variant( |
| 112 |
Style_Variant::make() |
| 113 |
->add_prop( 'aspect-ratio', String_Prop_Type::generate( '16/9' ) ) |
| 114 |
->add_prop( 'overflow', String_Prop_Type::generate( 'hidden' ) ) |
| 115 |
), |
| 116 |
]; |
| 117 |
} |
| 118 |
|
| 119 |
public function get_script_depends() { |
| 120 |
return array_merge( |
| 121 |
parent::get_script_depends(), |
| 122 |
[ 'elementor-youtube-handler' ], |
| 123 |
); |
| 124 |
} |
| 125 |
|
| 126 |
public function register_frontend_handlers() { |
| 127 |
$assets_url = ELEMENTOR_ASSETS_URL; |
| 128 |
$min_suffix = ( Utils::is_script_debug() || Utils::is_elementor_tests() ) ? '' : '.min'; |
| 129 |
|
| 130 |
wp_register_script( |
| 131 |
'elementor-youtube-handler', |
| 132 |
"{$assets_url}js/youtube-handler{$min_suffix}.js", |
| 133 |
[ Frontend_Assets_Loader::FRONTEND_HANDLERS_HANDLE ], |
| 134 |
ELEMENTOR_VERSION, |
| 135 |
true |
| 136 |
); |
| 137 |
} |
| 138 |
|
| 139 |
protected function get_templates(): array { |
| 140 |
return [ |
| 141 |
'elementor/elements/atomic-youtube' => __DIR__ . '/atomic-youtube.html.twig', |
| 142 |
]; |
| 143 |
} |
| 144 |
} |
| 145 |
|