Skip to content

Commit

Permalink
Forms: Add File Upload Field Skeleton (Experimental) (#41582)
Browse files Browse the repository at this point in the history
---------

Co-authored-by: Enej Bajgoric <[email protected]>

Committed via a GitHub action: https://github.com/Automattic/jetpack/actions/runs/13167345830

Upstream-Ref: Automattic/jetpack@c89a414
  • Loading branch information
lezama authored and matticbot committed Feb 5, 2025
1 parent c96e31e commit b923e5b
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
This is an alpha version! The changes listed here are not final.

### Added
- Forms: Add a new file upload field block to allow visitors to upload files through contact forms.
- Forms: Update fields and button blocks to support contentOnly editing.

### Changed
Expand Down
2 changes: 1 addition & 1 deletion dist/blocks/editor.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array('jetpack-connection', 'lodash', 'react', 'react-jsx-runtime', 'wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-core-data', 'wp-data', 'wp-editor', 'wp-element', 'wp-hooks', 'wp-i18n', 'wp-plugins', 'wp-polyfill', 'wp-primitives', 'wp-url'), 'version' => 'd1729909353bc2f6b840');
<?php return array('dependencies' => array('jetpack-connection', 'lodash', 'react', 'react-jsx-runtime', 'wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-core-data', 'wp-data', 'wp-editor', 'wp-element', 'wp-hooks', 'wp-i18n', 'wp-plugins', 'wp-polyfill', 'wp-primitives', 'wp-url'), 'version' => 'f486b0ffe90615fe0c10');
8 changes: 4 additions & 4 deletions dist/blocks/editor.js

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions src/blocks/contact-form/class-contact-form-block.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,23 @@ public static function register_child_blocks() {
'render_callback' => array( Contact_Form_Plugin::class, 'gutenblock_render_field_consent' ),
)
);

$blocks_variation = apply_filters( 'jetpack_blocks_variation', \Automattic\Jetpack\Constants::get_constant( 'JETPACK_BLOCKS_VARIATION' ) );
if ( 'experimental' === $blocks_variation ) {
self::register_experimental_blocks();
}
}

/**
* Register experimental blocks
*/
private static function register_experimental_blocks() {
Blocks::jetpack_register_block(
'jetpack/field-file',
array(
'render_callback' => array( Contact_Form_Plugin::class, 'gutenblock_render_field_file' ),
)
);
}

/**
Expand Down
13 changes: 13 additions & 0 deletions src/contact-form/class-contact-form-plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,19 @@ public static function gutenblock_render_field_consent( $atts, $content ) {
return Contact_Form::parse_contact_field( $atts, $content );
}

/**
* Render the file upload field.
*
* @param array $atts - the block attributes.
* @param string $content - html content.
*
* @return string HTML for the file upload field.
*/
public static function gutenblock_render_field_file( $atts, $content ) {
$atts = self::block_attributes_to_shortcode_attributes( $atts, 'file' );
return Contact_Form::parse_contact_field( $atts, $content );
}

/**
* Add the 'Form Responses' menu item as a submenu of Feedback.
*/
Expand Down

0 comments on commit b923e5b

Please sign in to comment.