Newer
Older
Alex Pott
committed
<?php
/**
* @file
* Contains \Drupal\image\ImageStyleListBuilder.
Alex Pott
committed
*/
namespace Drupal\image;
use Drupal\Core\Config\Entity\ConfigEntityListBuilder;
Alex Pott
committed
use Drupal\Core\Entity\EntityInterface;
catch
committed
use Drupal\Core\Entity\EntityStorageInterface;
Alex Pott
committed
use Drupal\Core\Entity\EntityTypeInterface;
Angie Byron
committed
use Drupal\Core\Routing\UrlGeneratorInterface;
Alex Pott
committed
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Defines a class to build a listing of image style entities.
*
* @see \Drupal\image\Entity\ImageStyle
Alex Pott
committed
*/
class ImageStyleListBuilder extends ConfigEntityListBuilder {
Alex Pott
committed
/**
* The URL generator.
*
Angie Byron
committed
* @var \Drupal\Core\Routing\UrlGeneratorInterface
Alex Pott
committed
*/
protected $urlGenerator;
/**
* Constructs a new ImageStyleListBuilder object.
Alex Pott
committed
*
Alex Pott
committed
* @param EntityTypeInterface $entity_type
* The entity type definition.
catch
committed
* @param \Drupal\Core\Entity\EntityStorageInterface $image_style_storage
* The image style entity storage class.
Angie Byron
committed
* @param \Drupal\Core\Routing\UrlGeneratorInterface $url_generator
Alex Pott
committed
* The URL generator.
*/
catch
committed
public function __construct(EntityTypeInterface $entity_type, EntityStorageInterface $image_style_storage, UrlGeneratorInterface $url_generator) {
Alex Pott
committed
parent::__construct($entity_type, $image_style_storage);
Alex Pott
committed
$this->urlGenerator = $url_generator;
}
/**
* {@inheritdoc}
*/
Alex Pott
committed
public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) {
Alex Pott
committed
return new static(
Alex Pott
committed
$entity_type,
catch
committed
$container->get('entity.manager')->getStorage($entity_type->id()),
Alex Pott
committed
$container->get('url_generator'),
$container->get('string_translation')
);
}
/**
* {@inheritdoc}
*/
public function buildHeader() {
Angie Byron
committed
$header['label'] = $this->t('Style name');
return $header + parent::buildHeader();
Alex Pott
committed
}
/**
* {@inheritdoc}
*/
public function buildRow(EntityInterface $entity) {
$row['label'] = $entity->label();
return $row + parent::buildRow($entity);
Alex Pott
committed
}
Alex Pott
committed
/**
* {@inheritdoc}
*/
public function getDefaultOperations(EntityInterface $entity) {
Alex Pott
committed
$flush = array(
'title' => t('Flush'),
'weight' => 200,
'url' => $entity->urlInfo('flush-form'),
);
Alex Pott
committed
return parent::getDefaultOperations($entity) + array(
'flush' => $flush,
);
Alex Pott
committed
}
Alex Pott
committed
/**
* {@inheritdoc}
*/
public function render() {
$build = parent::render();
Angie Byron
committed
$build['#empty'] = $this->t('There are currently no styles. <a href="!url">Add a new one</a>.', array(
'!url' => $this->urlGenerator->generateFromRoute('image.style_add'),