Skip to content

Commit b4a8932

Browse files
Merge branch 'main' into feature/tree
2 parents 3f688e8 + 41c8a3f commit b4a8932

208 files changed

Lines changed: 21132 additions & 153 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/cleanup-empty-translations.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
runs-on: ubuntu-latest
1010

1111
steps:
12-
- uses: actions/checkout@v6.0.2
12+
- uses: actions/checkout@v6.0.3
1313

1414
- name: Setup PHP
1515
uses: shivammathur/setup-php@v2

.github/workflows/monorepo-split-packages.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ jobs:
8686

8787

8888
steps:
89-
- uses: actions/checkout@v6.0.2
89+
- uses: actions/checkout@v6.0.3
9090

9191
# Search and replace "moox/core": "*" with "moox/core": "^3.1.3" in composer.json
9292
- name: Replace core version in composer.json

.github/workflows/monorepo-split-plugins.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
fail-fast: false
1717

1818
steps:
19-
- uses: actions/checkout@v6.0.2
19+
- uses: actions/checkout@v6.0.3
2020

2121
- if: "!startsWith(github.ref, 'refs/tags/')"
2222
uses: "symplify/monorepo-split-github-action@v2.4.5"

.github/workflows/pest.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ jobs:
3535
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
3636

3737
steps:
38-
- uses: actions/checkout@v6.0.2
38+
- uses: actions/checkout@v6.0.3
3939

4040
- name: Setup PHP
4141
uses: shivammathur/setup-php@v2
@@ -93,7 +93,7 @@ jobs:
9393
needs: pest
9494
runs-on: ubuntu-latest
9595
steps:
96-
- uses: actions/checkout@v6.0.2
96+
- uses: actions/checkout@v6.0.3
9797

9898
- name: Download Coverage Report
9999
uses: actions/download-artifact@v8

.github/workflows/pint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212

1313
steps:
1414
- name: Checkout code
15-
uses: actions/checkout@v6.0.2
15+
uses: actions/checkout@v6.0.3
1616
with:
1717
ref: ${{ github.head_ref }}
1818
token: ${{ secrets.BOT || github.token }}

.github/workflows/scorecard.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434

3535
steps:
3636
- name: "Checkout code"
37-
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
37+
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
3838
with:
3939
persist-credentials: false
4040

.github/workflows/split.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ jobs:
7373
package: ${{ fromJson(needs.prepare.outputs.package-list) }}
7474

7575
steps:
76-
- uses: actions/checkout@v6.0.2
76+
- uses: actions/checkout@v6.0.3
7777

7878
- name: Get package stability and determine version
7979
working-directory: packages/${{ matrix.package }}

packages/address/config/address.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,14 @@
122122
'delivery_address',
123123
],
124124
'owner_types' => [
125-
'Moox\Company\Models\Company' => 'Company',
126-
// 'Heco\Contact\Models\Contact' => 'Contact',
125+
// 'Moox\Company\Models\Company' => [
126+
// 'label' => 'Company',
127+
// 'title_attribute' => 'display_name',
128+
// ],
129+
// 'Moox\Contact\Models\Contact' => [
130+
// 'label' => 'Contact',
131+
// 'title_attribute' => 'display_name',
132+
// ],
127133
],
128134
],
129135
],

packages/address/src/Resources/Address/RelationManagers/AddressablesRelationManager.php

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Filament\Tables\Columns\TextColumn;
1717
use Filament\Tables\Table;
1818
use Illuminate\Database\Eloquent\Model;
19+
use Illuminate\Support\Facades\Schema as DatabaseSchema;
1920
use Moox\Address\Support\AddressRelationConfig;
2021
use Override;
2122

@@ -45,7 +46,12 @@ public function form(Schema $schema): Schema
4546
->label(__('address::fields.owner'))
4647
->types(
4748
collect($ownerTypes)
48-
->map(fn (string $label, string $class): Type => Type::make($class)->label($label))
49+
->map(fn (string $label, string $class): Type => Type::make($class)
50+
->label($label)
51+
->titleAttribute($this->resolveTitleAttributeForMorphType($class))
52+
->getOptionLabelFromRecordUsing(
53+
fn (Model $record): string => $this->resolveOptionLabel($record)
54+
))
4955
->values()
5056
->all()
5157
)
@@ -108,4 +114,42 @@ public function table(Table $table): Table
108114
DeleteAction::make(),
109115
]);
110116
}
117+
118+
private function resolveTitleAttributeForMorphType(string $class): string
119+
{
120+
$configured = AddressRelationConfig::titleAttributeForOwnerType($class);
121+
122+
if ($configured !== null) {
123+
return $configured;
124+
}
125+
126+
$model = app($class);
127+
$table = $model->getTable();
128+
$schema = DatabaseSchema::connection($model->getConnectionName());
129+
130+
foreach (['display_name', 'name', 'title'] as $column) {
131+
if ($schema->hasColumn($table, $column)) {
132+
return $column;
133+
}
134+
}
135+
136+
return $model->getKeyName();
137+
}
138+
139+
private function resolveOptionLabel(Model $record): string
140+
{
141+
if (method_exists($record, 'displayLabel')) {
142+
return (string) $record->displayLabel();
143+
}
144+
145+
foreach (['display_name', 'name', 'title'] as $attribute) {
146+
$value = $record->getAttribute($attribute);
147+
148+
if (is_string($value) && $value !== '') {
149+
return $value;
150+
}
151+
}
152+
153+
return (string) $record->getKey();
154+
}
111155
}

packages/address/src/Support/AddressRelationConfig.php

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,61 @@ public static function pivotColumns(): array
3838
return $columns;
3939
}
4040

41+
/**
42+
* @return array<class-string, array{label: string, title_attribute: ?string}>
43+
*/
44+
public static function ownerTypeDefinitions(): array
45+
{
46+
/** @var array<class-string, string|array{label?: string, title_attribute?: string}> $raw */
47+
$raw = self::addressables()['owner_types'] ?? [];
48+
49+
$definitions = [];
50+
51+
foreach ($raw as $class => $definition) {
52+
if (! is_string($class) || $class === '') {
53+
continue;
54+
}
55+
56+
if (is_string($definition)) {
57+
$definitions[$class] = [
58+
'label' => $definition,
59+
'title_attribute' => null,
60+
];
61+
62+
continue;
63+
}
64+
65+
if (! is_array($definition)) {
66+
continue;
67+
}
68+
69+
$definitions[$class] = [
70+
'label' => (string) ($definition['label'] ?? class_basename($class)),
71+
'title_attribute' => isset($definition['title_attribute']) && is_string($definition['title_attribute']) && $definition['title_attribute'] !== ''
72+
? $definition['title_attribute']
73+
: null,
74+
];
75+
}
76+
77+
return $definitions;
78+
}
79+
4180
/**
4281
* @return array<class-string, string>
4382
*/
4483
public static function ownerTypes(): array
4584
{
46-
/** @var array<class-string, string> $types */
47-
$types = self::addressables()['owner_types'] ?? [];
85+
$labels = [];
4886

49-
return $types;
87+
foreach (self::ownerTypeDefinitions() as $class => $definition) {
88+
$labels[$class] = $definition['label'];
89+
}
90+
91+
return $labels;
92+
}
93+
94+
public static function titleAttributeForOwnerType(string $class): ?string
95+
{
96+
return self::ownerTypeDefinitions()[$class]['title_attribute'] ?? null;
5097
}
5198
}

0 commit comments

Comments
 (0)