forked from hechoendrupal/drupal-console
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontroller.php.twig
More file actions
70 lines (64 loc) · 1.86 KB
/
Copy pathcontroller.php.twig
File metadata and controls
70 lines (64 loc) · 1.86 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
{% extends "base/class.php.twig" %}
{% block file_path %}
Drupal\{{module}}\Controller\{{ class_name }}.
{% endblock %}
{% block namespace_class %}
namespace Drupal\{{module}}\Controller;
{% endblock %}
{% block use_class %}
use Drupal\Core\Controller\ControllerBase;
{% if services is not empty %}
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
{% endif %}
{% endblock %}
{% block class_declaration %}
/**
* Class {{ class_name }}.
*
* @package Drupal\{{ module }}\Controller
*/
class {{ class_name }} extends ControllerBase {% if services is not empty %}implements ContainerInjectionInterface {% endif %}
{% endblock %}
{% block class_construct %}
{% if services is not empty %}
public function __construct({{ servicesAsParameters(services)|join(', ') }}) {
{{ serviceClassInitialization(services) }}
}
{% endif %}
{% endblock %}
{% block class_create %}
{% if services is not empty %}
public static function create(ContainerInterface $container) {
return new static(
{{ serviceClassInjection(services) }}
);
}
{% endif %}
{% endblock %}
{% block class_methods %}
/**
* {{ method_name | capitalize }}.
*
* @return string
* Return Hello string.
*/
public function {{method_name}}({{ argumentsFromRoute(route)|join(', ') }}) {
{% if class_name == "DefaultController" %}
return [
'#type' => 'markup',
'#markup' => $this->t('Hello @name!', ['@name' => $name])
];
{% elseif argumentsFromRoute(route) is not empty %}
return [
'#type' => 'markup',
'#markup' => $this->t('Implement method: {{method_name}} with parameter(s): {{ argumentsFromRoute(route)|join(', ') }}')
];
{% else %}
return [
'#type' => 'markup',
'#markup' => $this->t('Implement method: {{method_name}}')
];
{% endif %}
}
{% endblock %}