Skip to content

Add extendTable support to relation-style admin pages#2457

Open
tazzytazzy wants to merge 2 commits into
lunarphp:1.xfrom
tazzytazzy:feat/extend-table-filament-images
Open

Add extendTable support to relation-style admin pages#2457
tazzytazzy wants to merge 2 commits into
lunarphp:1.xfrom
tazzytazzy:feat/extend-table-filament-images

Conversation

@tazzytazzy
Copy link
Copy Markdown
Contributor

This PR implements Ask 1 from #2448 by adding an extendTable seam to relation-style resource pages in Lunar admin.

Today, packages can extend resource tables and relation-manager tables through narrow hooks, but relation-style pages built on BaseManageRelatedRecords do not expose the same seam. That forces packages to replace an entire page just to adjust one column, action, filter, or query clause.

This change brings those pages in line with Lunar's existing extension pattern.

What changed

New base table seam for relation-style pages

BaseManageRelatedRecords now uses a new ExtendsTables concern.

That concern provides the same shape Lunar already uses elsewhere:

public function table(Table $table): Table
{
    return $this->callLunarHook('extendTable', $this->getDefaultTable($table));
}

protected function getDefaultTable(Table $table): Table
{
    return $table;
}

Typed hook on RelationPageExtension

RelationPageExtension now exposes:

public function extendTable(Table $table): Table
{
    return $table;
}

This makes the relation-page table seam discoverable and consistent with the existing resource and relation-manager extension APIs.

Existing page table definitions moved behind getDefaultTable()

Each BaseManageRelatedRecords subclass that previously owned its own table definition now moves that table-building logic into getDefaultTable().

The touched pages are:

  • ManageUrlsRelatedRecords
  • ManageCollectionProducts
  • ManageCollectionChildren
  • ManageProductVariants
  • ManageProductCollections
  • ManageProductAssociations
  • ManageVariantMedia
  • ManageBrandProducts
  • ManageBrandCollections

Compatibility note

The touched pages keep a thin public table() wrapper that delegates to the new base implementation:

public function table(Table $table): Table
{
    return parent::table($table);
}

Behaviorally, this is redundant, but it preserves the concrete-class table() method shape for any downstream code that may reflect on those page classes directly, such as other add-ons.

Why this approach

This keeps the change narrow and upstream-safe:

Tests

Added focused coverage around a real relation-style page, ManageCollectionProducts, to verify:

  • the concrete page still exposes a public table() method
  • default table behavior is unchanged when no extension is registered
  • a RelationPageExtension can extend the table by adding a column

Verification

Ran:

  • vendor/bin/pint --dirty --format agent
  • vendor/bin/pest tests/admin/Feature/Support/Extending/RelationPageExtensionTest.php

Notes

ManageProductVariants also had an unreachable dead block in its old table() method after an early return $table;. That dead code was removed as part of moving to getDefaultTable(), with no intended behavior change.

Mirror Lunar's existing resource and relation-manager table extension
pattern on relation-style resource pages by adding a table seam to
BaseManageRelatedRecords.

This introduces a shared ExtendsTables concern that routes the public
table(Table $table) entrypoint through getDefaultTable() and the
existing Lunar hook dispatcher via extendTable.

The affected BaseManageRelatedRecords pages move their current table
definitions into getDefaultTable() so packages can alter columns,
filters, actions, and query behavior without replacing the whole page.

RelationPageExtension now exposes a typed extendTable(Table $table):
Table method for discoverability and consistency.

To preserve compatibility for downstream code that may expect concrete
pages to still expose a public table() method, the touched pages keep a
thin public wrapper that delegates to the base implementation.

Adds focused feature coverage using ManageCollectionProducts to verify:
- the concrete page still exposes a public table() method
- default table behavior is unchanged with no extension registered
- a RelationPageExtension can extend the page table
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

2 participants