Skip to content

Commit

Permalink
[generate:plugin:block] Added code standard (#4099)
Browse files Browse the repository at this point in the history
* [update:execute] Fixed update table

* Revert "Merge remote-tracking branch 'upstream/master'"

This reverts commit ddf7739, reversing
changes made to a95b7e6.

* [generate:plugin:block] Added code standard
  • Loading branch information
hjuarez20 authored and enzolutions committed Jun 24, 2019
1 parent 6fb6004 commit 032f80e
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions templates/module/src/Plugin/Block/block.php.twig
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,18 @@ class {{class_name}} extends BlockBase {% if services is not empty %}implements
* The plugin_id for the plugin instance.
* @param string $plugin_definition
* The plugin implementation definition.
{% if services is not empty %}
{% for service in services %}
* @param \{{ service.class }} ${{service.machine_name}}
* The {{service.short}} definition.
{% endfor %}
{% endif %}
*/
public function __construct(
array $configuration,
$plugin_id,
$plugin_definition,
{{ servicesAsParameters(services)|join(', \n\t') }}
{{ servicesAsParameters(services)|join(',\n ') }}
) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
{{ serviceClassInitialization(services) }}
Expand All @@ -54,6 +60,7 @@ class {{class_name}} extends BlockBase {% if services is not empty %}implements
{% endblock %}
{% block class_create %}
{% if services is not empty %}

/**
* {@inheritdoc}
*/
Expand All @@ -65,6 +72,7 @@ class {{class_name}} extends BlockBase {% if services is not empty %}implements
{{ serviceClassInjection(services) }}
);
}

{% endif %}
{% endblock %}
{% block class_methods %}
Expand All @@ -75,9 +83,9 @@ class {{class_name}} extends BlockBase {% if services is not empty %}implements
public function defaultConfiguration() {
return [
{% for input in inputs %}
{% if input.default_value is defined and input.default_value|length %}
{% if input.default_value is defined and input.default_value|length %}
'{{ input.name }}' => {{ input.default_value }},
{% endif %}
{% endif %}
{% endfor %}
] + parent::defaultConfiguration();
}
Expand All @@ -91,7 +99,7 @@ class {{class_name}} extends BlockBase {% if services is not empty %}implements
'#type' => '{{ input.type }}',
'#title' => $this->t('{{ input.label|escape }}'),
{% if input.description is defined and input.description is not empty %}
'#description' => $this->t('{{ input.description|e }}'),
'#description' => $this->t('{{ input.description|e }}'),
{% endif %}
{% if input.options is defined and input.options|length %}
'#options' => {{ input.options }},
Expand Down Expand Up @@ -128,7 +136,7 @@ class {{class_name}} extends BlockBase {% if services is not empty %}implements
public function build() {
$build = [];
{% for input in inputs %}
$build['{{plugin_id}}_{{ input.name }}']['#markup'] = '<p>' . $this->configuration['{{ input.name }}']. '</p>';
$build['{{plugin_id}}_{{ input.name }}']['#markup'] = '<p>' . $this->configuration['{{ input.name }}'] . '</p>';
{% else %}
$build['{{plugin_id}}']['#markup'] = 'Implement {{class_name}}.';
{% endfor %}
Expand Down

0 comments on commit 032f80e

Please sign in to comment.