You are here

public static function ViewsAddButtonUtilities::createPluginList in Views Add Button 2.0.x

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

Build Bundle Type List.

1 call to ViewsAddButtonUtilities::createPluginList()
ViewsAddButtonField::buildOptionsForm in src/Plugin/views/field/ViewsAddButtonField.php
Provide the options form.

File

src/ViewsAddButtonUtilities.php, line 20

Class

ViewsAddButtonUtilities
Class ViewsAddButtonUtilities @package Drupal\views_add_button

Namespace

Drupal\views_add_button

Code

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