How to get the list of field-types? I'm porting a module from Drupal 7 to Drupal 8. In this module's configuration settings I need to get the list of the currently existing field-types.

In Drupal 7, this was achieved using the field_info_field_types() function.

In Drupal 8 (8.0.0-rc3), I get an error "function does not exist", despite the information stated by a Drupal API Reference Help page, clearly out of date.

Then investigating I found a DrupalContrib page, where the function is declared deprecated, and proposing to now use Drupal::service('plugin.manager.entity.field.field_type')-&gt;getDefinitions(). 

But using it fires another error "Unknown service plugin.manager.entity.field.field_type", fortunately associated to the suggestion "Do you mean plugin.manager.field.field_type?"

So I tried using Drupal::service('plugin.manager.field.field_type')-&gt;getDefinitions() and wow: I got the expected array of field-types.

But each array member (one field-type) is now an object (instead of a child array), and the data I'm looking for is nested within protected properties, so I can't access them.

At this stage, I'm stuck. I considered it might exist some class I could expand to navigate through these data, but with no luck: I notably couldn't even figure out which is the component in Drupal 8 where field-types definitions is centralized.
The first level is an array. The keys are the plugin id's. You can list them:

$defs = Drupal::service('plugin.manager.field.field_type')-&gt;getDefinitions();
foreach ( $defs as $key =&gt; $value ) {
   echo $key, "\n";
}


This is the result:

comment
datetime
file
image
link
list_string
list_float
list_integer
path
text_with_summary
text
text_long
email
boolean
created
changed
timestamp
string_long
language
decimal
uri
float
password
string
integer
entity_reference
uuid
map
taxonomy_term_reference


You can pick one and dump the plugin definition.

var_dump($defs['comment']);


If you are interested in a special object, you can digg deeper with the help of api.drupal.org. But it will be easier, if you search for the plugin in the core directory.

To access an object, locate it in the var_dump and use a method:

$defs['comment']['description']-&gt;render();


In this case it is the object TranslatableMarkup, which has the method render to access the translated string.