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

Enhancement: Custom FullCalendar Configuration for Widgets #130

Merged
merged 18 commits into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,31 @@ class AdminPanelProvider extends PanelProvider
}
```

```php
<?php
namespace App\Filament\Widgets;

use Saade\FilamentFullCalendar\Widgets\FullCalendarWidget;
use App\Models\Event;

class CalendarWidget extends FullCalendarWidget
{
public Model | string | null $model = Event::class;

public function config(): array
{
return [
'firstDay' => 1,
'headerToolbar' => [
'left' => 'dayGridWeek,dayGridDay',
'center' => 'title',
'right' => 'prev,next today',
],
];
}
}
```

## Available methods

### schedulerLicenseKey(`string` | `null` $licenseKey)
Expand Down
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
"spatie/laravel-ray": "^1.26"
},
"autoload": {
"files": [
"src/helpers.php"
],
"psr-4": {
"Saade\\FilamentFullCalendar\\": "src"
}
Expand Down
2 changes: 1 addition & 1 deletion resources/views/fullcalendar.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
plugins: @js($plugin->getPlugins()),
schedulerLicenseKey: @js($plugin->getSchedulerLicenseKey()),
timeZone: @js($plugin->getTimezone()),
config: @js($plugin->getConfig()),
config: @js($this->getConfig()),
editable: @json($plugin->isEditable()),
selectable: @json($plugin->isSelectable()),
})">
Expand Down
23 changes: 23 additions & 0 deletions src/Widgets/Concerns/CanBeConfigured.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace Saade\FilamentFullCalendar\Widgets\Concerns;

use function Saade\FilamentFullCalendar\array_merge_recursive_unique;

use Saade\FilamentFullCalendar\FilamentFullCalendarPlugin;

trait CanBeConfigured
{
public function config(): array
{
return [];
}

protected function getConfig(): array
{
return array_merge_recursive_unique(
FilamentFullCalendarPlugin::get()->getConfig(),
$this->config(),
);
}
}
1 change: 1 addition & 0 deletions src/Widgets/FullCalendarWidget.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class FullCalendarWidget extends Widget implements HasForms, HasActions
use Concerns\InteractsWithRecords;
use Concerns\InteractsWithHeaderActions;
use Concerns\InteractsWithModalActions;
use Concerns\CanBeConfigured;

protected static string $view = 'filament-fullcalendar::fullcalendar';

Expand Down
18 changes: 18 additions & 0 deletions src/helpers.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace Saade\FilamentFullCalendar;

if(! function_exists('Saade\FilamentFullCalendar\array_merge_recursive_unique')) {
function array_merge_recursive_unique(array $array1, array $array2): array
{
foreach ($array2 as $key => $value) {
if (is_array($value) && isset($array1[$key]) && is_array($array1[$key])) {
$array1[$key] = array_merge_recursive_unique($array1[$key], $value);
} else {
$array1[$key] = $value;
}
}

return $array1;
}
}