Skip to content
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

Twig base form generator #159

Merged
merged 2 commits into from
Jul 16, 2014
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
4 changes: 2 additions & 2 deletions src/Resources/skeleton/base/class.php.twig
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

{% block use_class %}{% endblock %}
{% block use_class_services %}
{% if service is defined %}
{% if services is defined %}
{% for service in services %}
use {{ service.class }};
{% endfor %}
Expand All @@ -21,7 +21,7 @@ use {{ service.class }};
{% block class_declaration %}{% endblock %}
{
{% block class_properties %}
{% if service is defined %}
{% if services is defined %}
{% for service in services %}

/**
Expand Down
40 changes: 26 additions & 14 deletions src/Resources/skeleton/module/src/Form/form.php.twig
Original file line number Diff line number Diff line change
@@ -1,40 +1,52 @@
<?php
{% extends "base/class.php.twig" %}

/**
* @file
* Contains \Drupal\{{module_name}}\Form\{{ class_name }}.
*/
{% block file_path %}
Drupal\{{module_name}}\Form\{{ class_name }}.
{% endblock %}

{% block namespace_class %}
namespace Drupal\{{module_name}}\Form;
{% endblock %}

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

{% block class_declaration %}
class {{ class_name }} extends ConfigFormBase
{
{% if services is not empty %}
{% include 'skeleton/module/shared/services-class-properties-declaration.php.twig' %}
{% endblock %}

{% block class_construct %}
{% if services is not empty %}
public function __construct(
ConfigFactoryInterface $config_factory,
{{ servicesAsParameters(services)|join(', \n') }}
{{ servicesAsParameters(services)|join(',\n ') }}
)
{
parent::__construct($config_factory);
{% include 'skeleton/module/shared/services-class-properties-initialization.php.twig' %}
{{ serviceClassInitialization(services) }}
}

{% endif %}
{% endblock %}

{% block class_create %}
{% if services is not empty %}
public static function create(ContainerInterface $container) {
return new static(
$container->get('config.factory'),
{% include 'skeleton/module/shared/services-class-properties-injection.php.twig' %}
$container->get('config.factory'),
{{ serviceClassInjection(services) }}
);
}

{% endif %}
{% endblock %}

{% block class_methods %}
/**
* {@inheritdoc}
*/
Expand Down Expand Up @@ -81,4 +93,4 @@ class {{ class_name }} extends ConfigFormBase
{% endfor %}
->save();
}
}
{% endblock %}