PluginProbe
Elementor Website Builder – more than just a page builder / 4.3.0-beta3
Elementor Website Builder – more than just a page builder v4.3.0-beta3
4.3.0-beta3 4.3.0-beta2 4.3.0-beta1 4.2.4 4.2.3 4.2.2 4.2.1 4.2.0 4.1.5 4.2.0-beta2 4.2.0-dev2 4.2.0-beta1 4.1.4 4.1.3 4.1.2 4.1.1 4.1.0 4.1.0-beta3 4.1.0-dev3 4.0.9 4.1.0-beta2 4.1.0-dev2 4.0.8 4.1.0-beta1 4.1.0-dev1 All 452 releases
elementor / modules / atomic-widgets / elements / atomic-youtube / atomic-youtube.php

atomic-youtube.php in Elementor Website Builder – more than just a page builder 4.3.0-beta3, at modules/atomic-widgets/elements/atomic-youtube/atomic-youtube.php

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