Node content type object in Drupal 8
When obtaining the node types on a given Drupal site in Drupal 7 we use:
$types = node_get_types();
And the content type machine name is available from:
$names = array();
foreach ($types as $type) {
$names[] = $type->type;
}
In Drupal 8 we use the following:
use Drupal\node\Entity\NodeType;
$types = NodeType::loadMultiple();
$names = array();
foreach ($types as $type) {
$names[] = $type->id();
}
- Read more about Node content type object in Drupal 8
- Log in to post comments