ConfigPagesTypeListBuilder.php in Config Pages 8.2
File
src/ConfigPagesTypeListBuilder.php
View source
<?php
namespace Drupal\config_pages;
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 {
private $context;
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');
$header['token'] = t('Exposed as tokens');
return $header + parent::buildHeader();
}
public function buildRow(EntityInterface $entity) {
$row['type'] = $entity
->toLink(NULL, 'edit-form');
$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);
$row['token'] = !empty($entity->token) ? 'Exposed' : 'Hidden';
return $row + parent::buildRow($entity);
}
protected function getTitle() {
return $this
->t('Config page types');
}
}