public static function ViewsAddButtonUtilities::createEntityBundleList in Views Add Button 8
Same name and namespace in other branches
- 2.0.x src/ViewsAddButtonUtilities.php \Drupal\views_add_button\ViewsAddButtonUtilities::createEntityBundleList()
Build Bundle Type List.
1 call to ViewsAddButtonUtilities::createEntityBundleList()
- ViewsAddButtonField::buildOptionsForm in src/
Plugin/ views/ field/ ViewsAddButtonField.php - Provide the options form.
File
- src/
ViewsAddButtonUtilities.php, line 48
Class
- ViewsAddButtonUtilities
- Class ViewsAddButtonUtilities @package Drupal\views_add_button
Namespace
Drupal\views_add_buttonCode
public static function createEntityBundleList() {
$ret = [];
$entity_info = \Drupal::entityTypeManager()
->getDefinitions();
$bundle_info = \Drupal::service('entity_type.bundle.info');
foreach ($entity_info as $type => $info) {
// Is this a content/front-facing entity?
if ($info instanceof ContentEntityType) {
$label = $info
->getLabel();
if ($label instanceof TranslatableMarkup) {
$label = $label
->render();
}
$ret[$label] = [];
$bundles = $bundle_info
->getBundleInfo($type);
foreach ($bundles as $key => $bundle) {
if ($bundle['label'] instanceof TranslatableMarkup) {
$ret[$label][$type . '+' . $key] = $bundle['label']
->render();
}
else {
$ret[$label][$type . '+' . $key] = $bundle['label'];
}
}
}
}
return $ret;
}