-
Notifications
You must be signed in to change notification settings - Fork 63
Add the validation filter to block_sub_field() #419
Conversation
This is how each control's validate() function is called. For example, for the Image control, Image::validate() outputs a different value if $echo is true (the URL), vs when it's fale (the ID).
This fixed the issue locally, but I should test it more. |
Though this doesn't test default values, this tests a repeater with every possible control as a sub_field.
There was a typo in a DocBlock, where 'name' was spelled 'nam e'.
Request For Review Hi @lukecarbis, Could you please review this when you have a chance? Thanks, Luke! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Australia misses you too!
This PR looks great. Here's the template I used to test:
if ( block_rows( 'repeater' ) ) {
while ( block_rows( 'repeater' ) ) {
block_row( 'repeater' );
?>
<p><?php echo block_sub_value( 'background' ); ?></p>
<p><?php block_sub_field( 'background' ); ?></p>
<?php
}
}
reset_block_rows( 'repeater' );
Here's the result of that on develop
(notice an unexpected value from block_sub_field
):
Here's the result of the same template on this branch (with the correct value for block_sub_field
):
@@ -72,6 +72,7 @@ public function register_hooks() { | |||
add_action( 'wp_insert_post_data', array( $this, 'save_block' ), 10, 2 ); | |||
add_action( 'init', array( $this, 'register_controls' ) ); | |||
add_filter( 'block_lab_field_value', array( $this, 'get_field_value' ), 10, 3 ); | |||
add_filter( 'block_lab_sub_field_value', array( $this, 'get_field_value' ), 10, 3 ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great pickup!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Test all 13 fields that can have defaults, though this doesn't include the repeater, as it can't have a default. @todo: create a test file for the repeater field's defaults.
Hi @lukecarbis, Thanks a lot for testing this, also. If it's alright, I just pushed 7e7af7d, which adds an integration test for default values (but not yet for the repeater). It only touches files in |
7e7af7d looks good! Feel free to merge. |
Thanks, @lukecarbis! |
block_field()
validate()
function is called when callingblock_sub_field()
orblock_field()
$echo
is true (the URL), versus when it's false (the ID).Closes #418
Partially fulfills #404 (Add an integration test for the repeater)