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\crm\CrmRelationshipTypeInterface;
7
8/**
9 * Defines the CRM Relationship type configuration entity.
10 *
11 * @ConfigEntityType(
12 *   id = "crm_relationship_type",
13 *   label = @Translation("CRM Relationship type"),
14 *   label_collection = @Translation("CRM Relationship types"),
15 *   label_singular = @Translation("crm relationship type"),
16 *   label_plural = @Translation("crm relationships types"),
17 *   label_count = @PluralTranslation(
18 *     singular = "@count crm relationships type",
19 *     plural = "@count crm relationships types",
20 *   ),
21 *   handlers = {
22 *     "form" = {
23 *       "add" = "Drupal\crm\Form\RelationshipTypeForm",
24 *       "edit" = "Drupal\crm\Form\RelationshipTypeForm",
25 *       "delete" = "Drupal\Core\Entity\EntityDeleteForm",
26 *     },
27 *     "list_builder" = "Drupal\crm\RelationshipTypeListBuilder",
28 *     "route_provider" = {
29 *       "html" = "Drupal\Core\Entity\Routing\AdminHtmlRouteProvider",
30 *     }
31 *   },
32 *   admin_permission = "administer crm relationship types",
33 *   bundle_of = "crm_relationship",
34 *   config_prefix = "crm_relationship_type",
35 *   entity_keys = {
36 *     "id" = "id",
37 *     "label" = "label",
38 *     "uuid" = "uuid"
39 *   },
40 *   links = {
41 *     "add-form" = "/admin/structure/crm/relationship_types/add",
42 *     "edit-form" = "/admin/structure/crm/relationship_types/manage/{crm_relationship_type}",
43 *     "delete-form" = "/admin/structure/crm/relationship_types/manage/{crm_relationship_type}/delete",
44 *     "collection" = "/admin/structure/crm/relationship_types"
45 *   },
46 *   config_export = {
47 *     "id",
48 *     "label",
49 *     "description",
50 *     "asymmetric",
51 *     "uuid",
52 *     "contact_type_a",
53 *     "contact_type_b",
54 *     "label_a",
55 *     "label_b",
56 *   }
57 * )
58 */
59class RelationshipType extends ConfigEntityBundleBase implements CrmRelationshipTypeInterface {
60
61  /**
62   * The machine name of this crm relationship type.
63   *
64   * @var string
65   */
66  protected $id;
67
68  /**
69   * The human-readable name of the crm relationship type.
70   *
71   * @var string
72   */
73  protected $label;
74
75  /**
76   * The description of the crm relationship type.
77   *
78   * @var string
79   */
80  protected $description;
81
82  /**
83   * Is the bundle and label the same for both sides of the relationship?
84   *
85   * @var bool
86   */
87  protected $asymmetric;
88
89  /**
90   * The human-readable name of the crm relationship type.
91   *
92   * @var string
93   */
94  protected $label_a;
95
96  /**
97   * The human-readable name of the crm relationship type.
98   *
99   * @var string
100   */
101  protected $label_b;
102
103  /**
104   * The human-readable name of the crm relationship type.
105   *
106   * @var string
107   */
108  protected $contact_type_a;
109
110  /**
111   * The human-readable name of the crm relationship type.
112   *
113   * @var string
114   */
115  protected $contact_type_b;
116
117  /**
118   * {@inheritdoc}
119   */
120  public function getDescription() {
121    return $this->description ?? '';
122  }
123
124  /**
125   * {@inheritdoc}
126   */
127  public function setDescription($description) {
128    $this->description = $description;
129
130    return $this;
131  }
132
133  /**
134   * {@inheritdoc}
135   */
136  public function calculateDependencies() {
137    parent::calculateDependencies();
138
139    if ($type_a = $this->get('contact_type_a')) {
140      $this->addDependency('config', 'crm.crm_contact_type.' . $type_a);
141    }
142    if ($type_b = $this->get('contact_type_b')) {
143      $this->addDependency('config', 'crm.crm_contact_type.' . $type_b);
144    }
145
146    return $this;
147  }
148
149}