-
Notifications
You must be signed in to change notification settings - Fork 834
Forms: Update how we store rating type #45183
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
enejb
wants to merge
13
commits into
trunk
Choose a base branch
from
update/store-rating-type
base: trunk
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
8cc24c7
Forms: Improve rating field submit output
enejb ebcba41
changelog
enejb 64ec650
Update the tests
enejb 2fc0dfd
fix typo
enejb 2f35448
Detect the new format.
enejb c6e75b9
Fix the intermiten case
enejb ba5f417
return a string
enejb 1845648
Add a legacy test
enejb 2ada587
Update projects/packages/forms/src/contact-form/class-feedback-field.php
enejb 93a05a3
Update projects/packages/forms/tests/php/contact-form/Contact_Form_Te…
enejb 0cab7d6
Improve the translation copy
enejb 9c8a703
Use SVG icons on the frontend.
enejb d927387
Update the admin
enejb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Significance: patch | ||
Type: added | ||
|
||
Forms: Improve how we store and display ratings field values |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -180,6 +180,15 @@ function ( $choice ) { | |
); | ||
} | ||
|
||
if ( $this->is_of_type( 'rating' ) ) { | ||
if ( isset( $this->meta['icon'] ) ) { // Check if the icon is set. This means that we are using the new format. | ||
$max = is_numeric( $this->meta['max'] ) && (int) $this->meta['max'] > 0 ? (int) $this->meta['max'] : 5; | ||
return sprintf( '%d/%d', $this->value, $max ); | ||
} | ||
|
||
return $this->value; | ||
} | ||
|
||
return $this->get_render_default_value(); | ||
} | ||
|
||
|
@@ -247,6 +256,36 @@ private function get_render_default_value() { | |
return $this->value; | ||
} | ||
|
||
if ( $this->is_of_type( 'rating' ) ) { | ||
if ( isset( $this->meta['icon'] ) ) { // Check if the icon is set. This means that we are using the new format. | ||
$max = is_numeric( $this->meta['max'] ) && (int) $this->meta['max'] > 0 ? (int) $this->meta['max'] : 5; | ||
$value = is_numeric( $this->value ) && (int) $this->value > 0 ? (int) $this->value : 0; | ||
|
||
if ( $value > $max ) { | ||
$value = $max; | ||
} | ||
|
||
/* translators: %1$d is the current rating, %2$d is the maximum rating, %3$s is the type of rating (stars or hearts). */ | ||
$accessibility_label = sprintf( __( '%1$d out of %2$d stars', 'jetpack-forms' ), $value, $max ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We'll need So |
||
$icon_path = '<path d="M12 17.27L18.18 21l-1.64-7.03L22 9.24l-7.19-.62L12 2 9.19 8.62 2 9.24l5.46 4.73L5.82 21z" fill="none" stroke="currentColor" stroke-width="2" stroke-linejoin="round"></path>'; | ||
if ( $this->meta['icon'] === 'hearts' ) { | ||
$icon_path = '<path d="M12 21.35l-1.45-1.32C5.4 15.36 2 12.28 2 8.5 2 5.42 4.42 3 7.5 3c1.74 0 3.41.81 4.5 2.09C13.09 3.81 14.76 3 16.5 3 19.58 3 22 5.42 22 8.5c0 3.78-3.4 6.86-8.55 11.54L12 21.35z" fill="none" stroke="currentColor" stroke-width="2" stroke-linejoin="round"></path>'; | ||
|
||
/* translators: %1$d is the current rating, %2$d is the maximum rating). */ | ||
$accessibility_label = sprintf( __( '%1$d out of %2$d hearts', 'jetpack-forms' ), $value, $max ); | ||
} | ||
|
||
$icon_svg = '<svg class="jetpack-field-rating__icon is-filled" viewBox="0 0 24 24" aria-hidden="true">' . $icon_path . '</svg>'; | ||
$empty_icon = '<svg class="jetpack-field-rating__icon is-empty" viewBox="0 0 24 24" aria-hidden="true">' . $icon_path . '</svg>'; | ||
$icons = array_fill( 0, $value, $icon_svg ); | ||
$icons = array_merge( $icons, array_fill( 0, $max - $value, $empty_icon ) ); | ||
|
||
return '<span aria-label="' . esc_attr( $accessibility_label ) . '">' . implode( '', $icons ) . '</span>'; | ||
} | ||
// Return the array as is. | ||
return $this->value; | ||
} | ||
|
||
if ( is_array( $this->value ) ) { | ||
return implode( ', ', $this->value ); | ||
} | ||
|
@@ -283,6 +322,10 @@ private function get_render_api_value() { | |
return $this->value; | ||
} | ||
|
||
if ( $this->is_of_type( 'rating' ) ) { | ||
return $this->get_render_default_value(); | ||
} | ||
|
||
if ( is_array( $this->value ) ) { | ||
// If the value is an array, we can return it as a JSON string. | ||
return implode( ', ', $this->value ); | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.