I can't seem to figure out a good way to see if an Entry has an actual field defined. All the examples I see just to a falsy check for the property name, but this might fail if you have previously defined a field (either by switching Entry Type, or if you modified the Entry Type).
Entry Type 1 previously had a field called
MyFirstField (let's say it's a static table).
I later on concludes that the table was wrong, and hard to work with on some types. So I modify the Entry Type and replace it with
MyFirstFieldV2. I still keep
MyFirstField on some other type, and I use a shared partial to render this, so I want to check if the current type has
MyFirstFieldV2 and render it appropriately.
The falsy check works, as long as it is a new entry. If it is an old entry, it will think that it has data for
MyFirstField, even though I have removed that field from the type.
Entry type has a fields() method, that returns an array of all fields, but that becomes quite clunky to work with. I guess it would be possible to make some helper that validates the field name against that array, but it feels like there should be an easier way.
Preferably I think the entry should loose all properties that no longer exists on the entry type, but it seems like every entry has a property (albeit null) for each and every field that exists in the system?
EDIT: Regardless whether this is a feature or a bug, what is the appropriate way to check if an Entry Type has a certain field configured? The fields() function doesn't at all return what I expected.