-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix getExtraFieldWrapperAttributes missing
- Loading branch information
Showing
2 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
namespace Guava\FilamentClusters\Forms\Concerns; | ||
|
||
use Closure; | ||
use Illuminate\View\ComponentAttributeBag; | ||
|
||
/** | ||
* Class copied from from here: | ||
* https://github.com/filamentphp/filament/blob/v3.2.80/packages/forms/src/Components/Concerns/HasExtraFieldWrapperAttributes.php | ||
* | ||
* See more here: | ||
* https://github.com/GuavaCZ/filament-clusters/pull/11 | ||
*/ | ||
trait HasExtraFieldWrapperAttributes | ||
{ | ||
/** | ||
* @var array<array<mixed> | Closure> | ||
*/ | ||
protected array $extraFieldWrapperAttributes = []; | ||
|
||
/** | ||
* @param array<mixed> | Closure $attributes | ||
*/ | ||
public function extraFieldWrapperAttributes(array | Closure $attributes, bool $merge = false): static | ||
{ | ||
if ($merge) { | ||
$this->extraFieldWrapperAttributes[] = $attributes; | ||
} else { | ||
$this->extraFieldWrapperAttributes = [$attributes]; | ||
} | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* @return array<mixed> | ||
*/ | ||
public function getExtraFieldWrapperAttributes(): array | ||
{ | ||
$temporaryAttributeBag = new ComponentAttributeBag(); | ||
|
||
foreach ($this->extraFieldWrapperAttributes as $extraFieldWrapperAttributes) { | ||
$temporaryAttributeBag = $temporaryAttributeBag->merge($this->evaluate($extraFieldWrapperAttributes)); | ||
} | ||
|
||
return $temporaryAttributeBag->getAttributes(); | ||
} | ||
|
||
public function getExtraFieldWrapperAttributesBag(): ComponentAttributeBag | ||
{ | ||
return new ComponentAttributeBag($this->getExtraFieldWrapperAttributes()); | ||
} | ||
} |