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
ContactMethodType
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\Access\ContactMethodTypeAccessControlHandler;
13use Drupal\crm\Form\ContactMethodTypeForm;
14use Drupal\crm\ListBuilder\ContactMethodTypeListBuilder;
15
16/**
17 * Defines the CRM Contact Method type configuration entity.
18 */
19#[ConfigEntityType(
20  id: 'crm_contact_method_type',
21  label: new TranslatableMarkup('Contact Method type'),
22  label_collection: new TranslatableMarkup('Contact Method types'),
23  label_singular: new TranslatableMarkup('contact method type'),
24  label_plural: new TranslatableMarkup('contact method types'),
25  label_count: [
26    'singular' => '@count contact method type',
27    'plural' => '@count contact method types',
28  ],
29  handlers: [
30    'access' => ContactMethodTypeAccessControlHandler::class,
31    'form' => [
32      'add' => ContactMethodTypeForm::class,
33      'edit' => ContactMethodTypeForm::class,
34      'delete' => EntityDeleteForm::class,
35    ],
36    'list_builder' => ContactMethodTypeListBuilder::class,
37    'route_provider' => [
38      'html' => AdminHtmlRouteProvider::class,
39    ],
40  ],
41  admin_permission: 'administer crm',
42  bundle_of: 'crm_contact_method',
43  config_prefix: 'crm_contact_method_type',
44  entity_keys: [
45    'id' => 'id',
46    'label' => 'label',
47    'uuid' => 'uuid',
48  ],
49  links: [
50    'add-form' => '/admin/structure/crm/contact-method-types/add',
51    'edit-form' => '/admin/structure/crm/contact-method-types/manage/{crm_contact_method_type}',
52    'delete-form' => '/admin/structure/crm/contact-method-types/manage/{crm_contact_method_type}/delete',
53    'collection' => '/admin/structure/crm/contact-method-types',
54  ],
55  config_export: [
56    'id',
57    'label',
58    'description',
59    'uuid',
60  ],
61)]
62class ContactMethodType extends ConfigEntityBundleBase implements ContactMethodTypeInterface {
63
64  /**
65   * The machine name of this crm contact method type.
66   */
67  protected string $id;
68
69  /**
70   * The human-readable name of the crm contact method type.
71   */
72  protected string $label;
73
74  /**
75   * The description of the crm contact method type.
76   *
77   * @var string|null
78   */
79  protected ?string $description;
80
81  /**
82   * {@inheritdoc}
83   */
84  public function getDescription() {
85    return $this->description ?? '';
86  }
87
88  /**
89   * {@inheritdoc}
90   */
91  public function setDescription($description) {
92    $this->description = $description;
93
94    return $this;
95  }
96
97  /**
98   * Is the method type locked?
99   */
100  public function isLocked() {
101    $locked = \Drupal::state()->get('crm.contact_method_type.locked');
102    return $locked[$this->id()] ?? FALSE;
103  }
104
105}