Skip to content

Commit

Permalink
bug EasyCorp#1256 Improve forms to use custom variables instead of fi…
Browse files Browse the repository at this point in the history
…eld attributes (javiereguiluz)

This PR was squashed before being merged into the master branch (closes EasyCorp#1256).

Discussion
----------

Improve forms to use custom variables instead of field attributes

This fixes EasyCorp#1254. The solution was cleverly proposed by @ogizanagi in https://github.com/javiereguiluz/EasyAdminBundle/issues/1254#issuecomment-236534227 I just copied it 😁

Commits
-------

906fc8c Improve forms to use custom variables instead of field attributes
  • Loading branch information
javiereguiluz committed Aug 1, 2016
2 parents dc3b62b + 906fc8c commit a56532d
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
1 change: 1 addition & 0 deletions Form/Extension/EasyAdminExtension.php
Expand Up @@ -62,6 +62,7 @@ public function finishView(FormView $view, FormInterface $form, array $options)
'view' => $action,
'item' => $easyadmin['item'],
'field' => isset($fields[$view->vars['name']]) ? $fields[$view->vars['name']] : null,
'form_group' => $form->getConfig()->getAttribute('easyadmin_form_group'),
);
}
}
Expand Down
7 changes: 4 additions & 3 deletions Form/Type/EasyAdminFormType.php
Expand Up @@ -81,16 +81,17 @@ public function buildForm(FormBuilderInterface $builder, array $options)
continue;
}

$formFieldOptions['attr']['form_group'] = $currentFormGroup;

// 'divider' and 'section' are 'fake' form fields used to create the design
// elements of the complex form layouts: define them as unmapped and non-required
if (0 === strpos($metadata['property'], '_easyadmin_form_design_element_')) {
$formFieldOptions['mapped'] = false;
$formFieldOptions['required'] = false;
}

$builder->add($name, $formFieldType, $formFieldOptions);
$formField = $builder->getFormFactory()->createNamedBuilder($name, $formFieldType, null, $formFieldOptions);
$formField->setAttribute('easyadmin_form_group', $currentFormGroup);

$builder->add($formField);
}

$builder->setAttribute('easyadmin_form_groups', $formGroups);
Expand Down
2 changes: 1 addition & 1 deletion Resources/views/form/bootstrap_3_layout.html.twig
Expand Up @@ -439,7 +439,7 @@
{% endif %}

<div class="row">
{% for field in form.children if 'hidden' not in field.vars.block_prefixes and field.vars.attr.form_group == group_name %}
{% for field in form.children if 'hidden' not in field.vars.block_prefixes and field.vars.easyadmin.form_group == group_name %}
<div class="col-xs-12 {{ field.vars.easyadmin.field.css_class|default('') }}">
{{ form_row(field) }}
</div>
Expand Down

0 comments on commit a56532d

Please sign in to comment.