From 068cde50af3bc6f1d53bcf772df8cd4d5f4755f2 Mon Sep 17 00:00:00 2001 From: Voltra Date: Mon, 24 Jun 2024 16:51:37 +0000 Subject: [PATCH] Delegate BadMethodCallException throwing to a protected method --- src/Forms/IconPicker.php | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/src/Forms/IconPicker.php b/src/Forms/IconPicker.php index 61b0445..5c1d5a0 100644 --- a/src/Forms/IconPicker.php +++ b/src/Forms/IconPicker.php @@ -163,13 +163,21 @@ public function getSearchResults(string $search): array return $results; } + /** + * Marks the calling method as not allowed (whether because it's not supported or because it's meaningless when using this field) + * @throws \BadMethodCallException Always + */ + protected function markAsNotAllowed(string $reason = 'Method not allowed.'): void { + throw new \BadMethodCallException($reason); + } + /** * @deprecated Method inherited from `\Filament\Forms\Components\Select` but not supported (or meaningless) when using this field * @throws \BadMethodCallException */ public function relationship(string|Closure|null $name = null, string|Closure|null $titleAttribute = null, ?Closure $modifyQueryUsing = null, bool $ignoreRecord = false): static { - throw new \BadMethodCallException('Method not allowed.'); + $this->markAsNotAllowed(); } /** @@ -178,7 +186,7 @@ public function relationship(string|Closure|null $name = null, string|Closure|nu */ public function options(Arrayable|Closure|array|string|null $options): static { - throw new \BadMethodCallException('Method not allowed.'); + $this->markAsNotAllowed(); } /** @@ -187,7 +195,7 @@ public function options(Arrayable|Closure|array|string|null $options): static */ public function allowHtml(bool|Closure $condition = true): static { - throw new \BadMethodCallException('Method not allowed.'); + $this->markAsNotAllowed(); } /** @@ -196,7 +204,7 @@ public function allowHtml(bool|Closure $condition = true): static */ public function searchable(bool|array|Closure $condition = true): static { - throw new \BadMethodCallException('Method not allowed.'); + $this->markAsNotAllowed(); } /** @@ -205,7 +213,7 @@ public function searchable(bool|array|Closure $condition = true): static */ public function getSearchResultsUsing(?Closure $callback): static { - throw new \BadMethodCallException('Method not allowed.'); + $this->markAsNotAllowed(); } /** @@ -214,7 +222,7 @@ public function getSearchResultsUsing(?Closure $callback): static */ public function getOptionLabelFromRecordUsing(?Closure $callback): static { - throw new \BadMethodCallException('Method not allowed.'); + $this->markAsNotAllowed(); } /** @@ -223,7 +231,7 @@ public function getOptionLabelFromRecordUsing(?Closure $callback): static */ public function createOptionUsing(?Closure $callback): static { - throw new \BadMethodCallException('Method not allowed.'); + $this->markAsNotAllowed(); } /** @@ -232,7 +240,7 @@ public function createOptionUsing(?Closure $callback): static */ public function createOptionAction(?Closure $callback): static { - throw new \BadMethodCallException('Method not allowed.'); + $this->markAsNotAllowed(); } /** @@ -241,7 +249,7 @@ public function createOptionAction(?Closure $callback): static */ public function createOptionForm(array|Closure|null $schema): static { - throw new \BadMethodCallException('Method not allowed.'); + $this->markAsNotAllowed(); } /** @@ -250,7 +258,7 @@ public function createOptionForm(array|Closure|null $schema): static */ public function schema(array|Closure $components): static { - throw new \BadMethodCallException('Method not allowed.'); + $this->markAsNotAllowed(); } /** @@ -259,7 +267,7 @@ public function schema(array|Closure $components): static */ public function multiple(bool|Closure $condition = true): static { - throw new \BadMethodCallException('Method not allowed.'); + $this->markAsNotAllowed(); } private function loadIcons(): Collection