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