| 1 |
<?php |
| 2 |
namespace Elementor\TemplateLibrary\Forms; |
| 3 |
|
| 4 |
use Elementor\Controls_Manager; |
| 5 |
use Elementor\Controls_Stack; |
| 6 |
|
| 7 |
if ( ! defined( 'ABSPATH' ) ) { |
| 8 |
exit; // Exit if accessed directly |
| 9 |
} |
| 10 |
|
| 11 |
class New_Template_Form extends Controls_Stack { |
| 12 |
|
| 13 |
public function get_name() { |
| 14 |
return 'add-template-form'; |
| 15 |
} |
| 16 |
|
| 17 |
/** |
| 18 |
* @throws \Exception |
| 19 |
*/ |
| 20 |
public function render() { |
| 21 |
foreach ( $this->get_controls() as $control ) { |
| 22 |
switch ( $control['type'] ) { |
| 23 |
case Controls_Manager::SELECT: |
| 24 |
$this->render_select( $control ); |
| 25 |
break; |
| 26 |
default: |
| 27 |
throw new \Exception( '"' . $control['type'] . '" control type is not supported' ); |
| 28 |
} |
| 29 |
} |
| 30 |
} |
| 31 |
|
| 32 |
private function render_select( $control_settings ) { |
| 33 |
$control_id = "elementor-new-template__form__{$control_settings['name']}"; |
| 34 |
$wrapper_class = isset( $control_settings['wrapper_class'] ) ? $control_settings['wrapper_class'] : ''; |
| 35 |
?> |
| 36 |
<div id="<?php echo esc_attr( $control_id ); ?>__wrapper" class="elementor-form-field <?php echo esc_attr( $wrapper_class ); ?>"> |
| 37 |
<label for="<?php echo esc_html( $control_id ); ?>" class="elementor-form-field__label"> |
| 38 |
<?php echo esc_html( $control_settings['label'] ); ?> |
| 39 |
</label> |
| 40 |
<div class="elementor-form-field__select__wrapper"> |
| 41 |
<select id="<?php echo esc_html( $control_id ); ?>" class="elementor-form-field__select" name="meta[<?php echo esc_html( $control_settings['name'] ); ?>]"> |
| 42 |
<?php |
| 43 |
foreach ( $control_settings['options'] as $key => $value ) { |
| 44 |
echo sprintf( '<option value="%1$s">%2$s</option>', esc_html( $key ), esc_html( $value ) ); |
| 45 |
} |
| 46 |
?> |
| 47 |
</select> |
| 48 |
</div> |
| 49 |
</div> |
| 50 |
<?php |
| 51 |
} |
| 52 |
} |
| 53 |
|