BundleField.php in Display Suite 8.3
File
src/Plugin/Derivative/BundleField.php
View source
<?php
namespace Drupal\ds\Plugin\Derivative;
use Drupal\Component\Plugin\Derivative\DeriverBase;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class BundleField extends DeriverBase implements ContainerDeriverInterface {
protected $derivatives = [];
protected $basePluginId;
protected $entityTypeManager;
public function __construct($base_plugin_id, EntityTypeManagerInterface $entity_type_manager) {
$this->basePluginId = $base_plugin_id;
$this->entityTypeManager = $entity_type_manager;
}
public static function create(ContainerInterface $container, $base_plugin_id) {
return new static($base_plugin_id, $container
->get('entity_type.manager'));
}
public function getDerivativeDefinitions($base_plugin_definition) {
foreach ($this->entityTypeManager
->getDefinitions() as $entity_type_id => $entity_type) {
$base_table = $entity_type
->getBaseTable();
if ($entity_type
->get('field_ui_base_route') && !empty($base_table)) {
$this->derivatives[$entity_type_id] = $base_plugin_definition;
$this->derivatives[$entity_type_id] += [
'provider' => $entity_type_id,
'title' => 'Bundle name',
'entity_type' => $entity_type_id,
];
}
}
return $this->derivatives;
}
}