Skip to content

Commit

Permalink
Create InteractsWithConfig.php
Browse files Browse the repository at this point in the history
  • Loading branch information
sitenzo authored Nov 22, 2023
1 parent 7d37ecc commit 536cf81
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/Widgets/Concerns/InteractsWithConfig.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace Saade\FilamentFullCalendar\Widgets\Concerns;

use Saade\FilamentFullCalendar\FilamentFullCalendarPlugin;

trait InteractsWithConfig
{
public function getFinalConfig()
{
$initConfig = FilamentFullCalendarPlugin::get()->getConfig();
$widgetConfig = $this->getConfig();
return self::mergeArraysRecursive($initConfig,$widgetConfig);
}

private static function mergeArraysRecursive($initial, $custom) {
foreach ($custom as $key => $value) {
if (is_array($value) && isset($initial[$key]) && is_array($initial[$key])) {
// If both are arrays, recursively merge them
$initial[$key] = mergeArraysRecursive($initial[$key], $value);
} else {
// Otherwise, overwrite the value
$initial[$key] = $value;
}
}
return $initial;
}


protected function getConfig(): array
{
return [];
}
}

0 comments on commit 536cf81

Please sign in to comment.