gallery.php 3.2 KB

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