calculated-field.php
4 years ago
checkbox-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
radio-field.php
4 years ago
range-field.php
4 years ago
select-field.php
4 years ago
submit-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
58 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Media field template |
| 4 | */ |
| 5 | use Jet_Form_Builder\File_Upload; |
| 6 | |
| 7 | $this->add_attribute( 'class', 'jet-form-builder__field file-field jet-form-builder-file-upload__input' ); |
| 8 | $this->add_attribute( 'class', $this->maybe_get_error_class( $args ) ); |
| 9 | $this->add_attribute( 'class', $args['class_name'] ); |
| 10 | $this->add_attribute( 'name', $this->block_type->get_field_name( $args['name'] . '_input' ) ); |
| 11 | $this->add_attribute( 'type', 'file' ); |
| 12 | $this->add_attribute( 'data-form_id', $this->form_id ); |
| 13 | $this->add_attribute( 'data-field', $args['name'] ); |
| 14 | $this->add_attribute( 'id', $this->block_type->get_field_id( $args ) ); |
| 15 | |
| 16 | if ( ! empty( $args['max_files'] ) ) { |
| 17 | $this->add_attribute( 'data-max_files', absint( $args['max_files'] ) ); |
| 18 | $this->add_attribute( 'multiple', true ); |
| 19 | } |
| 20 | |
| 21 | if ( ! empty( $args['allowed_mimes'] ) ) { |
| 22 | $this->add_attribute( 'accept', implode( ',', $args['allowed_mimes'] ) ); |
| 23 | } |
| 24 | |
| 25 | $max_size = File_Upload::instance()->get_max_size_for_field( $args ); |
| 26 | |
| 27 | $this->add_attribute( 'data-max_size', $max_size ); |
| 28 | |
| 29 | $required = $this->block_type->get_required_val( $args ); |
| 30 | |
| 31 | if ( $required ) { |
| 32 | $required = 'required="required"'; |
| 33 | } |
| 34 | |
| 35 | if ( ! empty( $args['insert_attachment'] ) ) { |
| 36 | $format = ! empty( $args['value_format'] ) ? $args['value_format'] : 'url'; |
| 37 | } else { |
| 38 | $format = 'url'; |
| 39 | } |
| 40 | |
| 41 | $value = File_Upload::instance()->get_result_value( $args ); |
| 42 | $value = is_array( $value ) || ( 'url' === $format ) ? json_encode( $value ) : $value; |
| 43 | ?> |
| 44 | <div class="jet-form-builder__field-wrap jet-form-builder-file-upload"> |
| 45 | <div class="jet-form-builder-file-upload__content"> |
| 46 | <?php echo File_Upload::instance()->get_loader(); ?> |
| 47 | <div class="jet-form-builder-file-upload__files" <?php echo File_Upload::instance()->get_files_data_args( $this->block_type->block_attrs ); ?>><?php |
| 48 | echo File_Upload::instance()->get_result_html( $args ); |
| 49 | ?></div> |
| 50 | </div> |
| 51 | <div class="jet-form-builder-file-upload__fields"> |
| 52 | <input class="jet-form-builder-file-upload__value" type="hidden" name="<?php echo $this->block_type->get_field_name( $args['name'] ); ?>" data-field-name="<?php echo $args['name']; ?>" value="<?php echo htmlspecialchars( $value ); ?>" <?php echo $required; ?>> |
| 53 | <input <?php $this->render_attributes_string(); ?>> |
| 54 | <?php echo $this->maybe_render_error( $args ); ?> |
| 55 | </div> |
| 56 | <div class="jet-form-builder-file-upload__message"><small><?php _e( 'Maximum file size', 'jet-engine' );?>: <?php echo size_format( $max_size ); ?></small></div> |
| 57 | <div class="jet-form-builder-file-upload__errors is-hidden"></div> |
| 58 | </div> |