paragraphs_sets-8.x-2.x-dev/src/Controller/ParagraphsSetListBuilder.php
src/Controller/ParagraphsSetListBuilder.php
<?php
namespace Drupal\paragraphs_sets\Controller;
use Drupal\Core\Config\Entity\ConfigEntityListBuilder;
use Drupal\Core\Entity\EntityInterface;
/**
* Provides a listing of ParagraphsSet.
*/
class ParagraphsSetListBuilder extends ConfigEntityListBuilder {
/**
* {@inheritdoc}
*
* @return array<int|string, mixed>
* A render array structure of header data.
*/
public function buildHeader(): array {
$header['icon_file'] = [
'data' => $this->t('Icon'),
];
$header['label'] = $this->t('Label');
$header['id'] = $this->t('Machine name');
$header['description'] = $this->t('Description');
return $header + parent::buildHeader();
}
/**
* {@inheritdoc}
*
* @return array<int|string, mixed>
* A render array structure of fields for this entity.
*/
public function buildRow(EntityInterface $entity): array {
/** @var \Drupal\paragraphs_sets\ParagraphsSetInterface $entity */
$row['icon_file'] = [];
if ($icon_url = $entity->getIconUrl()) {
$row['icon_file']['class'][] = 'paragraphs-set-icon';
$row['icon_file']['data'] = [
'#theme' => 'image',
'#uri' => $icon_url,
'#width' => 32,
'#height' => 32,
];
}
$row['label'] = $entity->label();
$row['id'] = $entity->id();
$row['description']['data'] = ['#markup' => $entity->getDescription()];
return $row + parent::buildRow($entity);
}
/**
* {@inheritdoc}
*
* @return array<string, array<string, string|int>>
* List of supported operations.
*/
public function getDefaultOperations(EntityInterface $entity) {
/** @var \Drupal\field\FieldConfigInterface $entity */
/** @var array<string, array<string, string|int>> $operations */
$operations = parent::getDefaultOperations($entity);
if (isset($operations['edit'])) {
$operations['edit']['weight'] = 30;
}
return $operations;
}
}
