Skip to content

Commit

Permalink
Fix for vendor prefixed fieldset handles (#339)
Browse files Browse the repository at this point in the history
ryanmitchell authored Aug 21, 2024
1 parent 5fa84f7 commit dbcb234
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/Fields/FieldsetRepository.php
Original file line number Diff line number Diff line change
@@ -6,6 +6,7 @@
use Statamic\Facades\Blink;
use Statamic\Fields\Fieldset;
use Statamic\Fields\FieldsetRepository as StacheRepository;
use Statamic\Support\Str;

class FieldsetRepository extends StacheRepository
{
@@ -18,8 +19,14 @@ public function all(): Collection

return $models->map(function ($model) {
return Blink::once("eloquent-fieldset-{$model->handle}", function () use ($model) {
$handle = $model->handle;

if (Str::startsWith($handle, 'vendor.')) {
$handle = Str::of($handle)->after('vendor.')->replaceFirst('.', '::');
}

return (new Fieldset)
->setHandle($model->handle)
->setHandle($handle)
->setContents($model->data);
});
});
@@ -30,6 +37,10 @@ public function find($handle): ?Fieldset
{
$handle = str_replace('/', '.', $handle);

if (Str::startsWith($handle, 'vendor.')) {
$handle = Str::of($handle)->after('vendor.')->replaceFirst('.', '::');
}

return $this->all()->filter(function ($fieldset) use ($handle) {
return $fieldset->handle() == $handle;
})->first();

0 comments on commit dbcb234

Please sign in to comment.