protected function isValidFieldname(FieldStorageConfig $field_storage, FieldableEntityInterface $entity) { $comment_field_name_ok = FALSE; if ($field_storage->getTargetEntityTypeId() !== 'comment') { return TRUE; } $field_name = $field_storage->get('field_name'); // Check if the 'comment' field name exists on the 'commented' entity type. // @todo: Still not waterproof. You could have a field on a non-relevant entity_type. foreach (_workflow_info_fields() as $key => $info) { if ($info->getName() == $field_name && $info->getTargetEntityTypeId() !== 'comment') { $comment_field_name_ok = TRUE; } } return $comment_field_name_ok; }