You are here

public function ViewsAddButtonArea::createPluginList in Views Add Button 2.0.x

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

Build Bundle Type List.

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

File

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

Class

ViewsAddButtonArea
Defines a views area plugin.

Namespace

Drupal\views_add_button\Plugin\views\area

Code

public function createPluginList() {
  $plugin_manager = \Drupal::service('plugin.manager.views_add_button');
  $plugin_definitions = $plugin_manager
    ->getDefinitions();
  $options = [
    'Any Entity' => [],
  ];
  $entity_info = \Drupal::entityTypeManager()
    ->getDefinitions();
  foreach ($plugin_definitions as $pd) {
    $label = $pd['label'];
    if ($pd['label'] instanceof TranslatableMarkup) {
      $label = $pd['label']
        ->render();
    }
    $type_info = isset($pd['target_entity']) && isset($entity_info[$pd['target_entity']]) ? $entity_info[$pd['target_entity']] : 'default';
    $type_label = t('Any Entity');
    if ($type_info instanceof ContentEntityType) {
      $type_label = $type_info
        ->getLabel();
    }
    if ($type_label instanceof TranslatableMarkup) {
      $type_label = $type_label
        ->render();
    }
    $options[$type_label][$pd['id']] = $label;
  }
  return $options;
}