-
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Feat: Refactor FormField registration (#273) * feat!: refactor form field settings to use interfaces * feat!: refactor form field choice and inputs to use interfaces * chore: cleanup * chore: rename types * chore: cleanup filters * docs: add new actions/filters * chore: update composer deps * fix: remove duplicate $ignored_field values. * fix: use the correct GF_Field for child types with their own classes * chore: order value methods alphabetically * feat: graduate product Field (query) * feat: gradiuate `option`, `price`, `quantity`, `shipping`, and `total` fields (query * fix: set fallback product quantity to 1 * fix: change quantity GraphQL type to float * chore: fix composer deps post rebase * feat: add Product mutation support * feat: add price and formattedPrice to QuantitySelectFieldChoice * tests: quantity field tests * fix: docblock headers * test: reset $_gf_state by setting to empty array * fix: option choice type name should resolve to OptionFieldChoice * test: option field tests * test: shipping field tests * fix: use updated entry when preparing values for save * feat: add support for total field * test: lint
- Loading branch information
1 parent
1888be8
commit fe69948
Showing
53 changed files
with
6,375 additions
and
240 deletions.
There are no files selected for viewing
This file contains 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 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,106 @@ | ||
<?php | ||
/** | ||
* Manipulates input data for Product field values. | ||
* | ||
* @package WPGraphQL\GF\Data\FieldValueInput | ||
* @since @todo | ||
*/ | ||
|
||
namespace WPGraphQL\GF\Data\FieldValueInput; | ||
|
||
use GFCommon; | ||
use GraphQL\Error\UserError; | ||
|
||
/** | ||
* Class - ProductValueInput | ||
*/ | ||
class ProductValueInput extends AbstractFieldValueInput { | ||
/** | ||
* {@inheritDoc} | ||
* | ||
* @var array | ||
*/ | ||
protected $args; | ||
|
||
/** | ||
* {@inheritDoc} | ||
* | ||
* @var array | ||
*/ | ||
public $value; | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
protected function get_field_name() : string { | ||
return 'productValues'; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
* | ||
* @throws UserError . | ||
*/ | ||
protected function is_valid_input_type() : bool { | ||
$is_valid = false; | ||
|
||
// Calculation fields need a quantity and price. | ||
if ( 'calculation' === $this->field->get_input_type() && ( ! isset( $this->input_args[ $this->field_name ]['quantity'] ) || ! isset( $this->input_args[ $this->field_name ]['price'] ) ) ) { | ||
return $is_valid; | ||
} | ||
|
||
// Fields using `productValues` need a quantity. | ||
if ( isset( $this->input_args[ $this->field_name ] ) && isset( $this->input_args[ $this->field_name ]['quantity'] ) ) { | ||
return true; | ||
} | ||
|
||
// Fields using `value` must use it as the quantity. | ||
if ( isset( $this->input_args['value'] ) ) { | ||
if ( ! floatval( $this->input_args['value'] ) ) { | ||
throw new UserError( | ||
sprintf( | ||
// translators: field ID, input key. | ||
__( 'Mutation not processed. Field %1$s requires the use of `%2$s` as a valid quantity.', 'wp-graphql-gravity-forms' ), | ||
$this->field->id, | ||
'value', | ||
) | ||
); | ||
} | ||
return true; | ||
} | ||
|
||
return $is_valid; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
* | ||
* @return array | ||
*/ | ||
public function get_args() { | ||
return $this->input_args[ $this->field_name ] ?? [ | ||
'quantity' => $this->input_args['value'], | ||
'price' => null, | ||
]; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
protected function prepare_value() { | ||
$field = $this->field; | ||
|
||
return [ | ||
(string) $field->inputs[0]['id'] => $field->label, | ||
(string) $field->inputs[1]['id'] => ! empty( $this->args['price'] ) ? GFCommon::format_number( $this->args['price'], 'currency' ) : $field->basePrice, | ||
(string) $field->inputs[2]['id'] => floatval( $this->args['quantity'] ), | ||
]; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function add_value_to_submission( array &$field_values ) : void { | ||
$field_values += $this->value; | ||
} | ||
} |
This file contains 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 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 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 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 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 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 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 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,45 @@ | ||
<?php | ||
/** | ||
* GraphQL Input Type - ProductFieldInput | ||
* Input fields for a product. | ||
* | ||
* @package WPGraphQL\GF\Type\Input | ||
* @since 0.5.0 | ||
*/ | ||
|
||
namespace WPGraphQL\GF\Type\Input; | ||
|
||
/** | ||
* Class - ProductFieldInput | ||
*/ | ||
class ProductFieldInput extends AbstractInput { | ||
/** | ||
* Type registered in WPGraphQL. | ||
* | ||
* @var string | ||
*/ | ||
public static string $type = 'ProductFieldInput'; | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public static function get_description() : string { | ||
return __( 'Input fields for Product field.', 'wp-graphql-gravity-forms' ); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public static function get_fields() : array { | ||
return [ | ||
'quantity' => [ | ||
'type' => 'Float', | ||
'description' => __( 'Product quantity.', 'wp-graphql-gravity-forms' ), | ||
], | ||
'price' => [ | ||
'type' => 'Float', | ||
'description' => __( 'Product price.', 'wp-graphql-gravity-forms' ), | ||
], | ||
]; | ||
} | ||
} |
This file contains 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.