I'm still pretty new to D8 so I'm getting to grips with the new way it deals with fields and the OOP way of doing it etc.
I've got a hook in my module which I'm trying to add a submit handler to different types of form submission (user registration, comment forms, webforms etc) and I'm trying to write something which will go through each of the admin added fields (eg, all fields that start with field_ ) and deal with each field type so that I can do something additional with it at the end
In pseudo terms
foreach ($fields as $field_name => $field) {
if (substr($field_name, 0, 6) === "field_") {
switch ( //field type ) {
case 'boolean':
// if it's a boolean, do this
break;
case 'entity_reference':
// if it's an entity reference, do this
break;
default:
// for everything else, do this
break;
}
}
}
But where my switch statement is, I'm basically having to check against the field definition to determine what type of field I'm checking against, because if I just check against the submit handler answers, it only gives me the response.
Currently I'm getting the definitions by doing this
$definitions = \Drupal::service('entity_field.manager')->getFieldDefinitions('entity_type', 'bundle');
Is that the best method to do it? When I tried to run dpm() on this for a custom comment form type, it just seems to kill my site, not like a requirement error, but it just seems to have a memory leak when I try to do it or something.