statamic / ideas

đŸ’¡Discussions on ideas and feature requests for Statamic
https://statamic.dev
32 stars 1 forks source link

Custom rules will be ignored in Blueprint #427

Open jonassiewertsen opened 4 years ago

jonassiewertsen commented 4 years ago

In addon context, I am creating a blueprint on the fly. This might look something like this:

use Statamic\Facades\Blueprint as StatamicBlueprint;

class VariantBlueprint extends Blueprint
{
    public function __invoke()
    {
        return StatamicBlueprint::make()->setContents([
            'sections' => [
                'main' => [
                    'fields' => [
                        [
                            'handle' => 'price',
                            'field'  => [
                                'type'     => 'integer',
                                'display'  => 'Price',
                                'validate' => [ new VariantPriceRule ],
                            ],
                         ....

It seems that the rule won't be recognized at all by the blueprint and therefore not taking any effect.

My custom rule will always pass, even when explicit returning false.

Environment

Statamic version: 3.0.0.-beta-33

PHP version: 7.4

Install method (choose one):

duncanmcclean commented 4 years ago

What about if you use a string for your validation rules, instead of passing it in an array.

jonassiewertsen commented 4 years ago

This should be the appropriate way to register the rule, otherwise Statamic does not know where to find the rule.

github-actions[bot] commented 3 years ago

This issue has not had recent activity and has been marked as stale — by me, a robot. Simply reply to keep it open and send me away. If you do nothing, I will close it in a week. I have no feelings, so whatever you do is fine by me.

jonassiewertsen commented 3 years ago

This should still be an issue.

jasonvarga commented 3 years ago

This is more of a feature request.

Right now, a blueprint needs to be representable in YAML. You can't plop a PHP class based validation rule in YAML.

I'll move the to ideas repo.