You are here

public function ViewsAddButtonArea::createEntityBundleList in Views Add Button 8

Same name and namespace in other branches
  1. 2.0.x src/Plugin/views/area/ViewsAddButtonArea.php \Drupal\views_add_button\Plugin\views\area\ViewsAddButtonArea::createEntityBundleList()

Build Bundle Type List.

1 call to ViewsAddButtonArea::createEntityBundleList()
ViewsAddButtonArea::buildOptionsForm in src/Plugin/views/area/ViewsAddButtonArea.php
Provide the options form.

File

src/Plugin/views/area/ViewsAddButtonArea.php, line 64

Class

ViewsAddButtonArea
Defines a views area plugin.

Namespace

Drupal\views_add_button\Plugin\views\area

Code

public 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;
}