BundleDestinationOptionsTrait.php in Field tools 8
File
src/Form/BundleDestinationOptionsTrait.php
View source
<?php
namespace Drupal\field_tools\Form;
use Drupal\Core\Entity\EntityTypeBundleInfoInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
trait BundleDestinationOptionsTrait {
protected function getDestinationOptions(EntityTypeManagerInterface $entity_type_manager, EntityTypeBundleInfoInterface $entity_type_bundle_info) {
$entity_types = $entity_type_manager
->getDefinitions();
$bundles = $entity_type_bundle_info
->getAllBundleInfo();
$destination_options = [];
foreach ($entity_types as $entity_type_id => $entity_type) {
if (!$entity_type
->get('field_ui_base_route')) {
continue;
}
$entity_type_label = $entity_type
->getLabel();
foreach ($bundles[$entity_type_id] as $bundle_id => $bundle_info) {
$option_key = "{$entity_type_id}::{$bundle_id}";
$destination_options[$option_key] = $entity_type_label . ' - ' . $bundle_info['label'];
}
}
natcasesort($destination_options);
return $destination_options;
}
}