If I want to get a list of all fields that I've defined on the site, I can do this:
But how do I get a list of all sub-fields defined within a Matrix field?
I have access to the
MatrixBlockModel, if that helps.
You’ll need to start by figuring out the Matrix field’s ID. If you already have a MatrixBlockModel object as you say, you can get that via
Once you know the Matrix field’s ID, you can get all its block types like this:
That will give you an array of MatrixBlockTypeModel objects. From there you can loop through each of those and get their fields like this:
With a MatrixBlockModel you can get the MatrixBlockTypeModel like so:
You can get the FieldModel of all the fields associated with that type with the
If you needed the FieldLayoutFieldModel you could access them like so
NOTE: This answer misses the question as the original question requested all fields from the parent Matrix field, which would require looping through all of the MatrixBlockTypeModels as Brandon describes above. I've tried to update this answer to at least provide some related information instead of just being wrong or a duplicate of the one above!
|show 2 more comments|