3 namespace Drupal\webprofiler\DataCollector;
5 use Drupal\block\Entity\Block;
6 use Drupal\Core\Entity\EntityStorageInterface;
7 use Drupal\Core\Entity\EntityTypeManagerInterface;
8 use Drupal\Core\StringTranslation\StringTranslationTrait;
9 use Drupal\webprofiler\DrupalDataCollectorInterface;
10 use Drupal\webprofiler\Entity\EntityDecorator;
11 use Symfony\Component\HttpFoundation\Request;
12 use Symfony\Component\HttpFoundation\Response;
13 use Symfony\Component\HttpKernel\DataCollector\DataCollector;
16 * Class BlocksDataCollector
18 class BlocksDataCollector extends DataCollector implements DrupalDataCollectorInterface {
20 use StringTranslationTrait, DrupalDataCollectorTrait;
23 * @var \Drupal\Core\Entity\EntityManagerInterface
25 private $entityManager;
28 * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityManager
30 public function __construct(EntityTypeManagerInterface $entityManager) {
31 $this->entityManager = $entityManager;
33 $this->data['blocks']['loaded'] = [];
34 $this->data['blocks']['rendered'] = [];
40 public function collect(Request $request, Response $response, \Exception $exception = NULL) {
41 $storage = $this->entityManager->getStorage('block');
43 $loaded = $this->entityManager->getLoaded('config', 'block');
44 $rendered = $this->entityManager->getRendered('block');
47 $this->data['blocks']['loaded'] = $this->getBlocksData($loaded, $storage);
52 $this->data['blocks']['rendered'] = $this->getBlocksData($rendered, $storage);
59 public function getRenderedBlocks() {
60 return $this->data['blocks']['rendered'];
66 public function getRenderedBlocksCount() {
67 return count($this->getRenderedBlocks());
73 public function getLoadedBlocks() {
74 return $this->data['blocks']['loaded'];
80 public function getLoadedBlocksCount() {
81 return count($this->getLoadedBlocks());
87 public function getName() {
94 public function getTitle() {
95 return $this->t('Blocks');
101 public function getPanelSummary() {
102 return $this->t('Loaded: @loaded, rendered: @rendered', [
103 '@loaded' => $this->getLoadedBlocksCount(),
104 '@rendered' => $this->getRenderedBlocksCount()
111 public function getIcon() {
112 return 'iVBORw0KGgoAAAANSUhEUgAAABUAAAAcCAYAAACOGPReAAAAGXRFWHRTb2Z0d2FyZQ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Q9InhtcC5kaWQ6MDQ4MDExNzQwNzIwNjgxMThGNjJDQjYyNDQ2Nzc5MEQiLz4gPC9yZGY6RGVzY3JpcHRpb24+IDwvcmRmOlJERj4gPC94OnhtcG1ldGE+IDw/eHBhY2tldCBlbmQ9InIiPz68h+kGAAAAWElEQVR42mL8//8/A7UBEwMNwAg3lAVEODg4UCW2Dhw4wDgapgyMtEj8eCMKFPCkyI1GFCJMiUnQVDUUX0SNllK4wxRf+JAdUeQUfaMRRd+ib4SHKUCAAQAMcyf8vLAstgAAAABJRU5ErkJggg==';
121 private function getBlocksData(EntityDecorator $decorator, EntityStorageInterface $storage) {
124 /** @var \Drupal\block\BlockInterface $block */
125 foreach ($decorator->getEntities() as $block) {
126 /** @var Block $entity */
127 if (null !== $block && $entity = $storage->load($block->get('id'))) {
130 if ($entity->hasLinkTemplate('edit-form')) {
131 $route = $entity->toUrl('edit-form')->toString();
134 $id = $block->get('id');
137 'region' => $block->getRegion(),
138 'status' => $block->get('status'),
139 'theme' => $block->getTheme(),
140 'plugin' => $block->get('plugin'),
141 'settings' => $block->get('settings'),