Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Widgets without $heading and table widgets are not showing up in Shield resource #493

Closed
AxelvdS opened this issue Jan 21, 2025 · 3 comments · May be fixed by #473
Closed

Widgets without $heading and table widgets are not showing up in Shield resource #493

AxelvdS opened this issue Jan 21, 2025 · 3 comments · May be fixed by #473

Comments

@AxelvdS
Copy link

AxelvdS commented Jan 21, 2025

Great plugin!

It looks like that for widgets the only possible label for Shield is the widget $heading.
In several instances I don't want a heading for my widget and then the widgets show up in the Shield resource view under the Widget permissions with no label (just a tick box with empty label). Can that be fixed?

Table widgets do not show in the Shield resource permissions at all. Is it possible to add them?

Thanks :)

@nickpoulos
Copy link

I am also running into this issue.

I want my widgets to not have a heading displayed on the page, but this prevents Shield from loading the name on the Widgets tab underneath roles.

Interestingly enough, unlike @AxelvdS my custom table widget DOES show up within the Widgets listing, AND it is showing the proper Widget name. This happens correctly even without a $heading property or method defined.

@bezhanSalleh can you clarify the expected behavior here related to Widget titles?

Let me know if you would like me to post any widget files.

This table widget is displaying properly, even without a defined heading. How can we apply this behavior to standard widgets?

Image

@nickpoulos
Copy link

nickpoulos commented Jan 22, 2025

After digging in a bit, I believe I found the root cause:

FilamentShield::getLocalizedWidgetLabel() has a match statement which is returning an unexpected true for StatsOverviewWidgets.

This is because Filament\Widgets\StatsOverviewWidget.php always has a base getHeading() method, so the default match branch is not executed. This works for the table widgets because it uses a different method name --> getTableHeading() and does not have a getHeading() method.

I think a proper fix would be to update the match statement to check if getHeading() === null.

Ex.

! ($widgetInstance instanceof TableWidget) && $widgetInstance instanceof Widget && method_exists($widgetInstance, 'getHeading') => (string) invade($widgetInstance)->getHeading()

would turn into something like

! ($widgetInstance instanceof TableWidget) && $widgetInstance instanceof Widget && method_exists($widgetInstance, 'getHeading') && invade($widgetInstance)->getHeading() !== null => (string) invade($widgetInstance)->getHeading()

I can make a PR later today if we like this approach. My testing indicates this fix to work.

Image

@nickpoulos
Copy link

@bezhanSalleh please review when you are available:

#495

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants