Skip to content

Commit

Permalink
Fix sonata_help not showing for subfields and add the has-error class (
Browse files Browse the repository at this point in the history
  • Loading branch information
gremo authored and greg0ire committed Sep 18, 2017
1 parent fb15e0e commit ff905e1
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
5 changes: 2 additions & 3 deletions Form/Extension/Field/Type/FormTypeFieldExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,13 @@ public function buildForm(FormBuilderInterface $builder, array $options)
public function buildView(FormView $view, FormInterface $form, array $options)
{
$sonataAdmin = $form->getConfig()->getAttribute('sonata_admin');
$sonataAdminHelp = isset($options['sonata_help']) ? $options['sonata_help'] : null;

/*
* We have a child, so we need to upgrade block prefix
*/
if ($view->parent && $view->parent->vars['sonata_admin_enabled'] && !$sonataAdmin['admin']) {
$blockPrefixes = $view->vars['block_prefixes'];

$baseName = str_replace('.', '_', $view->parent->vars['sonata_admin_code']);

$baseType = $blockPrefixes[count($blockPrefixes) - 2];
Expand All @@ -115,13 +115,12 @@ public function buildView(FormView $view, FormInterface $form, array $options)
'class' => false,
'options' => $this->options,
);
$view->vars['sonata_help'] = $sonataAdminHelp;
$view->vars['sonata_admin_code'] = $view->parent->vars['sonata_admin_code'];

return;
}

$sonataAdminHelp = isset($options['sonata_help']) ? $options['sonata_help'] : null;

// avoid to add extra information not required by non admin field
if ($sonataAdmin && $form->getConfig()->getAttribute('sonata_admin_enabled', true)) {
$sonataAdmin['value'] = $form->getData();
Expand Down
6 changes: 5 additions & 1 deletion Resources/views/Form/form_admin_fields.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,8 @@ file that was distributed with this source code.
{% block sonata_type_immutable_array_widget %}
{% spaceless %}
<div {{ block('widget_container_attributes') }}>
{{ block('sonata_help') }}

{{ form_errors(form) }}

{% for key, child in form %}
Expand All @@ -435,7 +437,7 @@ file that was distributed with this source code.

{% block sonata_type_immutable_array_widget_row %}
{% spaceless %}
<div class="form-group{% if child.vars.errors|length > 0%} error{%endif%}" id="sonata-ba-field-container-{{ id }}-{{ key }}">
<div class="form-group{% if child.vars.errors|length > 0%} has-error{%endif%}" id="sonata-ba-field-container-{{ id }}-{{ key }}">

{{ form_label(child) }}

Expand All @@ -446,6 +448,8 @@ file that was distributed with this source code.

<div class="{{ div_class }} sonata-ba-field sonata-ba-field-{{ sonata_admin.edit }}-{{ sonata_admin.inline }} {% if child.vars.errors|length > 0 %}sonata-ba-field-error{% endif %}">
{{ form_widget(child, {'horizontal': false, 'horizontal_input_wrapper_class': ''}) }} {# {'horizontal': false, 'horizontal_input_wrapper_class': ''} needed to avoid MopaBootstrapBundle messing with the DOM #}
{% set sonata_help = child.vars.sonata_help %}
{{ block('sonata_help') }}
</div>

{% if child.vars.errors|length > 0 %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ public function testbuildViewWithNestedForm()
'class' => false,
'options' => array(),
),
'sonata_help' => 'help text',
'sonata_admin_code' => 'parent_code',
);

Expand Down

0 comments on commit ff905e1

Please sign in to comment.