Get labels of view modes in Drupal 8 I'm trying to rebuild the pullquote module in Drupal 8 but am running into an issue accessing view modes. In the Drupal 7 version, the view_modes variable is set by the following lines:

$entity_info = entity_get_info('node');
$view_modes = $entity_info['view modes'];
$view_mode_options = array();

foreach ($view_modes as $mode =&gt; $settings) {
  $view_mode_options[$mode] = $settings['label'];
}


However, entity_get_info() has been depreciated in Drupal 8, and according to the documentation I found, replaced with \Drupal::entityTypeManager()-&gt;getDefinition().

So I tried replacing the first line:

$nodeEntity = \Drupal::entityTypeManager()-&gt;getDefinition('node');


but the array was empty, so maybe I'm using the wrong tool.

I then found this answer for accessing a list of all view nodes.

$view_modes = \Drupal::entityQuery('entity_view_mode')
  -&gt;condition('targetEntityType', 'node')
  -&gt;execute();


It worked, however, they were returned like this:

['node.full', 'node.rss', 'node.teaser']


But here's the problem. I'm using these view modes as options in a form. When the form is saved in configuration, having a key with a period breaks the YAML file with the following error: The website encountered an unexpected error. Please try again later. Drupal\Core\Config\ConfigValueException: node.full key contains a dot which is not supported. in Drupal\Core\Config\ConfigBase-&gt;validateKeys(). I'm confused though, because I map over the array so that I'm stripping the names of ".node"

Here's my full code for reference:

// Load the list of avialable view modes.
$view_modes = \Drupal::entityQuery('entity_view_mode')
  -&gt;condition('targetEntityType', 'node')
  -&gt;execute();

// remove "node."
$view_mode_options = array_map(function ($mode) {
  $parsed = substr($mode, 5);
  return $parsed;
}, $view_modes);

$form['view_mode_settings']['pullquote_view_modes'] = [
  '#type' =&gt; 'checkboxes',
  '#title' =&gt; t('View Modes'),
  '#options' =&gt; $view_mode_options,
  '#default_value' =&gt; $config-&gt;get('pullquote_view_modes'),
  '#description' =&gt; t('Choose which view modes will load pullquote code and render pullquotes. For better performance you should only load pullquote where you need it.'),
   '#states' =&gt; array(
     'visible' =&gt; array(
       ':input[name="pullquote_load_by_view_mode"]' =&gt; array('value' =&gt; 1),
       ':input[name="pullquote_scope"]' =&gt; array('value' =&gt; 0),
     ),
   ),
];


Now the view modes display properly on the page, but I still get the error that Drupal can't save "node.full" in configuration, which is confusing because the page displays only "full."

Is there a method for getting the label of different entity types? Or is there a way to actually parse "node.full" down to a string that is only "full"--both when it displays and how Drupal understands it?
Drupal 8 services are essentially helpful objects (tools), which live inside the services container (tool belt). Calling a service returns an object, essentially providing a clear path to the helper methods within that class. As previously answered, EntityDisplayRepository class contains various methods, specifically one that will return an array of entity view modes (see a list of available methods). By calling \Drupal::service('entity_display.repository') and storing it in a variable, you now have an object that you can then call EntityDisplayRepository methods from, which in your case, is to return 'node' view modes.

/**
 * Implements hook_preprocess_page().
 *
 * This function is called before the page is rendered.
 */
function modulename_preprocess_page(&amp;$vars) {
  // call the entity service.
  $nodeEntity = \Drupal::service('entity_display.repository');

  // call the necessary method in order to return 'node' view modes.
  $nodeEntity-&gt;getViewModes('node');

  // one line: \Drupal::service('entity_display.repository')-&gt;getViewModes('node');
}