-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathController.php
More file actions
75 lines (59 loc) · 2 KB
/
Controller.php
File metadata and controls
75 lines (59 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php
namespace DrupalCodeBuilder\Generator;
use DrupalCodeBuilder\Definition\PropertyDefinition;
/**
* Generator class for controllers.
*/
class Controller extends PHPClassFileWithInjection {
protected $hasStaticFactoryMethod = TRUE;
/**
* {@inheritdoc}
*/
public static function getPropertyDefinition(): PropertyDefinition {
$definition = parent::getPropertyDefinition();
$properties = [
'injected_services' => PropertyDefinition::create('string')
->setLabel('Injected services')
->setDescription("Services to inject. Additionally, use 'storage:TYPE' to inject entity storage handlers.")
->setMultiple(TRUE)
->setOptionsProvider(\DrupalCodeBuilder\Factory::getTask('ReportServiceData')),
];
$definition->addProperties($properties);
return $definition;
}
/**
* {@inheritdoc}
*/
public function requiredComponents(): array {
$components = parent::requiredComponents();
foreach ($this->component_data['injected_services'] as $service_id) {
$components['service_' . $service_id] = [
'component_type' => 'InjectedService',
'containing_component' => '%requester',
'service_id' => $service_id,
'class_has_static_factory' => $this->hasStaticFactoryMethod,
'class_has_constructor' => TRUE,
'class_name' => $this->component_data->qualified_class_name->value,
];
}
return $components;
}
/**
* {@inheritdoc}
*/
protected function collectSectionBlocks() {
parent::collectSectionBlocks();
$this->collectSectionBlocksForDependencyInjection();
}
/**
* Produces the class declaration.
*/
function class_declaration() {
if (isset($this->containedComponents['injected_service'])) {
// Numeric key will clobber, so make something up!
// TODO: fix!
$this->component_data->interfaces->add(['ContainerInjectionInterface' => '\Drupal\Core\DependencyInjection\ContainerInjectionInterface']);
}
return parent::class_declaration();
}
}