CheckListBuilder.php in Production check & Production monitor 8
File
src/CheckListBuilder.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\ProdCheckPluginManager;
use Symfony\Component\DependencyInjection\ContainerInterface;
class CheckListBuilder extends ConfigEntityListBuilder {
protected $hasConfigurableChecks = FALSE;
protected $processorManager;
public function __construct(EntityTypeInterface $entity_type, EntityStorageInterface $storage, ProdCheckPluginManager $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'));
}
public function load() {
$entities = parent::load();
foreach ($entities as $entity) {
if ($entity
->isConfigurable()) {
$this->hasConfigurableChecks = TRUE;
continue;
}
}
return $entities;
}
public function buildRow(EntityInterface $entity) {
$row['label'] = $entity
->label();
if ($this->hasConfigurableChecks) {
$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['check_header']['#markup'] = '<h3>' . t('Available production checks:') . '</h3>';
$build['check_table'] = parent::render();
return $build;
}
}
Classes
Name |
Description |
CheckListBuilder |
Defines a class to build a listing of prod check processor entities. |