Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
66.67% covered (warning)
66.67%
6 / 9
33.33% covered (danger)
33.33%
1 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
RelationshipType
66.67% covered (warning)
66.67%
6 / 9
33.33% covered (danger)
33.33%
1 / 3
5.93
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
 calculateDependencies
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
3
1<?php
2
3namespace Drupal\crm\Entity;
4
5use Drupal\Core\Config\Entity\ConfigEntityBundleBase;
6use Drupal\Core\Entity\Attribute\ConfigEntityType;
7use Drupal\Core\Entity\EntityDeleteForm;
8use Drupal\Core\Entity\Routing\AdminHtmlRouteProvider;
9use Drupal\Core\StringTranslation\TranslatableMarkup;
10use Drupal\crm\RelationshipTypeListBuilder;
11use Drupal\crm\Form\RelationshipTypeForm;
12
13use Drupal\crm\CrmRelationshipTypeInterface;
14
15/**
16 * Defines the CRM Relationship type configuration entity.
17 */
18#[ConfigEntityType(
19  id: 'crm_relationship_type',
20  label: new TranslatableMarkup('CRM Relationship type'),
21  label_collection: new TranslatableMarkup('CRM Relationship types'),
22  label_singular: new TranslatableMarkup('crm relationship type'),
23  label_plural: new TranslatableMarkup('crm relationships types'),
24  label_count: [
25    'singular' => '@count crm relationships type',
26    'plural' => '@count crm relationships types',
27  ],
28  handlers: [
29    'form' => [
30      'add' => RelationshipTypeForm::class,
31      'edit' => RelationshipTypeForm::class,
32      'delete' => EntityDeleteForm::class,
33    ],
34    'list_builder' => RelationshipTypeListBuilder::class,
35    'route_provider' => [
36      'html' => AdminHtmlRouteProvider::class,
37    ],
38  ],
39  admin_permission: 'administer crm',
40  bundle_of: 'crm_relationship',
41  config_prefix: 'crm_relationship_type',
42  entity_keys: [
43    'id' => 'id',
44    'label' => 'label',
45    'uuid' => 'uuid',
46  ],
47  links: [
48    'add-form' => '/admin/structure/crm/relationship_types/add',
49    'edit-form' => '/admin/structure/crm/relationship_types/manage/{crm_relationship_type}',
50    'delete-form' => '/admin/structure/crm/relationship_types/manage/{crm_relationship_type}/delete',
51    'collection' => '/admin/structure/crm/relationship_types',
52  ],
53  config_export: [
54    'id',
55    'label',
56    'description',
57    'asymmetric',
58    'uuid',
59    'contact_type_a',
60    'contact_type_b',
61    'label_a',
62    'label_b',
63  ],
64)]
65class RelationshipType extends ConfigEntityBundleBase implements CrmRelationshipTypeInterface {
66
67  /**
68   * The machine name of this crm relationship type.
69   *
70   * @var string
71   */
72  protected $id;
73
74  /**
75   * The human-readable name of the crm relationship type.
76   *
77   * @var string
78   */
79  protected $label;
80
81  /**
82   * The description of the crm relationship type.
83   *
84   * @var string
85   */
86  protected $description;
87
88  /**
89   * Is the bundle and label the same for both sides of the relationship?
90   *
91   * @var bool
92   */
93  protected $asymmetric;
94
95  /**
96   * The human-readable name of the crm relationship type.
97   *
98   * @var string
99   */
100  protected $label_a;
101
102  /**
103   * The human-readable name of the crm relationship type.
104   *
105   * @var string
106   */
107  protected $label_b;
108
109  /**
110   * The human-readable name of the crm relationship type.
111   *
112   * @var string
113   */
114  protected $contact_type_a;
115
116  /**
117   * The human-readable name of the crm relationship type.
118   *
119   * @var string
120   */
121  protected $contact_type_b;
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 calculateDependencies() {
143    parent::calculateDependencies();
144
145    if ($type_a = $this->get('contact_type_a')) {
146      $this->addDependency('config', 'crm.crm_contact_type.' . $type_a);
147    }
148    if ($type_b = $this->get('contact_type_b')) {
149      $this->addDependency('config', 'crm.crm_contact_type.' . $type_b);
150    }
151
152    return $this;
153  }
154
155}