action-button.php
4 years ago
calculated-field.php
4 years ago
checkbox-field.php
4 years ago
color-picker-field.php
4 years ago
date-field.php
4 years ago
datetime-field.php
4 years ago
form-break-field.php
4 years ago
group-break-field.php
4 years ago
heading-field.php
4 years ago
hidden-field.php
4 years ago
media-field.php
4 years ago
number-field.php
4 years ago
progress-bar.php
4 years ago
radio-field.php
4 years ago
range-field.php
4 years ago
select-field.php
4 years ago
text-field.php
4 years ago
textarea-field.php
4 years ago
time-field.php
4 years ago
wysiwyg-field.php
4 years ago
media-field.php
71 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Media field template |
| 4 | */ |
| 5 | |
| 6 | use Jet_Form_Builder\File_Upload; |
| 7 | use Jet_Form_Builder\Classes\Tools; |
| 8 | |
| 9 | $this->add_attribute( 'class', 'jet-form-builder__field file-field jet-form-builder-file-upload__input' ); |
| 10 | $this->add_attribute( 'class', $this->maybe_get_error_class( $args ) ); |
| 11 | $this->add_attribute( 'class', $args['class_name'] ); |
| 12 | $this->add_attribute( 'name', $this->block_type->get_field_name( $args['name'] . '_input' ) ); |
| 13 | $this->add_attribute( 'type', 'file' ); |
| 14 | $this->add_attribute( 'data-form_id', $this->form_id ); |
| 15 | $this->add_attribute( 'data-field', $args['name'] ); |
| 16 | $this->add_attribute( 'id', $this->block_type->get_field_id( $args ) ); |
| 17 | |
| 18 | if ( ! empty( $args['max_files'] ) ) { |
| 19 | $this->add_attribute( 'data-max_files', absint( $args['max_files'] ) ); |
| 20 | $this->add_attribute( 'multiple', true ); |
| 21 | } |
| 22 | |
| 23 | if ( ! empty( $args['allowed_mimes'] ) ) { |
| 24 | $this->add_attribute( 'accept', implode( ',', $args['allowed_mimes'] ) ); |
| 25 | } |
| 26 | |
| 27 | $max_size = File_Upload::instance()->get_max_size_for_field( $args ); |
| 28 | |
| 29 | $this->add_attribute( 'data-max_size', $max_size ); |
| 30 | |
| 31 | $required = $this->block_type->get_required_val( $args ); |
| 32 | |
| 33 | if ( ! empty( $args['insert_attachment'] ) ) { |
| 34 | $format = ! empty( $args['value_format'] ) ? $args['value_format'] : 'url'; |
| 35 | } else { |
| 36 | $format = 'url'; |
| 37 | } |
| 38 | |
| 39 | $value = File_Upload::instance()->get_result_value( $args ); |
| 40 | $value = is_array( $value ) || ( 'url' === $format ) ? wp_json_encode( $value ) : $value; |
| 41 | // phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped |
| 42 | ?> |
| 43 | <div class="jet-form-builder__field-wrap jet-form-builder-file-upload"> |
| 44 | <div class="jet-form-builder-file-upload__content"> |
| 45 | <?php echo File_Upload::instance()->get_loader(); ?> |
| 46 | <div class="jet-form-builder-file-upload__files" <?php echo File_Upload::instance()->get_files_data_args( $this->block_type->block_attrs ); ?>> |
| 47 | <?php |
| 48 | echo File_Upload::instance()->get_result_html( $args ); |
| 49 | ?> |
| 50 | </div> |
| 51 | </div> |
| 52 | <div class="jet-form-builder-file-upload__fields"> |
| 53 | <input class="jet-form-builder-file-upload__value" |
| 54 | type="hidden" |
| 55 | name="<?php echo esc_attr( $this->block_type->get_field_name( $args['name'] ) ); ?>" |
| 56 | data-field-name="<?php echo esc_attr( $args['name'] ); ?>" |
| 57 | value="<?php echo htmlspecialchars( $value ); ?>" |
| 58 | <?php |
| 59 | if ( $required ) { |
| 60 | echo ' required="required"'; |
| 61 | } |
| 62 | ?> |
| 63 | > |
| 64 | <input <?php $this->render_attributes_string(); ?>> |
| 65 | <?php echo Tools::esc_template_string( $this->maybe_render_error( $args ) ); ?> |
| 66 | </div> |
| 67 | <div class="jet-form-builder-file-upload__message"><small><?php echo __( 'Maximum file size', 'jet-form-builder' ); ?>: <?php echo size_format( $max_size ); ?></small></div> |
| 68 | <div class="jet-form-builder-file-upload__errors is-hidden"></div> |
| 69 | </div> |
| 70 | <?php // phpcs:enable WordPress.Security.EscapeOutput.OutputNotEscaped ?> |
| 71 |