Skip to content

Commit

Permalink
fix: getExtraFieldWrapperAttributes missing
Browse files Browse the repository at this point in the history
fix: getExtraFieldWrapperAttributes missing
  • Loading branch information
lukas-frey authored May 21, 2024
2 parents b9bd5a4 + 62b26a3 commit dcc1902
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Forms/Cluster.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class Cluster extends Component
use CanBeAutofocused;
use CanBeMarkedAsRequired;
use CanBeValidated;
use Concerns\HasExtraFieldWrapperAttributes;
use HasHelperText;
use HasHint;
use HasName;
Expand Down
54 changes: 54 additions & 0 deletions src/Forms/Concerns/HasExtraFieldWrapperAttributes.php
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());
}
}

0 comments on commit dcc1902

Please sign in to comment.