Weird override behavior
Hi, I'm overriding the Shield resource, so I don't have to publish the stubs. But I just don't understand why some methods can be overwritten but some others not.
For example: I can easierly overwrite shouldRegisterNavigation() or getNavigationLabel(), but I can't overwrite getPluralModelLabel().
Both getNavigationLabel() and getPluralModelLabel() are used the same way in the base Shield resource. But only getNavigationLabel() works, the other method (getPluralModelLabel) doesn't even get called.
Can someone explain to me, why this is happening?
Full code:
For reference, this is the shield base class resource:
Solution:Jump to solution
The reason some method overrides work while others don’t is due to how they are scoped and utilized. For example, model label and model plural label overrides do not work because you’re only overriding the
RoleResource
. To make those overrides work, you also need to extend the ListRoles
page of the resource and bind your custom implementation in a service provider, just like you did with the resource.
The same applies to sub-navigation. To get sub-navigation working, you need to extend both the EditRole
and ViewRole
pages of the RoleResource
with your custom implementation of those pages. Once you’ve done that, bind them in a service provider. Then, within your custom RoleResource
(ShieldOverrideResource
) implementation, override the getPages()
method to provide your implementation for those pages, and implement getRecordSubNavigation()
accordingly....1 Reply
Solution
The reason some method overrides work while others don’t is due to how they are scoped and utilized. For example, model label and model plural label overrides do not work because you’re only overriding the
RoleResource
. To make those overrides work, you also need to extend the ListRoles
page of the resource and bind your custom implementation in a service provider, just like you did with the resource.
The same applies to sub-navigation. To get sub-navigation working, you need to extend both the EditRole
and ViewRole
pages of the RoleResource
with your custom implementation of those pages. Once you’ve done that, bind them in a service provider. Then, within your custom RoleResource
(ShieldOverrideResource
) implementation, override the getPages()
method to provide your implementation for those pages, and implement getRecordSubNavigation()
accordingly.