[FR] craft\services\Fields::getFieldsByType() #12381
-
It would be great if there were a simple service method for fetching all fields of a certain type... // Get all Plain Text fields
$plainTextFields = Craft::$app->getFields()->getFieldsByType(PlainText::class); That method doesn't yet exist, so here's what we currently have to do to filter by field type... // Get all fields
$allFields = Craft::$app->getFields()->getAllFields();
// Keep only Plain Text fields
$plainTextFields = array_filter($allFields, function($field) {
return is_a($field, PlainText::class);
}); I used Real-World ApplicationThis method would be truly helpful when writing a migration for a field type. Writing migrations are already a PITA. Within the context of the Google Maps plugin, I need to write a migration that targets every single Address field ( $addressFields = Craft::$app->getFields()->getFieldsByType(AddressField::class); |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 7 replies
-
Why not? Added for 4.4. (3ca0ec5) |
Beta Was this translation helpful? Give feedback.
Why not? Added for 4.4. (3ca0ec5)