ImageAPIOptimizePipelineListBuilder.php in Image Optimize (or ImageAPI Optimize) 8.2
File
src/ImageAPIOptimizePipelineListBuilder.php
View source
<?php
namespace Drupal\imageapi_optimize;
use Drupal\Core\Config\Entity\ConfigEntityListBuilder;
use Drupal\Core\Config\Entity\ConfigEntityStorageInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Form\FormBuilderInterface;
use Drupal\Core\Url;
use Symfony\Component\DependencyInjection\ContainerInterface;
class ImageAPIOptimizePipelineListBuilder extends ConfigEntityListBuilder {
protected $formBuilder;
public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) {
return new static($entity_type, $container
->get('entity.manager')
->getStorage($entity_type
->id()), $container
->get('form_builder'));
}
public function __construct(EntityTypeInterface $entity_type, ConfigEntityStorageInterface $storage, FormBuilderInterface $form_builder) {
$this->entityTypeId = $entity_type
->id();
$this->storage = $storage;
$this->entityType = $entity_type;
$this->formBuilder = $form_builder;
}
public function buildHeader() {
$header['label'] = $this
->t('Pipeline name');
return $header + parent::buildHeader();
}
public function buildRow(EntityInterface $entity) {
$row['label'] = $entity
->label();
return $row + parent::buildRow($entity);
}
public function getDefaultOperations(EntityInterface $entity) {
$flush = [
'title' => $this
->t('Flush'),
'weight' => 200,
'url' => $entity
->toUrl('flush-form'),
];
$operations = parent::getDefaultOperations($entity) + [
'flush' => $flush,
];
if (isset($operations['edit'])) {
$operations['edit']['url'] = $entity
->toUrl('edit-form');
}
return $operations;
}
public function render() {
$build = parent::render();
$build['table']['#empty'] = $this
->t('There are currently no pipelines. <a href=":url">Add a new one</a>.', [
':url' => Url::fromRoute('imageapi_optimize.pipeline_add')
->toString(),
]);
$build['config_form'] = $this->formBuilder
->getForm('Drupal\\imageapi_optimize\\Form\\ImageAPIOptimizeDefaultPipelineConfigForm');
return $build;
}
}