Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
daa737b
Forms: Adds a new Form_Responses class
enejb Jul 8, 2025
d45083f
Add tests for Form_Response::strip_tags method
enejb Jul 8, 2025
eb66d9d
Make endpoint rendering work
enejb Jul 9, 2025
caec50d
Make for submission work with the new response data
enejb Jul 9, 2025
2cbb3c5
Add test for get_render_value
enejb Jul 9, 2025
db409ae
Update has_file tests
enejb Jul 9, 2025
2316c2c
Add tests for get_render_api_value method
enejb Jul 10, 2025
85551b7
rename for clarity
enejb Jul 10, 2025
9e6927f
Simplify things
enejb Jul 10, 2025
8558fe9
Fix rendering on submit
enejb Jul 10, 2025
c1a260f
Rename Form_Response => Feedback
enejb Jul 11, 2025
2a63acf
Rename Response_Field => Feedback_Field
enejb Jul 11, 2025
b72b374
Implement CSV Export
enejb Jul 11, 2025
ac6da76
minor update test method name
enejb Jul 11, 2025
c14389e
Minor fixes
enejb Jul 11, 2025
ace74d4
Add reprecation
enejb Jul 11, 2025
2a9ff6d
Update the code coverage
enejb Jul 11, 2025
f279dbb
minor: test fixes
enejb Jul 11, 2025
9a9e2ee
Introduce Feedback_Entry class
enejb Jul 16, 2025
61435b8
split constructore up, refactor form
enejb Jul 16, 2025
f3e2124
Add Feedback_Author Class
enejb Jul 16, 2025
923ea28
Fix phan issue
enejb Jul 17, 2025
1f2b689
Add tests for Feedback_Author
enejb Jul 17, 2025
ce81573
Fix tests
enejb Jul 17, 2025
0fd15da
minor refactor
enejb Jul 17, 2025
e9673f0
Refactor legacy content parsing in Feedback class
enejb Jul 17, 2025
b612675
Refactor feedback field rendering and API output
enejb Jul 20, 2025
b66d8f9
Add context csv
enejb Jul 20, 2025
6abcaa7
Add more context
enejb Jul 20, 2025
7f53963
Fixing php phan issues
enejb Jul 20, 2025
1e414be
Improve test coverage
enejb Jul 20, 2025
fb3dc00
Fix typo in method name for author info retrieval
enejb Jul 20, 2025
9de7a06
Rename legacy feedback properties in Feedback class
enejb Jul 20, 2025
fe12680
Add more Feedback tests
enejb Jul 20, 2025
6d69cbb
Add form count test
enejb Jul 20, 2025
d4a5972
Move the test
enejb Jul 20, 2025
eafcde5
More tests and phan fixes
enejb Jul 20, 2025
8f76401
update baseline
enejb Jul 20, 2025
2e32c60
Add get_value assertions to Feedback_Field tests
enejb Jul 20, 2025
f6d2a0f
Add feedback field tests
enejb Jul 20, 2025
ef13486
remove unused method
enejb Jul 20, 2025
eac22f4
Refactor file field type handling in feedback forms
enejb Jul 20, 2025
0e7bfd1
Don't reimplement strip_tags method
enejb Jul 20, 2025
89aa584
Export personal Data update to use FeedBack Class
enejb Jul 20, 2025
e1f8381
Fix typos in docblocks
lezama Jul 22, 2025
b599db2
Making ajax work.
enejb Jul 23, 2025
d0f8da7
Add a test for label|value format
enejb Jul 23, 2025
1dc60fd
Add test for get_json_data
enejb Jul 23, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions projects/packages/forms/.phan/baseline.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
// PhanTypeMismatchArgumentInternal : 6 occurrences
// PhanTypeMismatchArgumentProbablyReal : 6 occurrences
// PhanPluginDuplicateAdjacentStatement : 2 occurrences
// PhanPluginRedundantAssignment : 2 occurrences
// PhanTypeConversionFromArray : 2 occurrences
// PhanTypeMismatchReturn : 2 occurrences
// PhanPluginMixedKeyNoKey : 1 occurrence
// PhanPluginRedundantAssignment : 1 occurrence
// PhanPossiblyNullTypeMismatchProperty : 1 occurrence
// PhanTypeArraySuspiciousNullable : 1 occurrence
// PhanTypeMismatchReturnNullable : 1 occurrence
Expand All @@ -28,7 +28,7 @@
'file_suppressions' => [
'src/contact-form/class-admin.php' => ['PhanPluginDuplicateConditionalNullCoalescing', 'PhanTypeArraySuspiciousNullable', 'PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentInternal', 'PhanTypeMismatchArgumentProbablyReal', 'PhanTypeMismatchReturn'],
'src/contact-form/class-contact-form-field.php' => ['PhanPluginDuplicateConditionalNullCoalescing', 'PhanPossiblyNullTypeMismatchProperty', 'PhanTypeConversionFromArray', 'PhanTypeMismatchArgument', 'PhanTypeMismatchReturnProbablyReal'],
'src/contact-form/class-contact-form-plugin.php' => ['PhanPluginDuplicateAdjacentStatement', 'PhanPluginDuplicateConditionalNullCoalescing', 'PhanPluginRedundantAssignment', 'PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentInternal', 'PhanTypeMismatchArgumentProbablyReal', 'PhanTypeMismatchReturnProbablyReal'],
'src/contact-form/class-contact-form-plugin.php' => ['PhanPluginDuplicateAdjacentStatement', 'PhanPluginDuplicateConditionalNullCoalescing', 'PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentInternal', 'PhanTypeMismatchArgumentProbablyReal', 'PhanTypeMismatchReturnProbablyReal'],
'src/contact-form/class-contact-form-shortcode.php' => ['PhanPluginDuplicateConditionalNullCoalescing', 'PhanTypeMismatchReturnProbablyReal'],
'src/contact-form/class-contact-form.php' => ['PhanPluginDuplicateConditionalNullCoalescing', 'PhanPluginRedundantAssignment', 'PhanTypeMismatchArgument', 'PhanTypeMismatchReturnNullable', 'PhanTypeMismatchReturnProbablyReal'],
'src/dashboard/class-dashboard-view-switch.php' => ['PhanUnreferencedUseNormal'],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: fixed

Forms: Adds a new Feedback and Feedback_Field class that keeps consistency between DB form response and the one before we submit it.

Original file line number Diff line number Diff line change
Expand Up @@ -530,100 +530,48 @@ public function prepare_item_for_response( $item, $request ) {
$data = $response->get_data();
$fields = $this->get_fields_for_response( $request );

$has_file = false;
$base_fields = array(
'email_marketing_consent' => '',
'entry_title' => '',
'entry_permalink' => '',
'feedback_id' => '',
);

$data_defaults = array(
'_feedback_author' => '',
'_feedback_author_email' => '',
'_feedback_author_url' => '',
'_feedback_all_fields' => array(),
'_feedback_ip' => '',
'_feedback_subject' => '',
);

$feedback_data = array_merge(
$data_defaults,
\Automattic\Jetpack\Forms\ContactForm\Contact_Form_Plugin::parse_fields_from_content( $item->ID )
);

$all_fields = array_merge( $base_fields, $feedback_data['_feedback_all_fields'] );
$response = Feedback::get( $item->ID );

$data['date'] = get_the_date( 'c', $data['id'] );
if ( rest_is_field_included( 'uid', $fields ) ) {
$data['uid'] = $all_fields['feedback_id'];
$data['uid'] = $response->get_feedback_id();
}
if ( rest_is_field_included( 'author_name', $fields ) ) {
$data['author_name'] = $feedback_data['_feedback_author'];
$data['author_name'] = $response->get_author();
}
if ( rest_is_field_included( 'author_email', $fields ) ) {
$data['author_email'] = $feedback_data['_feedback_author_email'];
$data['author_email'] = $response->get_author_email();
}
if ( rest_is_field_included( 'author_url', $fields ) ) {
$data['author_url'] = $feedback_data['_feedback_author_url'];
$data['author_url'] = $response->get_author_url();
}
if ( rest_is_field_included( 'author_avatar', $fields ) ) {
$data['author_avatar'] = empty( $feedback_data['_feedback_author_email'] ) ? '' : get_avatar_url( $feedback_data['_feedback_author_email'] );
$data['author_avatar'] = $response->get_author_avatar();
}
if ( rest_is_field_included( 'email_marketing_consent', $fields ) ) {
$data['email_marketing_consent'] = $all_fields['email_marketing_consent'];
$data['email_marketing_consent'] = $response->has_consent() ? __( 'Yes', 'jetpack-forms' ) : __( 'No', 'jetpack-forms' );
}
if ( rest_is_field_included( 'ip', $fields ) ) {
$data['ip'] = $feedback_data['_feedback_ip'];
$data['ip'] = $response->get_ip_address();
}
if ( rest_is_field_included( 'entry_title', $fields ) ) {
$data['entry_title'] = $all_fields['entry_title'];
$data['entry_title'] = $response->get_entry_title();
}
if ( rest_is_field_included( 'entry_permalink', $fields ) ) {
$data['entry_permalink'] = $all_fields['entry_permalink'];
$data['entry_permalink'] = $response->get_entry_permalink();
}
if ( rest_is_field_included( 'subject', $fields ) ) {
$data['subject'] = $feedback_data['_feedback_subject'];
$data['subject'] = $response->get_subject();
}
if ( rest_is_field_included( 'fields', $fields ) ) {
$fields_data = array_diff_key( $all_fields, $base_fields );

foreach ( $fields_data as &$field ) {
if ( Contact_Form::is_file_upload_field( $field ) ) {

foreach ( $field['files'] as &$file ) {
if ( ! isset( $file['size'] ) || ! isset( $file['file_id'] ) ) {
// this shouldn't happen, todo: log this
continue;
}
$file_id = absint( $file['file_id'] );
$file['file_id'] = $file_id;
$file['size'] = size_format( $file['size'] );
$file['url'] = apply_filters( 'jetpack_unauth_file_download_url', '', $file_id );
$file['is_previewable'] = self::is_previewable_file( $file );
$has_file = true;
}
}
}
$data['fields'] = $response->get_compiled_fields( 'api', 'key-value' );
}

$data['fields'] = $fields_data;
$data['has_file'] = $has_file;
if ( rest_is_field_included( 'has_file', $fields ) ) {
$data['has_file'] = $response->has_file();
}
return rest_ensure_response( $data );
}
/**
* Checks if the file is previewable based on its type or extension.
*
* @param array $file File data.
* @return bool True if the file is previewable, false otherwise.
*/
private static function is_previewable_file( $file ) {
$file_type = strtolower( pathinfo( $file['name'], PATHINFO_EXTENSION ) );
// Check if the file is previewable based on its type or extension.
// Note: This is a simplified check and does not match if the file is allowed to be uploaded by the server.
$previewable_types = array( 'jpg', 'jpeg', 'png', 'gif', 'webp' );
return in_array( $file_type, $previewable_types, true );
}

/**
* Retrieves the query params for the feedback collection.
Expand Down
Loading
Loading