Not really sure what you want to achieve in particular.
Note that isset() and empty() are two different things. While isset() only checks if a variable exists, no matter if it is empty or not, empty() returns true if the variable either does not exist or its value is falsey.
That’s why it makes sense to have these different types of checks.
Thanks @texnixe – I’m thinking out loud a bit here, but hypothetically the use case could be a snippet that is expecting some data (a title) to be passed in like this:
snippet('Component', [
'title' => ...,
],
In the snippet itself, I want to make sure that I have the title to work with or otherwise return early. So I want to know if:
$title exists (it was passed)
It’s not an empty string
If it’s a Kirby field it’s not empty
I was wondering if there was a validator (or similar) I wasn’t aware of that would check all of these, or if this check has to be more verbose.
No, you need to check this one by one, maybe skipping isset(), because empty() also takes care of non-existing variables. If you don’t want to test for field and if field is empty, just pass a value instead of field object $page->someField()->value()