Skip to content

Commit

Permalink
added form helper templates, form updates
Browse files Browse the repository at this point in the history
  • Loading branch information
n3vrax authored and n3vrax committed Mar 12, 2017
1 parent 3b6fe29 commit 8c55a14
Show file tree
Hide file tree
Showing 10 changed files with 132 additions and 116 deletions.
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
## 0.1.1 - 2017-03-12

Updated account and register forms to use the new form template helpers

### Added
* Form partial template helpers

### Deprecated
* Nothing

### Removed
* Nothing

### Fixed
* Nothing


## 0.1.0 - 2017-03-11

Initial tagged release
Expand Down
10 changes: 5 additions & 5 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions src/User/Form/AccountForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@

namespace Frontend\User\Form;

use Zend\Stdlib\ArrayUtils;

/**
* Class AccountForm
* @package App\User\Form
Expand All @@ -20,18 +18,20 @@ class AccountForm extends \Dot\User\Form\AccountForm
public function init()
{
parent::init();
$validationGroup = $this->getValidationGroup();
$validationGroup = ArrayUtils::merge($validationGroup, [
$this->setValidationGroup([
'account_csrf',
'user' => [
'username',
'details' => [
'firstName',
'lastName',
'phone',
'address'
]
]
],
// add submit to validation group,
// not needed usually bu needed for the form display helper partial template
'submit'
]);

$this->setValidationGroup($validationGroup);
}
}
21 changes: 15 additions & 6 deletions src/User/Form/RegisterForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@

namespace Frontend\User\Form;

use Zend\Stdlib\ArrayUtils;

/**
* Class RegisterForm
* @package App\User\Form
Expand All @@ -20,15 +18,26 @@ class RegisterForm extends \Dot\User\Form\RegisterForm
public function init()
{
parent::init();
$validationGroup = $this->getValidationGroup();
$validationGroup = ArrayUtils::merge($validationGroup, [
// if using the form helper template, form element order will match the order in the validation group
$validationGroup = [
'register_csrf',
'user' => [
'username',
'email',
'details' => [
'firstName',
'lastName',
]
],
'password',
'passwordConfirm',
]
]);
];
if ($this->has('captcha')) {
$validationGroup[] = 'captcha';
}
// add submit to validation group,
// not needed usually bu needed for the form display helper partial template
$validationGroup[] = 'submit';

$this->setValidationGroup($validationGroup);
}
Expand Down
4 changes: 3 additions & 1 deletion templates/layout/sidemenu.html.twig
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{% extends '@layout/default.html.twig' %}

{% block content_classes %}col-md-10 no-padding{% endblock %}
{% block content_classes %}
col-sm-10 col-md-8 col-lg-7 no-padding
{% endblock %}

{% block side_menu %}
{{ navigationPartial('account_side_menu', 'partial::account-sidemenu') }}
Expand Down
4 changes: 3 additions & 1 deletion templates/layout/single-form.html.twig
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{% extends '@layout/default.html.twig' %}

{% block content_classes %}col-md-6 col-md-offset-3 no-padding{% endblock %}
{% block content_classes %}
col-sm-6 col-sm-offset-3 col-md-6 col-md-offset-3 col-lg-6 col-lg-offset-3 no-padding
{% endblock %}
79 changes: 79 additions & 0 deletions templates/partial/form-display-validationgroup.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
{% if showLabels is not defined %}
{% set showLabels = false %}
{% endif %}

{% if validationGroup is not defined %}
{% set validationGroup = form.getValidationGroup() %}
{% endif %}

{% for k,v in validationGroup %}

{% if form.has(k) %}

{% include '@partial/form-display-validationgroup.html.twig' with {
'form' : form.get(k),
'validationGroup': validationGroup[k],
'showLabels' : showLabels} only
%}

{% else %}

{% if form.has(v) %}

{% set element = form.get(v) %}
{% if element is Captcha %}

<div class="form-group">

{% set dummy = element.setAttribute('class', 'form-control') %}

{{ formLabel(element) }}
{{ formCaptcha(element) }}

</div>

{% elseif element is Checkbox %}

<div class="checkbox">
<label>
{{ formCheckbox(element) }} {{ element.getLabel() }}
</label>
</div>

{% elseif element is Hidden %}

{{ formElement(element) }}

{% elseif element is Button and element.getName() != 'submit' %}

{% set dummy = element.setAttribute('class', 'btn btn-block') %}
{{ formButton(element) }}

{% elseif element is Submit or element is Button and element.getName() == 'submit' %}

{% set dummy = element.setAttribute('class', 'btn btn-lg btn-primary btn-block') %}
{{ formSubmit(element) }}

{% else %}

<div class="form-group {% if element.getMessages() %}has-error{% endif %}">

{% set dummy = element.setAttribute('class', 'form-control') %}

{% if showLabels and element.getLabel() is defined and element.getLabel() is not empty %}

{{ formLabel(element) }}

{% endif %}

{{ formElement(element) }}

</div>

{% endif %}

{% endif %}

{% endif %}

{% endfor %}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

{% elseif element is Fieldset %}

{% include '@dot-form/form.html.twig' with {'form' : element, 'showLabels' : showLabels} only %}
{% include '@partial/form-display.html.twig' with {'form' : element, 'showLabels' : showLabels} only %}

{% else %}

Expand Down
41 changes: 1 addition & 40 deletions templates/user/account.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -11,46 +11,7 @@
{% set dummy = form.prepare() %}
{{ form().openTag(form) | raw }}

{% set username = form.getBaseFieldset().get('username') %}
<div class="form-group {% if username.getMessages() %}has-error{% endif %}">
{% set dummy = username.setAttribute('class', 'form-control') %}
{{ formLabel(username) }}
{{ formElement(username) }}
</div>

{% set firstName = form.getBaseFieldset().get('details').get('firstName') %}
<div class="form-group {% if firstName.getMessages() %}has-error{% endif %}">
{% set dummy = firstName.setAttribute('class', 'form-control') %}
{{ formLabel(firstName) }}
{{ formElement(firstName) }}
</div>

{% set lastName = form.getBaseFieldset().get('details').get('lastName') %}
<div class="form-group {% if lastName.getMessages() %}has-error{% endif %}">
{% set dummy = lastName.setAttribute('class', 'form-control') %}
{{ formLabel(lastName) }}
{{ formElement(lastName) }}
</div>

{% set phone = form.getBaseFieldset().get('details').get('phone') %}
<div class="form-group {% if phone.getMessages() %}has-error{% endif %}">
{% set dummy = phone.setAttribute('class', 'form-control') %}
{{ formLabel(phone) }}
{{ formElement(phone) }}
</div>

{% set address = form.getBaseFieldset().get('details').get('address') %}
<div class="form-group {% if address.getMessages() %}has-error{% endif %}">
{% set dummy = address.setAttribute('class', 'form-control') %}
{{ formLabel(address) }}
{{ formElement(address) }}
</div>

{{ formElement(form.get('account_csrf')) }}

{% set submit = form.get('submit') %}
{% set dummy = submit.setAttribute('class', 'btn btn-lg btn-primary btn-block') %}
{{ formSubmit(submit) }}
{% include '@partial/form-display-validationgroup.html.twig' with {'form': form, 'showLabels': true} %}

{{ form().closeTag() | raw }}

Expand Down
56 changes: 1 addition & 55 deletions templates/user/register.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -11,61 +11,7 @@
{% set dummy = form.prepare() %}
{{ form().openTag(form) | raw }}

{% set username = form.getBaseFieldset().get('username') %}
<div class="form-group {% if username.getMessages() %}has-error{% endif %}">
{% set dummy = username.setAttribute('class', 'form-control') %}
{{ formLabel(username) }}
{{ formElement(username) }}
</div>

{% set email = form.getBaseFieldset().get('email') %}
<div class="form-group {% if email.getMessages() %}has-error{% endif %}">
{% set dummy = email.setAttribute('class', 'form-control') %}
{{ formLabel(email) }}
{{ formElement(email) }}
</div>

{% set firstName = form.getBaseFieldset().get('details').get('firstName') %}
<div class="form-group {% if firstName.getMessages() %}has-error{% endif %}">
{% set dummy = firstName.setAttribute('class', 'form-control') %}
{{ formLabel(firstName) }}
{{ formElement(firstName) }}
</div>

{% set lastName = form.getBaseFieldset().get('details').get('lastName') %}
<div class="form-group {% if lastName.getMessages() %}has-error{% endif %}">
{% set dummy = lastName.setAttribute('class', 'form-control') %}
{{ formLabel(lastName) }}
{{ formElement(lastName) }}
</div>

{% set password = form.getBaseFieldset().get('password') %}
<div class="form-group {% if password.getMessages() %}has-error{% endif %}">
{% set dummy = password.setAttribute('class', 'form-control') %}
{{ formLabel(password) }}
{{ formElement(password) }}
</div>

{% set passwordConfirm = form.getBaseFieldset().get('passwordConfirm') %}
<div class="form-group {% if passwordConfirm.getMessages() %}has-error{% endif %}">
{% set dummy = passwordConfirm.setAttribute('class', 'form-control') %}
{{ formLabel(passwordConfirm) }}
{{ formElement(passwordConfirm) }}
</div>

{{ formElement(form.get('register_csrf')) }}

{% if form.has('captcha') %}
{% set captcha = form.get('captcha') %}
<div class="form-group">
{% set dummy = captcha.setAttribute('class', 'form-control') %}
{{ formCaptcha(captcha) }}
</div>
{% endif %}

{% set submit = form.get('submit') %}
{% set dummy = submit.setAttribute('class', 'btn btn-lg btn-primary btn-block') %}
{{ formSubmit(submit) }}
{% include '@partial/form-display-validationgroup.html.twig' with {'form': form, 'showLabels': true} %}

{{ form().closeTag() | raw }}

Expand Down

0 comments on commit 8c55a14

Please sign in to comment.