Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
40.00% covered (danger)
40.00%
2 / 5
33.33% covered (danger)
33.33%
1 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
ContactDetailType
40.00% covered (danger)
40.00%
2 / 5
33.33% covered (danger)
33.33%
1 / 3
4.94
0.00% covered (danger)
0.00%
0 / 1
 getDescription
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 setDescription
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 isLocked
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3declare(strict_types=1);
4
5namespace Drupal\crm\Entity;
6
7use Drupal\Core\Config\Entity\ConfigEntityBundleBase;
8use Drupal\Core\Entity\Attribute\ConfigEntityType;
9use Drupal\Core\Entity\EntityDeleteForm;
10use Drupal\Core\Entity\Routing\AdminHtmlRouteProvider;
11use Drupal\Core\StringTranslation\TranslatableMarkup;
12use Drupal\crm\CrmContactDetailTypeInterface;
13use Drupal\crm\ContactDetailTypeAccessControlHandler;
14use Drupal\crm\ContactDetailTypeListBuilder;
15use Drupal\crm\Form\ContactDetailTypeForm;
16
17/**
18 * Defines the CRM Contact Detail type configuration entity.
19 */
20#[ConfigEntityType(
21  id: 'crm_contact_detail_type',
22  label: new TranslatableMarkup('CRM Contact Detail type'),
23  label_collection: new TranslatableMarkup('CRM Contact Detail types'),
24  label_singular: new TranslatableMarkup('crm contact detail type'),
25  label_plural: new TranslatableMarkup('crm contact details types'),
26  label_count: [
27    'singular' => '@count crm contact details type',
28    'plural' => '@count crm contact details types',
29  ],
30  handlers: [
31    'access' => ContactDetailTypeAccessControlHandler::class,
32    'form' => [
33      'add' => ContactDetailTypeForm::class,
34      'edit' => ContactDetailTypeForm::class,
35      'delete' => EntityDeleteForm::class,
36    ],
37    'list_builder' => ContactDetailTypeListBuilder::class,
38    'route_provider' => [
39      'html' => AdminHtmlRouteProvider::class,
40    ],
41  ],
42  admin_permission: 'administer crm',
43  bundle_of: 'crm_contact_detail',
44  config_prefix: 'crm_contact_detail_type',
45  entity_keys: [
46    'id' => 'id',
47    'label' => 'label',
48    'uuid' => 'uuid',
49  ],
50  links: [
51    'add-form' => '/admin/structure/crm/contact-detail-types/add',
52    'edit-form' => '/admin/structure/crm/contact-detail-types/manage/{crm_contact_detail_type}',
53    'delete-form' => '/admin/structure/crm/contact-detail-types/manage/{crm_contact_detail_type}/delete',
54    'collection' => '/admin/structure/crm/contact-detail-types',
55  ],
56  config_export: [
57    'id',
58    'label',
59    'description',
60    'uuid',
61  ],
62)]
63class ContactDetailType extends ConfigEntityBundleBase implements CrmContactDetailTypeInterface {
64
65  /**
66   * The machine name of this crm contact detail type.
67   */
68  protected string $id;
69
70  /**
71   * The human-readable name of the crm contact detail type.
72   */
73  protected string $label;
74
75  /**
76   * The description of the crm contact detail type.
77   *
78   * @var string|null
79   */
80  protected ?string $description;
81
82  /**
83   * {@inheritdoc}
84   */
85  public function getDescription() {
86    return $this->description ?? '';
87  }
88
89  /**
90   * {@inheritdoc}
91   */
92  public function setDescription($description) {
93    $this->description = $description;
94
95    return $this;
96  }
97
98  /**
99   * Is the detail type locked?
100   */
101  public function isLocked() {
102    $locked = \Drupal::state()->get('crm.contact_detail_type.locked');
103    return $locked[$this->id()] ?? FALSE;
104  }
105
106}