Skip to content

[generate:plugin:skeleton] Fixed namespace #4028

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 %}