ChannelListBuilder.php in Entity Share 8
File
modules/entity_share_server/src/ChannelListBuilder.php
View source
<?php
namespace Drupal\entity_share_server;
use Drupal\Core\Config\Entity\ConfigEntityListBuilder;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Entity\EntityTypeBundleInfoInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Entity\EntityTypeRepositoryInterface;
use Drupal\Core\Language\LanguageInterface;
use Drupal\Core\Language\LanguageManagerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class ChannelListBuilder extends ConfigEntityListBuilder {
protected $bundleInfos;
protected $entityTypeLabels;
protected $languages;
public function __construct(EntityTypeInterface $entity_type, EntityStorageInterface $storage, EntityTypeBundleInfoInterface $entity_type_bundle_info, EntityTypeRepositoryInterface $entity_type_repository, LanguageManagerInterface $language_manager) {
parent::__construct($entity_type, $storage);
$this->bundleInfos = $entity_type_bundle_info
->getAllBundleInfo();
$this->entityTypeLabels = $entity_type_repository
->getEntityTypeLabels();
$this->languages = $language_manager
->getLanguages(LanguageInterface::STATE_ALL);
}
public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) {
return new static($entity_type, $container
->get('entity.manager')
->getStorage($entity_type
->id()), $container
->get('entity_type.bundle.info'), $container
->get('entity_type.repository'), $container
->get('language_manager'));
}
public function buildHeader() {
$header['label'] = $this
->t('Channel');
$header['entity_type'] = $this
->t('Entity type');
$header['bundle'] = $this
->t('Bundle');
$header['language'] = $this
->t('Language');
return $header + parent::buildHeader();
}
public function buildRow(EntityInterface $entity) {
$entity_type = $entity
->get('channel_entity_type');
$bundle = $entity
->get('channel_bundle');
$row['label'] = $entity
->label() . ' (' . $entity
->id() . ')';
$row['entity_type'] = $this->entityTypeLabels[$entity_type];
$row['bundle'] = $this->bundleInfos[$entity_type][$bundle]['label'];
$row['language'] = $this->languages[$entity
->get('channel_langcode')]
->getName();
return $row + parent::buildRow($entity);
}
}