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

Make $settings public #158

Open
kevinruscoe opened this issue Oct 14, 2024 · 3 comments
Open

Make $settings public #158

kevinruscoe opened this issue Oct 14, 2024 · 3 comments

Comments

@kevinruscoe
Copy link

Hello, I need a way to access Layout names (before registration), but I can't seem to find an api to get them. It seems the name and label are both passed to settings, but I can't access settings because it's protected.

Would it be possible to either make $settings public; or add some public methods to get a fields name or label?

@vinkla
Copy link
Owner

vinkla commented Oct 17, 2024

I would be open to adding $name and $label properties to the field class if this helps with #157. Making $settings public could introduce side effects and increase the likelihood of mistakes. In the future, using property hooks may help with this.

@fiskhandlarn
Copy link
Contributor

a solution right now for @kevinruscoe could maybe be to extend the Layout class and write custom getters for name/label?

@kaelansmith
Copy link
Contributor

I'm also in need of access to the $name and $label properties, among other settings. I have used ReflectionClass in the past:

$property = (new \ReflectionClass($field))->getProperty('settings');
$property->setAccessible(true);
$settings = $field->settings;

@vinkla and I have talked about this in the past on PR #139, and concluded not to add a getter method to make $settings accessible. But I think php 8.4's Asymmetric Property Visibility addresses the concerns that prevented that PR from merging; eg. protected array $settings; becomes public protected(set) array $settings; -- this makes $settings public for the "read" scope while keeping it protected for the "set" scope.

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

No branches or pull requests

5 participants
@vinkla @kevinruscoe @fiskhandlarn @kaelansmith and others