Skip to content

Commit

Permalink
Merge pull request #161 from jmolivas/twig-base-plugins
Browse files Browse the repository at this point in the history
Twig base plugins generator
  • Loading branch information
jmolivas committed Jul 16, 2014
2 parents f2abe0f + 1f9e5f4 commit 7860704
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 18 deletions.
37 changes: 26 additions & 11 deletions src/Resources/skeleton/module/src/Plugin/Block/block.php.twig
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
<?php
/**
* @file
* Contains \Drupal\{{module}}\Plugin\Block\{{class_name}}.php
*/
{% extends "base/class.php.twig" %}

{% block file_path %}
Drupal\{{module}}\Plugin\Block\{{class_name}}.
{% endblock %}

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

{% block use_class %}
use Drupal\block\BlockBase;
{% if services is not empty %}
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
{% include 'skeleton/module/shared/services-use-operator.php.twig' %}
use Symfony\Component\DependencyInjection\ContainerInterface;
{% endif %}
{% endblock %}

{% block class_declaration %}
/**
* Provides a '{{class_name}}' block.
*
Expand All @@ -20,9 +25,11 @@ use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
* admin_label = @Translation("{{plugin_label}}")
* )
*/
class {{class_name}} extends BlockBase {% if services is not empty %}implements ContainerFactoryPluginInterface{% endif %} {{"\n"}}{
class {{class_name}} extends BlockBase {% if services is not empty %}implements ContainerFactoryPluginInterface {% endif %}
{% endblock %}

{% block class_construct %}
{% if services is not empty %}
{% include 'skeleton/module/shared/services-class-properties-declaration.php.twig' %}
/**
* Construct.
*
Expand All @@ -40,9 +47,14 @@ class {{class_name}} extends BlockBase {% if services is not empty %}implements
{{ servicesAsParameters(services)|join(', \n\t') }}
) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
{% include 'skeleton/module/shared/services-class-properties-initialization.php.twig' %}
{{ serviceClassInitialization(services) }}
}

{% endif %}
{% endblock %}

{% block class_create %}
{% if services is not empty %}
/**
* {@inheritdoc}
*/
Expand All @@ -52,11 +64,14 @@ class {{class_name}} extends BlockBase {% if services is not empty %}implements
$configuration,
$plugin_id,
$plugin_definition,
{% include 'skeleton/module/shared/services-class-properties-injection.php.twig' %}
{{ serviceClassInjection(services) }}
);
}

{% endif %}
{% endblock %}

{% block class_methods %}
/**
* {@inheritdoc}
*/
Expand Down Expand Up @@ -94,4 +109,4 @@ class {{class_name}} extends BlockBase {% if services is not empty %}implements
{% endfor %}
}
{% endif %}
}
{% endblock %}
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
<?php
/**
*@file
* Contains \Drupal\{{module}}\Plugin\ImageEffect\{{class_name}}.php
*/
{% extends "base/class.php.twig" %}

{% block file_path %}
Drupal\{{module}}\Plugin\ImageEffect\{{class_name}}.
{% endblock %}

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

{% block use_class %}
use Drupal\Core\Image\ImageInterface;
use Drupal\image\ImageEffectBase;
{% endblock %}

{% block class_declaration %}
/**
* Provides a '{{class_name}}' image effect.
*
Expand All @@ -18,13 +23,15 @@ use Drupal\image\ImageEffectBase;
* description = @Translation("{{description}}")
* )
*/
class {{ class_name }} extends ImageEffectBase {
class {{ class_name }} extends ImageEffectBase
{% endblock %}

{% block class_methods %}
/**
* {@inheritdoc}
*/
public function applyEffect(ImageInterface $image) {
// Implement Image Effect
return imagefilter($image->getToolkit()->getResource());
}
}
{% endblock %}

0 comments on commit 7860704

Please sign in to comment.