gallery.php (3635B)
1 <?php 2 namespace Elementor; 3 4 use Elementor\Modules\DynamicTags\Module as TagsModule; 5 6 if ( ! defined( 'ABSPATH' ) ) { 7 exit; // Exit if accessed directly. 8 } 9 10 /** 11 * Elementor gallery control. 12 * 13 * A base control for creating gallery chooser control. Based on the WordPress 14 * media library galleries. Used to select images from the WordPress media library. 15 * 16 * @since 1.0.0 17 */ 18 class Control_Gallery extends Base_Data_Control { 19 20 /** 21 * Get gallery control type. 22 * 23 * Retrieve the control type, in this case `gallery`. 24 * 25 * @since 1.0.0 26 * @access public 27 * 28 * @return string Control type. 29 */ 30 public function get_type() { 31 return 'gallery'; 32 } 33 34 /** 35 * Import gallery images. 36 * 37 * Used to import gallery control files from external sites while importing 38 * Elementor template JSON file, and replacing the old data. 39 * 40 * @since 1.0.0 41 * @access public 42 * 43 * @param array $settings Control settings 44 * 45 * @return array Control settings. 46 */ 47 public function on_import( $settings ) { 48 foreach ( $settings as &$attachment ) { 49 if ( empty( $attachment['url'] ) ) { 50 continue; 51 } 52 53 $attachment = Plugin::$instance->templates_manager->get_import_images_instance()->import( $attachment ); 54 } 55 56 // Filter out attachments that don't exist 57 $settings = array_filter( $settings ); 58 59 return $settings; 60 } 61 62 /** 63 * Render gallery control output in the editor. 64 * 65 * Used to generate the control HTML in the editor using Underscore JS 66 * template. The variables for the class are available using `data` JS 67 * object. 68 * 69 * @since 1.0.0 70 * @access public 71 */ 72 public function content_template() { 73 ?> 74 <div class="elementor-control-field"> 75 <div class="elementor-control-title">{{{ data.label }}}</div> 76 <div class="elementor-control-input-wrapper"> 77 <# if ( data.description ) { #> 78 <div class="elementor-control-field-description">{{{ data.description }}}</div> 79 <# } #> 80 <div class="elementor-control-media__content elementor-control-tag-area"> 81 <div class="elementor-control-gallery-status elementor-control-dynamic-switcher-wrapper"> 82 <span class="elementor-control-gallery-status-title"></span> 83 <span class="elementor-control-gallery-clear elementor-control-unit-1"><i class="eicon-trash-o" aria-hidden="true"></i></span> 84 </div> 85 <div class="elementor-control-gallery-content"> 86 <div class="elementor-control-gallery-thumbnails"></div> 87 <div class="elementor-control-gallery-edit"><span><i class="eicon-pencil" aria-hidden="true"></i></span></div> 88 <button class="elementor-button elementor-control-gallery-add" aria-label="<?php echo esc_html__( 'Add Images', 'elementor' ); ?>"><i class="eicon-plus-circle" aria-hidden="true"></i></button> 89 </div> 90 </div> 91 </div> 92 </div> 93 <?php 94 } 95 96 /** 97 * Get gallery control default settings. 98 * 99 * Retrieve the default settings of the gallery control. Used to return the 100 * default settings while initializing the gallery control. 101 * 102 * @since 1.0.0 103 * @access protected 104 * 105 * @return array Control default settings. 106 */ 107 protected function get_default_settings() { 108 return [ 109 'label_block' => true, 110 'separator' => 'none', 111 'dynamic' => [ 112 'categories' => [ TagsModule::GALLERY_CATEGORY ], 113 'returnType' => 'object', 114 ], 115 ]; 116 } 117 118 /** 119 * Get gallery control default values. 120 * 121 * Retrieve the default value of the gallery control. Used to return the default 122 * values while initializing the gallery control. 123 * 124 * @since 1.0.0 125 * @access public 126 * 127 * @return array Control default value. 128 */ 129 public function get_default_value() { 130 return []; 131 } 132 }