How to get all Fields of specific FieldType? What I'm trying to do is ->

 $fields = [];
  $fields = $entity-&gt;getFieldDefinitions();  
  foreach ($fields as $field) {
    if ($field-&gt;field_type == 'type') {
      $test = $field-&gt;field_type;
    }
  }


Unfortunately I couldn't find a neat method to select my fields by type, so I thought unless Drupal won't give me one I write my own.
But Drupal restrict me on that also with this ->
Fatal error: Cannot access protected property 


  Fatal error: Cannot access protected property
  Drupal\field\Entity\FieldConfig::$field_type
You code is OK, only that you are trying to read the protected property field_type. Instead use the method:

$field-&gt;getType()


Reference: public function FieldDefinitionInterface::getType()