Skip to content

Commit

Permalink
Fix for manually setting options
Browse files Browse the repository at this point in the history
  • Loading branch information
afonic committed Apr 19, 2024
1 parent 2fbffa2 commit 287238c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 16 deletions.
2 changes: 0 additions & 2 deletions src/Http/Livewire/LfCheckboxFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ public function filterOptions()
{
if (isset($this->statamic_field['options'])) {
return $this->statamic_field['options'];
} elseif (is_array($this->options)) {
return $this->options;
}
}

Expand Down
2 changes: 0 additions & 2 deletions src/Http/Livewire/LfRadioFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ public function filterOptions()
{
if (isset($this->statamic_field['options'])) {
return $this->statamic_field['options'];
} elseif (is_array($this->options)) {
return $this->options;
}
}

Expand Down
32 changes: 20 additions & 12 deletions src/Http/Livewire/Traits/IsLivewireFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,27 @@ public function initiateField()
collect($field->config()['taxonomies'])->each(function ($taxonomy) use ($terms) {
$terms->push(($this->getTaxonomyTerms($taxonomy)->all()));
});
$field->setConfig([
'options' => $terms->collapse()->all(),
'counts' => $terms->collapse()->keys()->flatMap(fn ($slug) => [$slug => null])->all(),
]);
} else {
if (array_key_exists('options', $field->toArray())) {
$field->setConfig(array_merge(
$field->config(),
['counts' => collect($field->get('options'))->keys()->flatMap(fn ($option) => [$option => null])->all()]
));
}
$field->setConfig(array_merge(
$field->config(),
[
'options' => $terms->collapse()->all(),
'counts' => $terms->collapse()->keys()->flatMap(fn ($slug) => [$slug => null])->all(),
]
));
} elseif (array_key_exists('options', $field->toArray())) {
$field->setConfig(array_merge(
$field->config(),
['counts' => collect($field->get('options'))->keys()->flatMap(fn ($option) => [$option => null])->all()]
));
} elseif (isset($this->options) && is_array($this->options)) {
$field->setConfig(array_merge(
$field->config(),
[
'options' => $this->options,
'counts' => collect($this->options)->keys()->flatMap(fn ($option) => [$option => null])->all(),
]
));
}

$this->statamic_field = $field->toArray();
}

Expand Down

0 comments on commit 287238c

Please sign in to comment.