Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 17 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
Relationships | |
0.00% |
0 / 17 |
|
0.00% |
0 / 4 |
30 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
create | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
2 | |||
getTitle | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
6 | |||
getCacheMaxAge | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace Drupal\crm\Plugin\Menu\LocalTask; |
4 | |
5 | use Drupal\Core\Menu\LocalTaskDefault; |
6 | use Drupal\Core\Plugin\ContainerFactoryPluginInterface; |
7 | use Drupal\Core\Routing\RouteMatchInterface; |
8 | use Drupal\Core\StringTranslation\StringTranslationTrait; |
9 | use Drupal\crm\CrmContactInterface; |
10 | use Drupal\crm\Relationship; |
11 | use Symfony\Component\DependencyInjection\ContainerInterface; |
12 | use Symfony\Component\HttpFoundation\Request; |
13 | |
14 | /** |
15 | * Provides a local task that shows the amount of comments. |
16 | */ |
17 | final class Relationships extends LocalTaskDefault implements ContainerFactoryPluginInterface { |
18 | use StringTranslationTrait; |
19 | |
20 | /** |
21 | * The comment storage service. |
22 | * |
23 | * @var \Drupal\crm\Relationship |
24 | */ |
25 | protected $relationshipService; |
26 | |
27 | /** |
28 | * The route match service. |
29 | * |
30 | * @var \Drupal\Core\Routing\RouteMatchInterface |
31 | */ |
32 | protected $routeMatch; |
33 | |
34 | /** |
35 | * Construct the relationship task object. |
36 | * |
37 | * @param array $configuration |
38 | * A configuration array containing information about the plugin instance. |
39 | * @param string $plugin_id |
40 | * The plugin_id for the plugin instance. |
41 | * @param array $plugin_definition |
42 | * The plugin implementation definition. |
43 | * @param \Drupal\crm\Relationship $relationship_service |
44 | * The crm relationship service. |
45 | * @param \Drupal\Core\Routing\RouteMatchInterface $route_match |
46 | * The route match service. |
47 | */ |
48 | public function __construct( |
49 | array $configuration, |
50 | $plugin_id, |
51 | array $plugin_definition, |
52 | Relationship $relationship_service, |
53 | RouteMatchInterface $route_match, |
54 | ) { |
55 | parent::__construct($configuration, $plugin_id, $plugin_definition); |
56 | $this->relationshipService = $relationship_service; |
57 | $this->routeMatch = $route_match; |
58 | } |
59 | |
60 | /** |
61 | * {@inheritdoc} |
62 | */ |
63 | public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { |
64 | return new self( |
65 | $configuration, |
66 | $plugin_id, |
67 | $plugin_definition, |
68 | $container->get('crm.relationship'), |
69 | $container->get('current_route_match') |
70 | ); |
71 | } |
72 | |
73 | /** |
74 | * {@inheritdoc} |
75 | */ |
76 | public function getTitle(?Request $request = NULL) { |
77 | $contact_id = $this->routeMatch->getParameter('crm_contact'); |
78 | if ($contact_id instanceof CrmContactInterface) { |
79 | $contact_id = $contact_id->id(); |
80 | } |
81 | $ids = $this->relationshipService->getRelationshipIdByContactId($contact_id); |
82 | $count = count($ids); |
83 | |
84 | return $this->formatPlural($count, 'Relationship (1)', 'Relationships (@count)'); |
85 | } |
86 | |
87 | /** |
88 | * {@inheritdoc} |
89 | */ |
90 | public function getCacheMaxAge() { |
91 | return 0; |
92 | } |
93 | |
94 | } |