Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
12.50% covered (danger)
12.50%
1 / 8
14.29% covered (danger)
14.29%
1 / 7
CRAP
0.00% covered (danger)
0.00%
0 / 1
ContactType
12.50% covered (danger)
12.50%
1 / 8
14.29% covered (danger)
14.29%
1 / 7
39.83
0.00% covered (danger)
0.00%
0 / 1
 id
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 isLocked
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getHelp
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 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
 shouldCreateNewRevision
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 setNewRevision
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3namespace Drupal\crm\Entity;
4
5use Drupal\Core\Config\Entity\ConfigEntityBundleBase;
6use Drupal\Core\Entity\Attribute\ConfigEntityType;
7use Drupal\Core\Entity\EntityDeleteForm;
8use Drupal\Core\Entity\Routing\AdminHtmlRouteProvider;
9use Drupal\Core\StringTranslation\TranslatableMarkup;
10use Drupal\crm\ContactTypeAccessControlHandler;
11use Drupal\crm\ContactTypeListBuilder;
12use Drupal\crm\CrmContactTypeInterface;
13use Drupal\crm\Form\ContactTypeForm;
14
15/**
16 * Defines the Contact type configuration entity.
17 */
18#[ConfigEntityType(
19  id: 'crm_contact_type',
20  label: new TranslatableMarkup('Contact type'),
21  label_collection: new TranslatableMarkup('Contact types'),
22  label_singular: new TranslatableMarkup('contact type'),
23  label_plural: new TranslatableMarkup('contacts types'),
24  label_count: [
25    'singular' => '@count contacts type',
26    'plural' => '@count contacts types',
27  ],
28  handlers: [
29    'access' => ContactTypeAccessControlHandler::class,
30    'form' => [
31      'add' => ContactTypeForm::class,
32      'edit' => ContactTypeForm::class,
33      'delete' => EntityDeleteForm::class,
34    ],
35    'list_builder' => ContactTypeListBuilder::class,
36    'route_provider' => [
37      'html' => AdminHtmlRouteProvider::class,
38    ],
39  ],
40  admin_permission: 'administer crm',
41  bundle_of: 'crm_contact',
42  config_prefix: 'crm_contact_type',
43  entity_keys: [
44    'id' => 'id',
45    'label' => 'label',
46    'uuid' => 'uuid',
47  ],
48  links: [
49    'add-form' => '/admin/structure/crm/contact-types/add',
50    'edit-form' => '/admin/structure/crm/contact-types/manage/{crm_contact_type}',
51    'delete-form' => '/admin/structure/crm/contact-types/manage/{crm_contact_type}/delete',
52    'collection' => '/admin/structure/crm/contact-types',
53  ],
54  config_export: [
55    'id',
56    'label',
57    'description',
58    'help',
59    'new_revision',
60    'uuid',
61    'locked',
62  ],
63)]
64class ContactType extends ConfigEntityBundleBase implements CrmContactTypeInterface {
65
66  /**
67   * The machine name of this contact type.
68   *
69   * @var string
70   */
71  protected $id;
72
73  /**
74   * The human-readable name of the contact type.
75   *
76   * @var string
77   */
78  protected $label;
79
80  /**
81   * A description of the contact type.
82   *
83   * @var string|null
84   */
85  protected $description;
86
87  /**
88   * Whether the contact type is locked.
89   *
90   * @var bool
91   */
92  protected $locked = FALSE;
93
94  /**
95   * Help text for the contact type.
96   *
97   * @var string
98   */
99  protected $help;
100
101  /**
102   * Whether a new revision should be created by default.
103   *
104   * @var bool
105   */
106  protected $new_revision = TRUE;
107
108  /**
109   * {@inheritdoc}
110   */
111  public function id() {
112    return $this->id;
113  }
114
115  /**
116   * Is the contact type locked?
117   */
118  public function isLocked() {
119    return $this->locked;
120  }
121
122  /**
123   * {@inheritdoc}
124   */
125  public function getHelp() {
126    return $this->help ?? '';
127  }
128
129  /**
130   * {@inheritdoc}
131   */
132  public function getDescription() {
133    return $this->description ?? '';
134  }
135
136  /**
137   * {@inheritdoc}
138   */
139  public function setDescription($description) {
140    $this->description = $description;
141
142    return $this;
143  }
144
145  /**
146   * {@inheritdoc}
147   */
148  public function shouldCreateNewRevision() {
149    return $this->new_revision;
150  }
151
152  /**
153   * {@inheritdoc}
154   */
155  public function setNewRevision($new_revision) {
156    $this->new_revision = $new_revision;
157  }
158
159}