Drupal - Get the list of all content types

loadMultiple() should be fine for this:

$types = \Drupal::entityTypeManager()
  ->getStorage('node_type')
  ->loadMultiple();

You can load all of the NodeType entities (config entities) using the NodeType class:

$node_types = \Drupal\node\Entity\NodeType::loadMultiple();
// If you need to display them in a drop down:
$options = [];
foreach ($node_types as $node_type) {
  $options[$node_type->id()] = $node_type->label();
}

There is another Drupal helper function that is not deprecated as of 8.7. node_type_get_names() returns:

string[] An array of node type labels, keyed by the node type name.

API docs

Tags:

Nodes

8