嵌入时,字段帮助不会显示在父管理中的Sonata Admin中

时间:2013-11-11 17:41:38

标签: symfony sonata-admin symfony-sonata

我不知道这是交响乐还是奏鸣曲管理包问题。

我的主要MultimediaAdmin类有多个嵌入式FileAdmin条目。

class MultimediaAdmin extends Admin
{

protected function configureFormFields(FormMapper $formMapper)
{
    $formMapper

        ->with('Files')
            ->add('files','sonata_type_collection',
            array('label' => 'Multimedia Files',
                'btn_add'       => 'Add File',
                'by_reference' => 'false',
                'type_options' => array('delete' => false)
                ), array(
                    'edit' => 'inline',
                    'template' => 'MyMultimediaBundle:Multimedia:horizontal.fields.html.twig'
                )
            )
        ->end()
        ->with('Tags')
            ->add('tags')
        ->end()
    ;
}

}

我有一个自定义模板样式化嵌入式FileAdmin表单的外观,在几个字段中有一个显示编辑时上传媒体的预览。

/* horizontal.fields.html.twig */

<fieldset>
                    <div class="sonata-ba-collapsed-fields">
                    {% for nested_group_field_name, nested_group_field in form.children %}
                        {% for field_name, nested_field in nested_group_field.children %}
                        <div class="control-group">
                            <label class="control-label" for="nested_field.vars['sonata_admin'].admin.trans(nested_field.vars.label" {{ nested_field.vars['required']  ? 'class="required"' : '' }}>{{ nested_field.vars['sonata_admin'].admin.trans(nested_field.vars.label) }}</label>
                            <div class="controls">
                            {% if sonata_admin.field_description.associationadmin.formfielddescriptions[field_name] is defined %}                               

                                {{ form_widget(nested_field, {
                                    'inline': 'natural',
                                    'edit'  : 'inline'
                                }) }}
                                {% set dummy = nested_group_field.setrendered %}
                            {% else %}
                                {{ form_widget(nested_field) }}
                            {% endif %}
                                {% if sonata_admin.field_description.help %}
                <span class="help-block sonata-ba-field-help">{{ sonata_admin.admin.trans(sonata_admin.field_description.help, {}, sonata_admin.field_description.translationDomain)|raw }}</span>
            {% endif %}
                            </div>

                            </div>
                        {% endfor %}
                    {% endfor %}
                    </div>
                </fieldset>

这是FileAdmin,在编辑时添加了图像预览以显示缩略图

class FileAdmin extends Admin
{

protected function configureFormFields(FormMapper $formMapper)
{

        $media = $this->getSubject();


        // use $fileFieldOptions so we can add other options to the field
        $fileFieldOptions = array('required' => false,'label' => 'Files', 'attr' => array("multiple" => "multiple"), 'by_reference' => false);
        if ($media && ($webPath = $media->getWebPath())) {
            $fileFieldOptions['help'] = '<img src="'.$webPath.'" class="admin-preview" />';
        }
    $formMapper
        ->add('title','text',array('label'=>'Title'))
        ->add('abstract','textarea',array('label'=>'Abstract'))
        ->add('language')
        ->add('format')
        ->add('file', 'file', $fileFieldOptions)
        ->add('quality')
    ;
}
}

自定义表单在样式方面完美运行,但我唯一的问题是,它在以多媒体形式编辑嵌入文件时不显示图像预览。当我直接编辑文件时,而不是在MultimediaAdmin下,图像预览工作得很好。我哪里可能出错?

0 个答案:

没有答案