欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

得到 所有的内容类型 有大用 有大大用 有大大大用

1) node_type_get_types()

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



$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();
}

function node_type_get_names() {  return array_map(function ($bundle_info) {    return $bundle_info['label'];  }, \Drupal::service('entity_type.bundle.info')    ->getBundleInfo('node')); }


>>> $bi = \Drupal::service('entity_type.bundle.info'); => Drupal\Core\Entity\EntityTypeBundleInfo {#1433     +"_serviceId": "entity_type.bundle.info",   } >>> $bi->getBundleInfo('node'); => [     "article" => [       "label" => "Article",       "translatable" => false,     ],

来自  https://drupal.stackexchange.com/questions/199852/get-the-list-of-all-content-types


普通分类: