Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: getCustomSchema will make problem for all of fields #316

Closed
mrhappyheart opened this issue Jul 9, 2024 · 6 comments
Closed

[Bug]: getCustomSchema will make problem for all of fields #316

mrhappyheart opened this issue Jul 9, 2024 · 6 comments
Labels
bug Something isn't working

Comments

@mrhappyheart
Copy link

What happened?

Filament\Forms\ComponentContainer::Filament\Forms\Concerns{closure}(): Argument #1 ($component) must be of type Filament\Forms\Components\Component, array given {"userId":4,"exception":"[object] (TypeError(code: 0): Filament\Forms\ComponentContainer::Filament\Forms\Concerns\{closure}(): Argument #1 ($component) must be of type Filament\Forms\Components\Component, null given at /home/yallaxom/public_html/vendor/filament/forms/src/Concerns/HasComponents.php:122)

How to reproduce the bug

in most of the fields this line makss problem in codes:
Bolt::getCustomSchema('field', resolve(static::class)) ?? []

example in FileUpload.php (vendor\lara-zeus\bolt\src\Fields\Classes\FileUpload.php)

public static function getOptions(?array $sections = null): array
    {
        return [
            Accordions::make('check-list-options')
                ->accordions([
                    Accordion::make('general-options')
                        ->label(__('General Options'))
                        ->icon('iconpark-checklist-o')
                        ->schema([
                            \Filament\Forms\Components\Toggle::make('options.allow_multiple')->label(__('Allow Multiple')),
                            self::required(),
                            self::columnSpanFull(),
                            self::htmlID(),
                        ]),
                    self::hintOptions(),
                    self::visibility($sections),
                    Bolt::getCustomSchema('field', resolve(static::class)) ?? [],
                ]),
        ];
    }

error :
Filament\Forms\ComponentContainer::Filament\Forms\Concerns\{closure}(): Argument #1 ($component) must be of type Filament\Forms\Components\Component, null given {"userId":4,"exception":"[object] (TypeError(code: 0): Filament\\Forms\\ComponentContainer::Filament\\Forms\\Concerns\\{closure}(): Argument #1 ($component) must be of type Filament\\Forms\\Components\\Component, null given at /home/yallaxom/public_html/vendor/filament/forms/src/Concerns/HasComponents.php:122)

when you remove the line the problem will be solved

Package Version

3.0.59

PHP Version

8.2.*

Laravel Version

11

Which operating systems does with happen with?

No response

Notes

No response

@mrhappyheart mrhappyheart added the bug Something isn't working label Jul 9, 2024
@mrhappyheart
Copy link
Author

mrhappyheart commented Jul 9, 2024

dirty solution :
edit all the files and use this structure :

    public static function getOptions(?array $sections = null): array
    {
        $options = [
            Accordion::make('general-options')
                        ->label(__('General Options'))
                        ->icon('iconpark-checklist-o')
                        ->schema([
                            \Filament\Forms\Components\Toggle::make('options.allow_multiple')->label(__('Allow Multiple')),
                            self::required(),
                            self::columnSpanFull(),
                            self::htmlID(),
                        ]),
                    self::hintOptions(),
            self::visibility($sections),
        ];
        if($ins = Bolt::getCustomSchema('field', resolve(static::class))) {
            $options[] = $ins;
        }
        return [
            Accordions::make('check-list-options')
                ->accordions([
                    ...$options,
                ]),
        ];
    }

standard solution :
adding "..." to first of line

public static function getOptions(?array $sections = null): array
    {
        return [
            Accordions::make('check-list-options')
                ->accordions([
                    Accordion::make('general-options')
                        ->label(__('General Options'))
                        ->icon('iconpark-checklist-o')
                        ->schema([
                            \Filament\Forms\Components\Toggle::make('options.allow_multiple')->label(__('Allow Multiple')),
                            self::required(),
                            self::columnSpanFull(),
                            self::htmlID(),
                        ]),
                    self::hintOptions(),
                    self::visibility($sections),
                    ...Bolt::getCustomSchema('field', resolve(static::class)) ?? [],
                ]),
        ];
}

@atmonshi
Copy link
Member

atmonshi commented Jul 9, 2024

this looks similar to #294.
can you make sure you have the last version of bolt and accordion packages

you can run php artisan about --only=zeus

@mrhappyheart
Copy link
Author

yes it's latest
even on github you can find the problem like :
https://github.com/lara-zeus/bolt/blob/3.x/src/Fields/Classes/CheckboxList.php

and output:

 accordion ................................................................................................ 1.1.3  
  bolt ................................................................................................... v3.0.60
  bolt-pro ................................................................................................ v3.2.1  
  core .................................................................................................... v3.1.9  
  matrix-choice ........................................................................................... v3.2.1  
  sky ..................................................................................................... v3.4.9

@atmonshi
Copy link
Member

atmonshi commented Jul 9, 2024

I cant reproduce the issue, the demo is working fine :)

I test it with/without Bolt pro
I test it with/without Grades
I test it with/without Custom Schema

try update bolt pro:
bolt-pro ................... v3.2.1 => v3.2.12

and as I explained about the ...:

I need the 3 dots here:
...Bolt::hasPro() ? \LaraZeus\BoltPro\Facades\GradeOptions::schema($field) : [],

coz the GradeOptions::schema will return array so I need the ... to append it to the accordions array and it will filtered in the accordions method.

I dont need the dots here:
Bolt::getCustomSchema('field', resolve(static::class)) ?? [],

coz the getCustomSchema will return Accordion::make so adding ... will break if you use Custom Schema, otherwise it will return empty array and will be filtered in the accordions method

@mrhappyheart
Copy link
Author

i think the problem is coming from Facede / Bolt file:

public static function getCustomSchema(string $hook, ?FieldsContract $field = null): Tab | Accordion | null
    {
        $class = BoltPlugin::getSchema($hook);
        if ($class !== null) {
            $getClass = new $class;
            if ($hook === 'form' && $getClass instanceof CustomFormSchema) {
                return $getClass->make();
            }

            if ($getClass instanceof CustomSchema) {
                return $getClass->make($field);
            }
        }

        return null;
    }

it returns null for me

@atmonshi
Copy link
Member

atmonshi commented Sep 1, 2024

tested on new app and 'zeus` starter kit and the demo app
I test it with/without Bolt pro
I test it with/without Grades
I test it with/without Custom Schema

feel free to reopen with a reproduction repository.
thank you

@atmonshi atmonshi closed this as completed Sep 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants