Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 150 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
CrmCase | |
0.00% |
0 / 150 |
|
0.00% |
0 / 2 |
12 | |
0.00% |
0 / 1 |
preSave | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
baseFieldDefinitions | |
0.00% |
0 / 147 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace Drupal\crm_case\Entity; |
4 | |
5 | use Drupal\Core\Entity\EntityChangedTrait; |
6 | use Drupal\Core\Entity\EntityStorageInterface; |
7 | use Drupal\Core\Entity\EntityTypeInterface; |
8 | use Drupal\Core\Entity\RevisionableContentEntityBase; |
9 | use Drupal\Core\Field\BaseFieldDefinition; |
10 | use Drupal\crm_case\CrmCaseInterface; |
11 | use Drupal\user\EntityOwnerTrait; |
12 | |
13 | /** |
14 | * Defines the crm case entity class. |
15 | * |
16 | * @ContentEntityType( |
17 | * id = "crm_case", |
18 | * label = @Translation("Crm Case"), |
19 | * label_collection = @Translation("Crm Cases"), |
20 | * label_singular = @Translation("crm case"), |
21 | * label_plural = @Translation("crm cases"), |
22 | * label_count = @PluralTranslation( |
23 | * singular = "@count crm cases", |
24 | * plural = "@count crm cases", |
25 | * ), |
26 | * bundle_label = @Translation("Crm Case type"), |
27 | * handlers = { |
28 | * "list_builder" = "Drupal\crm_case\CrmCaseListBuilder", |
29 | * "views_data" = "Drupal\views\EntityViewsData", |
30 | * "access" = "Drupal\crm_case\CrmCaseAccessControlHandler", |
31 | * "form" = { |
32 | * "add" = "Drupal\crm_case\Form\CrmCaseForm", |
33 | * "edit" = "Drupal\crm_case\Form\CrmCaseForm", |
34 | * "delete" = "Drupal\Core\Entity\ContentEntityDeleteForm", |
35 | * }, |
36 | * "route_provider" = { |
37 | * "html" = "Drupal\Core\Entity\Routing\AdminHtmlRouteProvider", |
38 | * } |
39 | * }, |
40 | * base_table = "crm_case", |
41 | * revision_table = "crm_case_revision", |
42 | * show_revision_ui = TRUE, |
43 | * admin_permission = "administer crm case types", |
44 | * entity_keys = { |
45 | * "id" = "id", |
46 | * "revision" = "revision_id", |
47 | * "bundle" = "bundle", |
48 | * "label" = "label", |
49 | * "uuid" = "uuid", |
50 | * "owner" = "uid", |
51 | * }, |
52 | * revision_metadata_keys = { |
53 | * "revision_user" = "revision_uid", |
54 | * "revision_created" = "revision_timestamp", |
55 | * "revision_log_message" = "revision_log", |
56 | * }, |
57 | * links = { |
58 | * "collection" = "/admin/content/crm/case", |
59 | * "add-form" = "/crm/case/add/{crm_case_type}", |
60 | * "add-page" = "/crm/case/add", |
61 | * "canonical" = "/crm/case/{crm_case}", |
62 | * "edit-form" = "/crm/case/{crm_case}/edit", |
63 | * "delete-form" = "/crm/case/{crm_case}/delete", |
64 | * }, |
65 | * bundle_entity_type = "crm_case_type", |
66 | * field_ui_base_route = "entity.crm_case_type.edit_form", |
67 | * ) |
68 | */ |
69 | class CrmCase extends RevisionableContentEntityBase implements CrmCaseInterface { |
70 | |
71 | use EntityChangedTrait; |
72 | use EntityOwnerTrait; |
73 | |
74 | /** |
75 | * {@inheritdoc} |
76 | */ |
77 | public function preSave(EntityStorageInterface $storage) { |
78 | parent::preSave($storage); |
79 | if (!$this->getOwnerId()) { |
80 | // If no owner has been set explicitly, make the anonymous user the owner. |
81 | $this->setOwnerId(0); |
82 | } |
83 | } |
84 | |
85 | /** |
86 | * {@inheritdoc} |
87 | */ |
88 | public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { |
89 | |
90 | $fields = parent::baseFieldDefinitions($entity_type); |
91 | $fields['bundle']->setLabel(t('Type')) |
92 | ->setDisplayOptions('view', [ |
93 | 'type' => 'text_default', |
94 | 'label' => 'inline', |
95 | 'weight' => 10, |
96 | ]) |
97 | ->setDisplayConfigurable('view', TRUE); |
98 | |
99 | $fields['label'] = BaseFieldDefinition::create('string') |
100 | ->setRevisionable(TRUE) |
101 | ->setLabel(t('Label')) |
102 | ->setRequired(TRUE) |
103 | ->setSetting('max_length', 255) |
104 | ->setDisplayOptions('form', [ |
105 | 'type' => 'string_textfield', |
106 | 'weight' => -5, |
107 | ]) |
108 | ->setDisplayConfigurable('form', TRUE) |
109 | ->setDisplayOptions('view', [ |
110 | 'label' => 'hidden', |
111 | 'type' => 'string', |
112 | 'weight' => -5, |
113 | ]) |
114 | ->setDisplayConfigurable('view', TRUE); |
115 | |
116 | $fields['status'] = BaseFieldDefinition::create('boolean') |
117 | ->setRevisionable(TRUE) |
118 | ->setLabel(t('Status')) |
119 | ->setDefaultValue(TRUE) |
120 | ->setSetting('on_label', 'Enabled') |
121 | ->setDisplayOptions('form', [ |
122 | 'type' => 'boolean_checkbox', |
123 | 'settings' => [ |
124 | 'display_label' => FALSE, |
125 | ], |
126 | 'weight' => 0, |
127 | ]) |
128 | ->setDisplayConfigurable('form', TRUE) |
129 | ->setDisplayOptions('view', [ |
130 | 'type' => 'boolean', |
131 | 'label' => 'inline', |
132 | 'weight' => 0, |
133 | 'settings' => [ |
134 | 'format' => 'enabled-disabled', |
135 | ], |
136 | ]) |
137 | ->setDisplayConfigurable('view', TRUE); |
138 | |
139 | $fields['description'] = BaseFieldDefinition::create('text_long') |
140 | ->setRevisionable(TRUE) |
141 | ->setLabel(t('Description')) |
142 | ->setDisplayOptions('form', [ |
143 | 'type' => 'text_textarea', |
144 | 'weight' => 10, |
145 | ]) |
146 | ->setDisplayConfigurable('form', TRUE) |
147 | ->setDisplayOptions('view', [ |
148 | 'type' => 'text_default', |
149 | 'label' => 'above', |
150 | 'weight' => 10, |
151 | ]) |
152 | ->setDisplayConfigurable('view', TRUE); |
153 | |
154 | $fields['uid'] = BaseFieldDefinition::create('entity_reference') |
155 | ->setRevisionable(TRUE) |
156 | ->setLabel(t('Owner')) |
157 | ->setSetting('target_type', 'user') |
158 | ->setDefaultValueCallback(static::class . '::getDefaultEntityOwner') |
159 | ->setDisplayOptions('form', [ |
160 | 'type' => 'entity_reference_autocomplete', |
161 | 'settings' => [ |
162 | 'match_operator' => 'CONTAINS', |
163 | 'size' => 60, |
164 | 'placeholder' => '', |
165 | ], |
166 | 'weight' => 15, |
167 | ]) |
168 | ->setDisplayConfigurable('form', TRUE) |
169 | ->setDisplayOptions('view', [ |
170 | 'label' => 'inline', |
171 | 'type' => 'author', |
172 | 'weight' => 15, |
173 | ]) |
174 | ->setDisplayConfigurable('view', TRUE); |
175 | |
176 | $fields['contact_id'] = BaseFieldDefinition::create('entity_reference') |
177 | ->setRevisionable(TRUE) |
178 | ->setLabel(t('Contact')) |
179 | ->setSetting('target_type', 'crm_contact') |
180 | ->setDefaultValueCallback(static::class . '::getDefaultEntityOwner') |
181 | ->setDisplayOptions('form', [ |
182 | 'type' => 'entity_reference_autocomplete', |
183 | 'settings' => [ |
184 | 'match_operator' => 'CONTAINS', |
185 | 'size' => 60, |
186 | 'placeholder' => '', |
187 | ], |
188 | 'weight' => 15, |
189 | ]) |
190 | ->setDisplayConfigurable('form', TRUE) |
191 | ->setDisplayOptions('view', [ |
192 | 'label' => 'inline', |
193 | 'type' => 'author', |
194 | 'weight' => 15, |
195 | ]) |
196 | ->setDisplayConfigurable('view', TRUE); |
197 | |
198 | $fields['encounter'] = BaseFieldDefinition::create('entity_reference') |
199 | ->setRevisionable(TRUE) |
200 | ->setLabel(t('Encounter')) |
201 | ->setSetting('target_type', 'crm_case_encounter') |
202 | ->setDefaultValueCallback(static::class . '::getDefaultEntityOwner') |
203 | ->setDisplayOptions('form', [ |
204 | 'type' => 'entity_reference_autocomplete', |
205 | 'settings' => [ |
206 | 'match_operator' => 'CONTAINS', |
207 | 'size' => 60, |
208 | 'placeholder' => '', |
209 | ], |
210 | 'weight' => 15, |
211 | ]) |
212 | ->setDisplayConfigurable('form', TRUE) |
213 | ->setDisplayOptions('view', [ |
214 | 'label' => 'inline', |
215 | 'type' => 'author', |
216 | 'weight' => 15, |
217 | ]) |
218 | ->setDisplayConfigurable('view', TRUE); |
219 | |
220 | $fields['created'] = BaseFieldDefinition::create('created') |
221 | ->setLabel(t('Created')) |
222 | ->setDescription(t('The time that the crm case was created.')) |
223 | ->setDisplayOptions('view', [ |
224 | 'label' => 'inline', |
225 | 'type' => 'timestamp', |
226 | 'weight' => 20, |
227 | ]) |
228 | ->setDisplayConfigurable('form', TRUE) |
229 | ->setDisplayOptions('form', [ |
230 | 'type' => 'datetime_timestamp', |
231 | 'weight' => 20, |
232 | ]) |
233 | ->setDisplayConfigurable('view', TRUE); |
234 | |
235 | $fields['changed'] = BaseFieldDefinition::create('changed') |
236 | ->setLabel(t('Changed')) |
237 | ->setDescription(t('The time that the crm case was last edited.')) |
238 | ->setDisplayOptions('view', [ |
239 | 'label' => 'inline', |
240 | 'type' => 'timestamp', |
241 | 'weight' => 20, |
242 | ]) |
243 | ->setDisplayConfigurable('view', TRUE); |
244 | |
245 | return $fields; |
246 | } |
247 | |
248 | } |