View source
<?php
namespace Drupal\devel\Controller;
use Drupal\Component\Serialization\Json;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Url;
use Drupal\devel\DevelDumperManagerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
class EntityTypeInfoController extends ControllerBase {
protected $dumper;
public function __construct(DevelDumperManagerInterface $dumper) {
$this->dumper = $dumper;
}
public static function create(ContainerInterface $container) {
return new static($container
->get('devel.dumper'));
}
public function entityTypeList() {
$headers = [
$this
->t('ID'),
$this
->t('Name'),
$this
->t('Provider'),
$this
->t('Class'),
$this
->t('Operations'),
];
$rows = [];
foreach ($this
->entityTypeManager()
->getDefinitions() as $entity_type_id => $entity_type) {
$row['id'] = [
'data' => $entity_type
->id(),
'filter' => TRUE,
];
$row['name'] = [
'data' => $entity_type
->getLabel(),
'filter' => TRUE,
];
$row['provider'] = [
'data' => $entity_type
->getProvider(),
'filter' => TRUE,
];
$row['class'] = [
'data' => $entity_type
->getClass(),
'filter' => TRUE,
];
$row['operations']['data'] = [
'#type' => 'operations',
'#links' => [
'devel' => [
'title' => $this
->t('Devel'),
'url' => Url::fromRoute('devel.entity_info_page.detail', [
'entity_type_id' => $entity_type_id,
]),
'attributes' => [
'class' => [
'use-ajax',
],
'data-dialog-type' => 'modal',
'data-dialog-options' => Json::encode([
'width' => 700,
'minHeight' => 500,
]),
],
],
],
];
$rows[$entity_type_id] = $row;
}
ksort($rows);
$output['entities'] = [
'#type' => 'devel_table_filter',
'#filter_label' => $this
->t('Search'),
'#filter_placeholder' => $this
->t('Enter entity type id, provider or class'),
'#filter_description' => $this
->t('Enter a part of the entity type id, provider or class to filter by.'),
'#header' => $headers,
'#rows' => $rows,
'#empty' => $this
->t('No entity types found.'),
'#sticky' => TRUE,
'#attributes' => [
'class' => [
'devel-entity-type-list',
],
],
];
return $output;
}
public function entityTypeDetail($entity_type_id) {
if (!($entity_type = $this
->entityTypeManager()
->getDefinition($entity_type_id, FALSE))) {
throw new NotFoundHttpException();
}
return $this->dumper
->exportAsRenderable($entity_type, $entity_type_id);
}
}