Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 22 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
| ContactDetailTypeListBuilder | |
0.00% |
0 / 22 |
|
0.00% |
0 / 4 |
30 | |
0.00% |
0 / 1 |
| buildHeader | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
2 | |||
| buildRow | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
2 | |||
| render | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
2 | |||
| getDefaultOperations | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Drupal\crm; |
| 6 | |
| 7 | use Drupal\Core\Config\Entity\ConfigEntityListBuilder; |
| 8 | use Drupal\Core\Entity\EntityInterface; |
| 9 | use Drupal\Core\Url; |
| 10 | |
| 11 | /** |
| 12 | * Defines a class to build a listing of CRM contact detail type entities. |
| 13 | * |
| 14 | * @see \Drupal\crm\Entity\ContactDetailType |
| 15 | */ |
| 16 | class ContactDetailTypeListBuilder extends ConfigEntityListBuilder { |
| 17 | |
| 18 | /** |
| 19 | * {@inheritdoc} |
| 20 | */ |
| 21 | public function buildHeader(): array { |
| 22 | $header['label'] = $this->t('Label'); |
| 23 | $header['description'] = [ |
| 24 | 'data' => $this->t('Description'), |
| 25 | 'class' => [RESPONSIVE_PRIORITY_MEDIUM], |
| 26 | ]; |
| 27 | |
| 28 | return $header + parent::buildHeader(); |
| 29 | } |
| 30 | |
| 31 | /** |
| 32 | * {@inheritdoc} |
| 33 | */ |
| 34 | public function buildRow(EntityInterface $entity): array { |
| 35 | $row['label'] = [ |
| 36 | 'data' => $entity->label(), |
| 37 | 'class' => ['menu-label'], |
| 38 | ]; |
| 39 | $row['description']['data'] = ['#markup' => $entity->getDescription()]; |
| 40 | |
| 41 | return $row + parent::buildRow($entity); |
| 42 | } |
| 43 | |
| 44 | /** |
| 45 | * {@inheritdoc} |
| 46 | */ |
| 47 | public function render(): array { |
| 48 | $build = parent::render(); |
| 49 | |
| 50 | $build['table']['#empty'] = $this->t( |
| 51 | 'No CRM contact detail types available. <a href=":link">Add CRM contact detail type</a>.', |
| 52 | [':link' => Url::fromRoute('entity.crm_contact_detail_type.add_form')->toString()], |
| 53 | ); |
| 54 | |
| 55 | return $build; |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * {@inheritdoc} |
| 60 | */ |
| 61 | public function getDefaultOperations(EntityInterface $entity) { |
| 62 | $operations = parent::getDefaultOperations($entity); |
| 63 | // Place the edit operation after the operations added by field_ui.module |
| 64 | // which have the weights 15, 20, 25. |
| 65 | if (isset($operations['edit'])) { |
| 66 | $operations['edit']['weight'] = 30; |
| 67 | } |
| 68 | return $operations; |
| 69 | } |
| 70 | |
| 71 | } |