make tweaks to manage related records page generation in same way as RM

This commit is contained in:
Dan Harrin
2025-04-18 16:31:11 +01:00
parent eef8768b89
commit fa2accf4e2
2 changed files with 22 additions and 7 deletions
@@ -77,7 +77,6 @@ class ResourceManageRelatedRecordsPageClassGenerator extends ClassGenerator
? [$relatedResourceFqn]
: [
Schema::class,
Table::class,
...($this->hasPartialImports() ? [
...(blank($this->getTableFqn()) ? ['Filament\Actions', 'Filament\Tables'] : []),
...(blank($this->getFormSchemaFqn()) ? ['Filament\Forms'] : []),
@@ -223,17 +222,32 @@ class ResourceManageRelatedRecordsPageClassGenerator extends ClassGenerator
protected function addTableMethodToClass(ClassType $class): void
{
if ($this->hasRelatedResource()) {
$relatedResource = $this->getRelatedResourceFqn();
if ($relatedResource && blank($headerActionsOutput = $this->outputTableHeaderActions())) {
// If the related resource is set and there are no table header actions to add, we don't need
// to generate the table method since it will be inherited from the related resource.
return;
}
$tableFqn = $this->getTableFqn();
$this->namespace->addUse(Table::class);
$methodBody = filled($tableFqn)
? <<<PHP
if ($relatedResource) {
$methodBody = <<<PHP
return \$table
->headerActions([
{$headerActionsOutput}
]);
PHP;
} else {
$tableFqn = $this->getTableFqn();
$methodBody = filled($tableFqn)
? <<<PHP
return {$this->simplifyFqn($tableFqn)}::configure(\$table);
PHP
: $this->generateTableMethodBody($this->getRelatedModelFqn(), exceptColumns: Arr::wrap($this->getForeignKeyColumnToNotGenerate()));
: $this->generateTableMethodBody($this->getRelatedModelFqn(), exceptColumns: Arr::wrap($this->getForeignKeyColumnToNotGenerate()));
}
$method = $class->addMethod('table')
->setPublic()
@@ -201,7 +201,8 @@ class RelationManagerClassGenerator extends ClassGenerator
$relatedResource = $this->getRelatedResourceFqn();
if ($relatedResource && blank($headerActionsOutput = $this->outputTableHeaderActions())) {
// If the related resource is set and there are no table header actions, we don't need to generate the table method, since we
// If the related resource is set and there are no table header actions to add, we don't need
// to generate the table method since it will be inherited from the related resource.
return;
}