Skip to content

Commit

Permalink
Add possibility for custom tab titles
Browse files Browse the repository at this point in the history
  • Loading branch information
AngryMoustache authored Oct 4, 2023
1 parent 82d9177 commit fd7be7d
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/Repositories/SettingTabRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ public function registerTab(string|array $tab): static
$this->tabs = collect($tab)
->reject(fn ($tab) => ! is_subclass_of($tab, SettingsInterface::class))
->mapWithKeys(function ($tab) {
$className = Str::replace(
Str::beforeLast($tab, '\\') . '\\',
'',
$tab
);
$tabTitle = $tab::title() ?? Str::of($tab)
->afterLast('\\')
->replaceMatches('/([A-Z])/', ' $1')
->headline()
->ucfirst();

return [Str::ucfirst(Str::headline($className)) => $tab];
return [(string) $tabTitle => $tab];
})
->merge($this->tabs)
->sortBy(fn (string $settingsTab) => method_exists($settingsTab, 'priority') ? $settingsTab::priority() : 0)
Expand Down Expand Up @@ -80,9 +80,10 @@ public function getAllTabs(): Collection

public function getRequiredKeys()
{
return $this->getTabs()->flatten()
return $this->getTabs()
->flatten()
->filter(fn (Field $field) => collect($field->getValidationRules())
->contains(fn ($rule) => $rule instanceof SettingMustBeFilledIn))
->contains(fn ($rule) => $rule instanceof SettingMustBeFilledIn))
->mapWithKeys(fn (Field $field) => [
$field->getName() => [
'label' => $field->getLabel(),
Expand Down

0 comments on commit fd7be7d

Please sign in to comment.