Skip to content
This repository has been archived by the owner on Nov 6, 2022. It is now read-only.

Add the validation filter to block_sub_field() #419

Merged
merged 4 commits into from
Sep 9, 2019

Conversation

kienstra
Copy link
Collaborator

@kienstra kienstra commented Sep 4, 2019

  • Adds an integration test for the repeater, with 2 rows of all possible controls.
  • Though it doesn't test default values yet.
  • Adds a filter similar to the one for block_field()
  • That filter is how each control's validate() function is called when calling block_sub_field() or block_field()
  • For example, for the Image control, Image::validate() outputs a different value if $echo is true (the URL), versus when it's false (the ID).

Closes #418
Partially fulfills #404 (Add an integration test for the repeater)

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).
@kienstra
Copy link
Collaborator Author

kienstra commented Sep 4, 2019

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'.
@kienstra
Copy link
Collaborator Author

kienstra commented Sep 8, 2019

Request For Review

Hi @lukecarbis,
Hope you're doing great, I kind of miss Australia 😄

Could you please review this when you have a chance? Thanks, Luke!

Copy link
Member

@lukecarbis lukecarbis left a 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):
Screen Shot 2019-09-09 at 7 39 44 am

Here's the result of the same template on this branch (with the correct value for block_sub_field):
Screen Shot 2019-09-09 at 7 40 20 am

@@ -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 );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great pickup!

Copy link
Collaborator Author

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.
@kienstra
Copy link
Collaborator Author

kienstra commented Sep 8, 2019

Hi @lukecarbis,
Haha, thanks.

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 tests/php/

@lukecarbis
Copy link
Member

7e7af7d looks good! Feel free to merge.

@kienstra
Copy link
Collaborator Author

kienstra commented Sep 9, 2019

Thanks, @lukecarbis!

@kienstra kienstra merged commit cf49ebf into develop Sep 9, 2019
@kienstra kienstra deleted the add/validation-repeater-row branch September 9, 2019 03:06
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

block_sub_field returns image ID instead of URL
2 participants