Skip to content
This repository has been archived by the owner on Sep 4, 2024. It is now read-only.

Commit

Permalink
Merge pull request #1 from martin-ro/dev
Browse files Browse the repository at this point in the history
Adds plugin configuration
  • Loading branch information
martin-ro authored Jul 31, 2023
2 parents 522dba8 + 2681073 commit eada8d2
Showing 1 changed file with 70 additions and 0 deletions.
70 changes: 70 additions & 0 deletions src/FilamentPageBlockPlugin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php

namespace MartinRo\FilamentPageBlocks;

use Closure;
use Filament\Contracts\Plugin;
use Filament\Panel;
use Filament\Support\Concerns\EvaluatesClosures;
use MartinRo\FilamentPageBlocks\Forms\Components\PageBuilder;

class FilamentPageBlockPlugin implements Plugin
{
use EvaluatesClosures;

protected bool|Closure|null $shouldBeCollapsible = null;

protected bool|Closure|null $shouldBeCollapsed = null;

public function getId(): string
{
return 'filament-page-blocks';
}

public function register(Panel $panel): void
{
//
}

public function boot(Panel $panel): void
{
PageBuilder::configureUsing(function (PageBuilder $builder) {
$builder->collapsible($this->shouldBeCollapsible())
->collapsed($this->shouldBeCollapsed());
});
}

public static function make(): static
{
return app(static::class);
}

public static function get(): static
{
return filament(app(static::class)->getId());
}

public function shouldBeCollapsible(): bool
{
return $this->evaluate($this->shouldBeCollapsible) ?? false;
}

public function collapsible(bool|Closure|null $condition = false): static
{
$this->shouldBeCollapsible = $condition;

return $this;
}

public function shouldBeCollapsed(): bool
{
return $this->evaluate($this->shouldBeCollapsed) ?? false;
}

public function collapsed(bool|Closure|null $condition = false): static
{
$this->shouldBeCollapsed = $condition;

return $this;
}
}

0 comments on commit eada8d2

Please sign in to comment.