Created
June 3, 2022 18:07
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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