arch-8.x-1.x-dev/modules/product/src/Entity/Builder/ProductTypeListBuilder.php
modules/product/src/Entity/Builder/ProductTypeListBuilder.php
<?php
namespace Drupal\arch_product\Entity\Builder;
use Drupal\Core\Config\Entity\ConfigEntityListBuilder;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Url;
/**
* Defines a class to build a listing of product type entities.
*
* @see \Drupal\arch_product\Entity\ProductType
*/
class ProductTypeListBuilder extends ConfigEntityListBuilder {
/**
* {@inheritdoc}
*/
public function buildHeader() {
$header['title'] = $this->t('Name', [], ['context' => 'arch_product_type']);
$header['description'] = [
'data' => $this->t('Description', [], ['context' => 'arch_product_type']),
'class' => [RESPONSIVE_PRIORITY_MEDIUM],
];
return $header + parent::buildHeader();
}
/**
* {@inheritdoc}
*/
public function buildRow(EntityInterface $entity) {
$row['title'] = [
'data' => $entity->label(),
'class' => ['menu-label'],
];
$row['description']['data'] = ['#markup' => $entity->getDescription()];
return $row + parent::buildRow($entity);
}
/**
* {@inheritdoc}
*/
public function getDefaultOperations(EntityInterface $entity) {
$operations = parent::getDefaultOperations($entity);
// Place the edit operation after the operations added by field_ui.module
// which have the weights 15, 20, 25.
if (isset($operations['edit'])) {
$operations['edit']['weight'] = 30;
}
return $operations;
}
/**
* {@inheritdoc}
*/
public function render() {
$build = parent::render();
$build['table']['#empty'] = $this->t(
'No product types available. <a href=":link">Add product type</a>.',
[':link' => Url::fromRoute('product.type_add')->toString()],
['context' => 'arch_product_type']
);
return $build;
}
}
