Skip to content

Commit

Permalink
Add more config
Browse files Browse the repository at this point in the history
  • Loading branch information
cklei-carly committed Aug 13, 2024
1 parent b1af69a commit 579082c
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 10 deletions.
34 changes: 28 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,26 @@ return [

## Usage

1. Enable the Field Group resource by setting `enabled` to `true` in the config file:
1. Add `FilamentFieldGroupPlugin` to you panel.
2. Enable the Field Group resource by setting `enabled` to `true` in the config file:
```php

// config/filament-field-group.php
return [
'enabled' => true,
// ... other config options
'enabled' => true,
// ... other config options
];
```
Or enable the plugin on `FilamentFieldGroupPlugin`
```php
use SolutionForest\FilamentFieldGroup\FilamentFieldGroupPlugin;

$panel
->plugin(FilamentFieldGroupPlugin::make()->enablePlugin());
```
![Filament Field Group](./docs-assets/images/initial-resource.png)

2. Create field groups and fields, for example:
3. Create field groups and fields, for example:

- Navigate to the Field Group resource in your Filament admin panel.
- Create a new field group (e.g., "User Basic Info").
Expand All @@ -83,7 +91,7 @@ return [
![Create Field Group and Field](./docs-assets/images/add-field-2.png)
![Create Field Group and Field](./docs-assets/images/add-field-3.png)

3. Apply field groups to your form schema:
4. Apply field groups to your form schema:
```php

use SolutionForest\FilamentFieldGroup\Facades\FilamentFieldGroup;
Expand All @@ -99,7 +107,7 @@ public static function form(Form $form): Form
}
```
![Apply Field Group](./docs-assets/images/apply-field-group.png)

## Available Components

Currently, this package provides the following components:
Expand All @@ -114,6 +122,20 @@ Currently, this package provides the following components:

More components can be added in the future. Feel free to submit a pull request if you have ideas for additional components!


## Advanced Usage
### Custom Resources
You can call `overrideResources` on `FilamentFieldGroupPlugin` to replace original resource:
```php

use SolutionForest\FilamentFieldGroup\FilamentFieldGroupPlugin;

$panel
->plugin(FilamentFieldGroupPlugin::make()->overrideResources([
// your resource
]));
```

## Testing

```bash
Expand Down
24 changes: 20 additions & 4 deletions src/FilamentFieldGroupPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

class FilamentFieldGroupPlugin implements Plugin
{
protected ?array $overrideResources = null;
protected bool $enablePlugin = false;

public function getId(): string
{
return 'filament-field-group';
Expand All @@ -16,10 +19,9 @@ public function getId(): string
public function register(Panel $panel): void
{
// Register the FieldGroup resource
if (config('filament-field-group.enabled', false)) {
$panel->resources([
FieldGroupResource::class,
]);
if (config('filament-field-group.enabled', false) || $this->enablePlugin) {
$resources = $this->overrideResources ?? [FieldGroupResource::class];
$panel->resources($resources);
}
}

Expand All @@ -39,4 +41,18 @@ public static function get(): static

return $plugin;
}

public function overrideResources(array $resources): static
{
$this->overrideResources = $resources;

return $this;
}

public function enablePlugin(bool $enable = true): static
{
$this->enablePlugin = $enable;

return $this;
}
}

0 comments on commit 579082c

Please sign in to comment.