Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 20 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
GroupContact | |
0.00% |
0 / 11 |
|
0.00% |
0 / 3 |
12 | |
0.00% |
0 / 1 |
defaultConfiguration | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
buildConfigurationForm | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
calculateDependencies | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace Drupal\crm\Plugin\Group\Relation; |
4 | |
5 | use Drupal\Core\Form\FormStateInterface; |
6 | use Drupal\Core\StringTranslation\TranslatableMarkup; |
7 | use Drupal\group\Plugin\Attribute\GroupRelationType; |
8 | use Drupal\group\Plugin\Group\Relation\GroupRelationBase; |
9 | |
10 | /** |
11 | * Provides a group relation type for contacts. |
12 | */ |
13 | #[GroupRelationType( |
14 | id: 'group_crm_contact', |
15 | entity_type_id: 'crm_contact', |
16 | label: new TranslatableMarkup('Group contact'), |
17 | description: new TranslatableMarkup('Adds contacts to groups both publicly and privately.'), |
18 | reference_label: new TranslatableMarkup('Name'), |
19 | reference_description: new TranslatableMarkup('The name of the contact to add to the group'), |
20 | entity_access: TRUE, |
21 | deriver: 'Drupal\crm\Plugin\Group\Relation\GroupContactDeriver' |
22 | )] |
23 | class GroupContact extends GroupRelationBase { |
24 | |
25 | /** |
26 | * {@inheritdoc} |
27 | */ |
28 | public function defaultConfiguration() { |
29 | $config = parent::defaultConfiguration(); |
30 | $config['entity_cardinality'] = 1; |
31 | return $config; |
32 | } |
33 | |
34 | /** |
35 | * {@inheritdoc} |
36 | */ |
37 | public function buildConfigurationForm(array $form, FormStateInterface $form_state) { |
38 | $form = parent::buildConfigurationForm($form, $form_state); |
39 | |
40 | // Disable the entity cardinality field as the functionality of this module |
41 | // relies on a cardinality of 1. We don't just hide it, though, to keep a UI |
42 | // that's consistent with other group relations. |
43 | $info = $this->t("This field has been disabled by the plugin to guarantee the functionality that's expected of it."); |
44 | $form['entity_cardinality']['#disabled'] = TRUE; |
45 | $form['entity_cardinality']['#description'] .= '<br /><em>' . $info . '</em>'; |
46 | |
47 | return $form; |
48 | } |
49 | |
50 | /** |
51 | * {@inheritdoc} |
52 | */ |
53 | public function calculateDependencies() { |
54 | $dependencies = parent::calculateDependencies(); |
55 | $dependencies['config'][] = 'crm_contact.type.' . $this->getRelationType()->getEntityBundle(); |
56 | return $dependencies; |
57 | } |
58 | |
59 | } |