ProductListBuilder.php in Commerce Core 8.2
File
modules/product/src/ProductListBuilder.php
View source
<?php
namespace Drupal\commerce_product;
use Drupal\commerce_product\Entity\ProductType;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityListBuilder;
use Drupal\Core\Url;
class ProductListBuilder extends EntityListBuilder {
public function buildHeader() {
$header['title'] = $this
->t('Title');
$header['type'] = $this
->t('Type');
$header['status'] = $this
->t('Status');
return $header + parent::buildHeader();
}
public function buildRow(EntityInterface $entity) {
$product_type = ProductType::load($entity
->bundle());
$row['title']['data'] = [
'#type' => 'link',
'#title' => $entity
->label(),
] + $entity
->toUrl()
->toRenderArray();
$row['type'] = $product_type
->label();
$row['status'] = $entity
->isPublished() ? $this
->t('Published') : $this
->t('Unpublished');
return $row + parent::buildRow($entity);
}
protected function getDefaultOperations(EntityInterface $entity) {
$operations = parent::getDefaultOperations($entity);
$variations_url = new Url('entity.commerce_product_variation.collection', [
'commerce_product' => $entity
->id(),
]);
if ($variations_url
->access()) {
$operations['variations'] = [
'title' => $this
->t('Variations'),
'weight' => 20,
'url' => $variations_url,
'query' => [
'destination' => NULL,
],
];
}
return $operations;
}
}