Commit 82ecfadf authored by alexpott's avatar alexpott

Issue #2261401 by Berdir: Automatically provide bundle info/list based on bundle_of annotation.

parent 3eda9f70
......@@ -627,8 +627,17 @@ public function getAllBundleInfo() {
}
else {
$this->bundleInfo = $this->moduleHandler->invokeAll('entity_bundle_info');
// If no bundles are provided, use the entity type name and label.
// First look for entity types that act as bundles for others, load them
// and add them as bundles.
foreach ($this->getDefinitions() as $type => $entity_type) {
if ($entity_type->getBundleOf()) {
foreach ($this->getStorage($type)->loadMultiple() as $entity) {
$this->bundleInfo[$entity_type->getBundleOf()][$entity->id()]['label'] = $entity->label();
}
}
}
foreach ($this->getDefinitions() as $type => $entity_type) {
// If no bundles are provided, use the entity type name and label.
if (!isset($this->bundleInfo[$type])) {
$this->bundleInfo[$type][$type]['label'] = $entity_type->getLabel();
}
......
......@@ -92,18 +92,6 @@ function custom_block_entity_type_alter(array &$entity_types) {
}
}
/**
* Implements hook_entity_bundle_info().
*/
function custom_block_entity_bundle_info() {
$bundles = array();
foreach (\Drupal::configFactory()->listAll('custom_block.type.') as $config_name) {
$config = \Drupal::config($config_name);
$bundles['custom_block'][$config->get('id')]['label'] = $config->get('label');
}
return $bundles;
}
/**
* Adds the default body field to a custom block type.
*
......
......@@ -61,18 +61,6 @@ function contact_entity_type_alter(array &$entity_types) {
$entity_types['user']->setLinkTemplate('contact-form', 'contact.personal_page');
}
/**
* Implements hook_entity_bundle_info().
*/
function contact_entity_bundle_info() {
$bundles = array();
foreach (\Drupal::configFactory()->listAll('contact.category.') as $config_name) {
$config = \Drupal::config($config_name);
$bundles['contact_message'][$config->get('id')]['label'] = $config->get('label');
}
return $bundles;
}
/**
* Implements hook_entity_extra_field_info().
*/
......
......@@ -184,19 +184,6 @@ function node_theme() {
);
}
/**
* Implements hook_entity_bundle_info().
*/
function node_entity_bundle_info() {
$bundles = array();
// Bundles must provide a human readable name so we can create help and error
// messages.
foreach (node_type_get_names() as $id => $label) {
$bundles['node'][$id]['label'] = $label;
}
return $bundles;
}
/**
* Implements hook_entity_view_display_alter().
*/
......@@ -323,24 +310,9 @@ function node_type_get_types() {
* An array of node type labels, keyed by the node type name.
*/
function node_type_get_names() {
$cid = 'node_type:names:' . \Drupal::languageManager()->getCurrentLanguage()->id;
if ($cache = \Drupal::cache()->get($cid)) {
return $cache->data;
}
// Not using node_type_get_types() or entity_load_multiple() here, to allow
// this function being used in hook_entity_type_build() implementations.
// @todo Consider to convert this into a generic config entity helper.
$config_names = \Drupal::configFactory()->listAll('node.type.');
$names = array();
foreach ($config_names as $config_name) {
$config = \Drupal::config($config_name);
$names[$config->get('type')] = $config->get('name');
}
\Drupal::cache()->set($cid, $names, Cache::PERMANENT, array(
'node_type' => array_keys($names),
'node_types' => TRUE,
));
return $names;
return array_map(function ($bundle_info) {
return $bundle_info['label'];
}, \Drupal::entityManager()->getBundleInfo('node'));
}
/**
......
......@@ -115,18 +115,6 @@ function taxonomy_permission() {
return $permissions;
}
/**
* Implements hook_entity_bundle_info().
*/
function taxonomy_entity_bundle_info() {
$bundles = array();
foreach (taxonomy_vocabulary_get_names() as $id) {
$config = \Drupal::config('taxonomy.vocabulary.' . $id);
$bundles['taxonomy_term'][$id]['label'] = $config->get('name');
}
return $bundles;
}
/**
* Entity URI callback.
*/
......
......@@ -150,14 +150,6 @@ function user_js_alter(&$javascript) {
);
}
/**
* Implements hook_entity_bundle_info().
*/
function user_entity_bundle_info() {
$bundles['user']['user']['label'] = t('User');
return $bundles;
}
/**
* Entity URI callback.
*/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment