Skip to content

Commit

Permalink
[generate:plugin:skeleton] Fixed namespace (#4028)
Browse files Browse the repository at this point in the history
  • Loading branch information
hjuarez20 authored and enzolutions committed May 10, 2019
1 parent 404a026 commit 245767a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 22 deletions.
2 changes: 2 additions & 0 deletions src/Command/Generate/PluginSkeletonCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
'class_name' => $className,
'services' => $buildServices,
'plugin_metadata' => $pluginMetaData,
'id' => $this->stringConverter->camelCaseToUnderscore($className),
'label' => $this->stringConverter->camelCaseToHuman($className)
]);

$this->chainQueue->addCommand('cache:rebuild', ['cache' => 'discovery']);
Expand Down
1 change: 1 addition & 0 deletions src/Generator/PluginSkeletonGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public function generate(array $parameters)

$parameters['plugin_annotation'] = array_pop(explode('\\', $pluginMetaData['pluginAnnotation']));
$parameters['plugin_interface'] = array_pop(explode('\\', $pluginMetaData['pluginInterface']));
$parameters['namespace'] = str_replace('/', '\\', $pluginMetaData['subdir']);

$this->renderFile(
'module/src/Plugin/skeleton.php.twig',
Expand Down
44 changes: 22 additions & 22 deletions templates/module/src/Plugin/skeleton.php.twig
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{% endblock %}

{% block namespace_class %}
namespace Drupal\{{module}}\Plugin\{{ plugin }};
namespace Drupal\{{module}}\{{ namespace }};
{% endblock %}

{% block use_class %}
Expand All @@ -25,17 +25,17 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
* @{{ plugin_annotation }}(
{% for property in pluginAnnotationProperties %}
{% if property.name == 'id' %}
* id = "{{- plugin_id }}",
* id = "{{- id }}",
{% elseif property.type == "\\Drupal\\Core\\Annotation\\Translation" %}
* {{ property.name }} = @Translation("{{property.description}}"),
* {{ property.name }} = @Translation("{{label}}"),
{% else %}
* {{ property.name }} = "{{ property.type }}",
{% endif %}
{% endfor %}
* )
*/
{% endif %}
class {{class_name}} implements {% if plugin_interface is not empty %} {{ plugin_interface }} {% endif %}{% if services is not empty %}, ContainerFactoryPluginInterface {% endif %}{% endblock %}
class {{class_name}} implements {% if plugin_interface is not empty %}{{ plugin_interface }}{% endif %}{% if services is not empty %}, ContainerFactoryPluginInterface {% endif %}{% endblock %}
{% block class_construct %}
{% if services is not empty %}
/**
Expand All @@ -61,38 +61,38 @@ class {{class_name}} implements {% if plugin_interface is not empty %} {{ plugin
{% endblock %}
{% block class_create %}
{% if services is not empty %}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static(
$configuration,
$plugin_id,
$plugin_definition,
{{ serviceClassInjection(services) }}
);
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static(
$configuration,
$plugin_id,
$plugin_definition,
{{ serviceClassInjection(services) }}
);
}
{% endif %}
{% endblock %}
{% block class_methods %}

/**
* {@inheritdoc}
*/
* {@inheritdoc}
*/
public function build() {
$build = [];

// Implement your logic

return $build;
}

{% for method in pluginInterfaceMethods %}

/**
* {@inheritdoc}
*/
{{ method.declaration }} {
* {@inheritdoc}
*/
{{ method.declaration }} {

}
}
{% endfor %}
{% endblock %}

0 comments on commit 245767a

Please sign in to comment.