public function PromotionListBuilder::buildRow in Commerce Core 8.2
Builds a row for an entity in the entity listing.
Parameters
\Drupal\Core\Entity\EntityInterface $entity: The entity for this row of the list.
Return value
array A render array structure of fields for this entity.
Overrides EntityListBuilder::buildRow
See also
\Drupal\Core\Entity\EntityListBuilder::render()
1 call to PromotionListBuilder::buildRow()
- PromotionListBuilder::buildForm in modules/
promotion/ src/ PromotionListBuilder.php - Form constructor.
File
- modules/
promotion/ src/ PromotionListBuilder.php, line 162
Class
- PromotionListBuilder
- Defines the list builder for promotions.
Namespace
Drupal\commerce_promotionCode
public function buildRow(EntityInterface $entity) {
$current_usage = $this->usageCounts[$entity
->id()];
$usage_limit = $entity
->getUsageLimit();
$usage_limit = $usage_limit ?: $this
->t('Unlimited');
$customer_limit = $entity
->getCustomerUsageLimit();
$customer_limit = $customer_limit ?: $this
->t('Unlimited');
/** @var \Drupal\commerce_promotion\Entity\PromotionInterface $entity */
$row['#attributes']['class'][] = 'draggable';
$row['#weight'] = $entity
->getWeight();
$row['name'] = $entity
->label();
$row['usage'] = $current_usage . ' / ' . $usage_limit;
$row['customer_limit'] = $customer_limit;
$row['start_date'] = $entity
->getStartDate()
->format('M jS Y H:i:s');
$row['end_date'] = $entity
->getEndDate() ? $entity
->getEndDate()
->format('M jS Y H:i:s') : '—';
if ($this->hasTableDrag && $entity
->isEnabled()) {
$row['weight'] = [
'#type' => 'weight',
'#title' => $this
->t('Weight for @title', [
'@title' => $entity
->label(),
]),
'#title_display' => 'invisible',
'#default_value' => $entity
->getWeight(),
'#attributes' => [
'class' => [
'weight',
],
],
];
}
return $row + parent::buildRow($entity);
}