Skip to content

Instantly share code, notes, and snippets.

@abelperezlindo
Created June 3, 2022 18:07
Show Gist options
  • Save abelperezlindo/97000cfa0cfbd56d8a53e318e87574b3 to your computer and use it in GitHub Desktop.
Save abelperezlindo/97000cfa0cfbd56d8a53e318e87574b3 to your computer and use it in GitHub Desktop.
Obtener una lista de los tipos de contenido del sitio para usarlos como opciones en un menú desplegable en Drupal 9.
use Drupal\node\Entity\NodeType;
// Code ...
$node_types = NodeType::loadMultiple();
// If you need to display them in a drop down.
$options = []; // options are stored in this variable
foreach ($node_types as $node_type) {
// Get a list of site content types to use as options in a dropdown menu in Drupal 9.
$options[$node_type->id()] = $node_type->label();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment