diff --git a/src/FormBuilder/BlockModels/DonationAmountBlockModel.php b/src/FormBuilder/BlockModels/DonationAmountBlockModel.php index 5f2f2500ae3..ccedac8017f 100644 --- a/src/FormBuilder/BlockModels/DonationAmountBlockModel.php +++ b/src/FormBuilder/BlockModels/DonationAmountBlockModel.php @@ -67,7 +67,13 @@ public function getLabel(): string */ public function getLevels(): array { - return $this->block->getAttribute('levels'); + return array_map(static function($level) { + return [ + 'label' => (string)filter_var($level['label'], FILTER_SANITIZE_STRING), + 'value' => (float)filter_var($level['value'], FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION), + 'checked' => (bool)filter_var($level['checked'], FILTER_VALIDATE_BOOLEAN), + ]; + }, $this->block->getAttribute('levels')); } /** diff --git a/src/FormBuilder/BlockTypes/DonationAmountBlockType.php b/src/FormBuilder/BlockTypes/DonationAmountBlockType.php index 422428ab147..78a26afa8aa 100644 --- a/src/FormBuilder/BlockTypes/DonationAmountBlockType.php +++ b/src/FormBuilder/BlockTypes/DonationAmountBlockType.php @@ -54,15 +54,20 @@ public static function name(): string ]; /** + * @unreleased Update levels array schema. * @since 3.8.0 * * @return float[] */ public function getLevels(): array { - return array_map(static function ($level) { - return (float)filter_var($level, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION); - }, $this->levels); + return array_map(static function($level) { + return [ + 'label' => (string)filter_var($level['label'], FILTER_SANITIZE_STRING), + 'value' => (float)filter_var($level['value'], FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION), + 'checked' => (bool)filter_var($level['checked'], FILTER_VALIDATE_BOOLEAN), + ]; + }, $this->block->getAttribute('levels')); } /**