Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
33.33% |
3 / 9 |
|
28.57% |
2 / 7 |
CRAP | |
0.00% |
0 / 1 |
| ContactType | |
33.33% |
3 / 9 |
|
28.57% |
2 / 7 |
21.52 | |
0.00% |
0 / 1 |
| id | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| isLocked | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| getHelp | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getDescription | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setDescription | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| shouldCreateNewRevision | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setNewRevision | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Drupal\crm\Entity; |
| 4 | |
| 5 | use Drupal\Core\Config\Entity\ConfigEntityBundleBase; |
| 6 | use Drupal\Core\Entity\Attribute\ConfigEntityType; |
| 7 | use Drupal\Core\Entity\EntityDeleteForm; |
| 8 | use Drupal\Core\Entity\Routing\AdminHtmlRouteProvider; |
| 9 | use Drupal\Core\StringTranslation\TranslatableMarkup; |
| 10 | use Drupal\crm\ContactTypeAccessControlHandler; |
| 11 | use Drupal\crm\ContactTypeListBuilder; |
| 12 | use Drupal\crm\CrmContactTypeInterface; |
| 13 | use 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 | 'date', |
| 62 | ], |
| 63 | )] |
| 64 | class 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 | * Help text for the contact type. |
| 89 | * |
| 90 | * @var string |
| 91 | */ |
| 92 | protected $help; |
| 93 | |
| 94 | /** |
| 95 | * Whether a new revision should be created by default. |
| 96 | * |
| 97 | * @var bool |
| 98 | */ |
| 99 | protected $new_revision = TRUE; |
| 100 | |
| 101 | /** |
| 102 | * {@inheritdoc} |
| 103 | */ |
| 104 | public function id() { |
| 105 | return $this->id; |
| 106 | } |
| 107 | |
| 108 | /** |
| 109 | * {@inheritdoc} |
| 110 | */ |
| 111 | public function isLocked() { |
| 112 | $locked = \Drupal::state()->get('crm.contact_type.locked'); |
| 113 | return $locked[$this->id()] ?? FALSE; |
| 114 | } |
| 115 | |
| 116 | /** |
| 117 | * {@inheritdoc} |
| 118 | */ |
| 119 | public function getHelp() { |
| 120 | return $this->help ?? ''; |
| 121 | } |
| 122 | |
| 123 | /** |
| 124 | * {@inheritdoc} |
| 125 | */ |
| 126 | public function getDescription() { |
| 127 | return $this->description ?? ''; |
| 128 | } |
| 129 | |
| 130 | /** |
| 131 | * {@inheritdoc} |
| 132 | */ |
| 133 | public function setDescription($description) { |
| 134 | $this->description = $description; |
| 135 | |
| 136 | return $this; |
| 137 | } |
| 138 | |
| 139 | /** |
| 140 | * {@inheritdoc} |
| 141 | */ |
| 142 | public function shouldCreateNewRevision() { |
| 143 | return $this->new_revision; |
| 144 | } |
| 145 | |
| 146 | /** |
| 147 | * {@inheritdoc} |
| 148 | */ |
| 149 | public function setNewRevision($new_revision) { |
| 150 | $this->new_revision = $new_revision; |
| 151 | } |
| 152 | |
| 153 | } |