From 62b26a38f839812e5b1fafbba2f5e3fa0850ad5f Mon Sep 17 00:00:00 2001 From: Saulius Kazokas Date: Fri, 17 May 2024 12:18:47 +0300 Subject: [PATCH] Fix getExtraFieldWrapperAttributes missing --- src/Forms/Cluster.php | 1 + .../HasExtraFieldWrapperAttributes.php | 54 +++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 src/Forms/Concerns/HasExtraFieldWrapperAttributes.php diff --git a/src/Forms/Cluster.php b/src/Forms/Cluster.php index e364652..46acb41 100644 --- a/src/Forms/Cluster.php +++ b/src/Forms/Cluster.php @@ -17,6 +17,7 @@ class Cluster extends Component use CanBeAutofocused; use CanBeMarkedAsRequired; use CanBeValidated; + use Concerns\HasExtraFieldWrapperAttributes; use HasHelperText; use HasHint; use HasName; diff --git a/src/Forms/Concerns/HasExtraFieldWrapperAttributes.php b/src/Forms/Concerns/HasExtraFieldWrapperAttributes.php new file mode 100644 index 0000000..ae76775 --- /dev/null +++ b/src/Forms/Concerns/HasExtraFieldWrapperAttributes.php @@ -0,0 +1,54 @@ + | Closure> + */ + protected array $extraFieldWrapperAttributes = []; + + /** + * @param array | 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 + */ + 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()); + } +}