X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=vendor%2Fdrupal%2Fconsole%2Ftemplates%2Fmodule%2Fsrc%2FForm%2Fform.php.twig;fp=vendor%2Fdrupal%2Fconsole%2Ftemplates%2Fmodule%2Fsrc%2FForm%2Fform.php.twig;h=a495d6a9c920842bab2e20d91031766fddd5e63a;hp=0000000000000000000000000000000000000000;hb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;hpb=57c063afa3f66b07c4bbddc2d6129a96d90f0aad diff --git a/vendor/drupal/console/templates/module/src/Form/form.php.twig b/vendor/drupal/console/templates/module/src/Form/form.php.twig new file mode 100644 index 000000000..a495d6a9c --- /dev/null +++ b/vendor/drupal/console/templates/module/src/Form/form.php.twig @@ -0,0 +1,109 @@ +{% extends "base/class.php.twig" %} + +{% 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\FormBase; +use Drupal\Core\Form\FormStateInterface; +{% if services is not empty %} +use Symfony\Component\DependencyInjection\ContainerInterface; +{% endif %} +{% endblock %} + +{% block class_declaration %} +/** + * Class {{ class_name }}. + * + * @package Drupal\{{module_name}}\Form + */ +class {{ class_name }} extends FormBase {% endblock %} +{% block class_construct %} +{% if services is not empty %} + public function __construct( + {{ servicesAsParameters(services)|join(',\n ') }} + ) { +{{ serviceClassInitialization(services) }} + } + +{% endif %} +{% endblock %} + +{% block class_create %} +{% if services is not empty %} + public static function create(ContainerInterface $container) { + return new static( +{{ serviceClassInjection(services) }} + ); + } + +{% endif %} +{% endblock %} + +{% block class_methods %} + + /** + * {@inheritdoc} + */ + public function getFormId() { + return '{{form_id}}'; + } + + /** + * {@inheritdoc} + */ + public function buildForm(array $form, FormStateInterface $form_state) { +{% for input in inputs %} +{% if input.fieldset|length %} + $form['{{ input.fieldset }}']['{{ input.name }}'] = [ +{% else %} + $form['{{ input.name }}'] = [ +{% endif %} + '#type' => '{{ input.type }}', + '#title' => $this->t('{{ input.label|e }}'), +{% if input.description|length %} + '#description' => $this->t('{{ input.description|e }}'), +{% endif %} +{% if input.options|length %} + '#options' => {{ input.options }}, +{% endif %} +{% if input.maxlength|length %} + '#maxlength' => {{ input.maxlength }}, +{% endif %} +{% if input.size|length %} + '#size' => {{ input.size }}, +{% endif %} + ]; +{% endfor %} + + $form['submit'] = [ + '#type' => 'submit', + '#value' => $this->t('Submit'), + ]; + + return $form; + } + + /** + * {@inheritdoc} + */ + public function validateForm(array &$form, FormStateInterface $form_state) { + parent::validateForm($form, $form_state); + } + + /** + * {@inheritdoc} + */ + public function submitForm(array &$form, FormStateInterface $form_state) { + // Display result. + foreach ($form_state->getValues() as $key => $value) { + drupal_set_message($key . ': ' . $value); + } + + } +{% endblock %}