Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 14 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
ContactDetailBase | |
0.00% |
0 / 14 |
|
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 1 |
getLabelWithoutType | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
label | |
0.00% |
0 / 14 |
|
0.00% |
0 / 1 |
6 |
1 | <?php |
2 | |
3 | declare(strict_types=1); |
4 | |
5 | namespace Drupal\crm\Entity\ContactDetail; |
6 | |
7 | use Drupal\Core\StringTranslation\StringTranslationTrait; |
8 | use Drupal\crm\Entity\ContactDetail; |
9 | |
10 | /** |
11 | * A base bundle class for crm_contact_detail entities. |
12 | */ |
13 | abstract class ContactDetailBase extends ContactDetail { |
14 | |
15 | use StringTranslationTrait; |
16 | |
17 | /** |
18 | * Gets the entity label without the type. |
19 | * |
20 | * @return string |
21 | * The label without the type. |
22 | */ |
23 | abstract public function getLabelWithoutType(): string; |
24 | |
25 | /** |
26 | * {@inheritdoc} |
27 | */ |
28 | public function label() { |
29 | if ($this->get('type')->isEmpty()) { |
30 | return $this->getLabelWithoutType(); |
31 | } |
32 | |
33 | /** @var \Drupal\Core\Entity\Plugin\DataType\EntityReference $detail_type_entity_reference */ |
34 | $detail_type_entity_reference = $this |
35 | ->get('type') |
36 | ->first() |
37 | ->get('entity'); |
38 | |
39 | /** @var \Drupal\crm\CrmDetailTypeInterface $detail_type_entity */ |
40 | $detail_type_entity = $detail_type_entity_reference |
41 | ->getTarget() |
42 | ->getValue(); |
43 | |
44 | $type = $detail_type_entity?->label(); |
45 | |
46 | return $this->t('@type: @label', [ |
47 | '@type' => $type, |
48 | '@label' => $this->getLabelWithoutType(), |
49 | ]); |
50 | } |
51 | |
52 | } |