ConfigPagesTypeListBuilder.php in Config Pages 8
File
src/ConfigPagesTypeListBuilder.php
View source
<?php
namespace Drupal\config_pages;
use Drupal\Component\Utility\Xss;
use Drupal\Core\Config\Entity\ConfigEntityListBuilder;
use Drupal\Core\Entity\EntityInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Entity\EntityStorageInterface;
class ConfigPagesTypeListBuilder extends ConfigEntityListBuilder {
public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) {
return new static($entity_type, $container
->get('entity_type.manager')
->getStorage($entity_type
->id()), $container
->get('plugin.manager.config_pages_context'));
}
public function __construct(EntityTypeInterface $entity_type, EntityStorageInterface $storage, ConfigPagesContextManagerInterface $context) {
$this->entityTypeId = $entity_type
->id();
$this->storage = $storage;
$this->entityType = $entity_type;
$this->context = $context;
}
public function getDefaultOperations(EntityInterface $entity) {
$operations = parent::getDefaultOperations($entity);
if (isset($operations['edit'])) {
$operations['edit']['weight'] = 30;
}
return $operations;
}
public function buildHeader() {
$header['type'] = t('Type');
$header['context'] = t('Context');
return $header + parent::buildHeader();
}
public function buildRow(EntityInterface $entity) {
$row['type'] = $entity
->link();
$contextData = [];
if (!empty($entity->context['group'])) {
foreach ($entity->context['group'] as $context_id => $context_enabled) {
if ($context_enabled) {
$item = $this->context
->getDefinition($context_id);
$context_value = $item['label'];
$contextData[] = $context_value;
}
}
}
$row['context'] = implode(', ', $contextData);
return $row + parent::buildRow($entity);
}
protected function getTitle() {
return $this
->t('Config page types');
}
}