ProcessorListBuilder.php in Production check & Production monitor 8
File
src/ProcessorListBuilder.php
View source
<?php
namespace Drupal\prod_check;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Config\Entity\ConfigEntityListBuilder;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\prod_check\Plugin\ProdCheckProcessorPluginManager;
use Symfony\Component\DependencyInjection\ContainerInterface;
class ProcessorListBuilder extends ConfigEntityListBuilder {
protected $hasConfigurableProcessors = FALSE;
protected $processorManager;
public function __construct(EntityTypeInterface $entity_type, EntityStorageInterface $storage, ProdCheckProcessorPluginManager $manager) {
parent::__construct($entity_type, $storage);
$this->processorManager = $manager;
}
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.prod_check_processor'));
}
public function load() {
$entities = parent::load();
foreach ($entities as $entity) {
if ($entity
->isConfigurable()) {
$this->hasConfigurableProcessors = TRUE;
continue;
}
}
return $entities;
}
public function buildRow(EntityInterface $entity) {
$row['label'] = $entity
->label();
if ($this->hasConfigurableProcessors) {
$row += parent::buildRow($entity);
}
return $row;
}
public function buildHeader() {
$header = [
'label' => t('Label'),
] + parent::buildHeader();
return $header;
}
public function getDefaultOperations(EntityInterface $entity) {
$operations = $entity
->isConfigurable() ? parent::getDefaultOperations($entity) : [];
unset($operations['delete']);
if (isset($operations['edit'])) {
$operations['edit']['title'] = t('Configure');
}
return $operations;
}
public function render() {
$build['processor_header']['#markup'] = '<h3>' . t('Available processors:') . '</h3>';
$build['processor_table'] = parent::render();
return $build;
}
}