sonata_type_collection在模态中编辑

时间:2016-09-25 19:40:01

标签: symfony sonata-admin

在我的项目中,我有链接到它们的页面和元素。元素只能链接到一个页面。

我有一个特定的表单来选择字段掩码和许多字段。我想有一个链接到页面而不是嵌入表单的元素列表。是否可以打开模态对话框以在其中包含编辑表单,例如添加元素时?

sonata_type_collection最适合吗?

PageAdmin

/**
 * @param FormMapper $formMapper
 */
protected function configureFormFields(FormMapper $formMapper) {
    $availableApiRoutes = [];
    foreach ($this->getConfigurationPool()->getContainer()->get('router')->getRouteCollection()->all() as $name => $route) {
        $route = $route->compile();
        if (( strstr($name, "api_") === FALSE ) &&
                ( strstr($name, "admin") === FALSE ) &&
                ( strstr($name, "ajax") === FALSE ) &&
                ( strstr($name, "fos") === FALSE ) &&
                ( strstr($name, "sonata") === FALSE ) &&
                ( strstr($name, "add") === FALSE ) &&
                ( strstr($name, "edit") === FALSE ) &&
                ( strstr($name, "payment") === FALSE ) &&
                ( strstr($name, "suppr") === FALSE ) &&
                ( substr($name, 0, 1) !== "_" )) {
            $availableApiRoutes[$name] = $name;
        }
    }
    $formMapper
            ->add('route', FormType\ChoiceType::class , array(
                'choices' => $availableApiRoutes,
            ))
            ->add('element', 'sonata_type_collection', array(), array('edit' => 'inline', 'inline'=>'table'))
    ;
}

元素形式:

ElementAdmin

/**
 * @param FormMapper $formMapper
 */
protected function configureFormFields(FormMapper $formMapper) {
    $formMapper
            ->add('page', 'sonata_type_model_hidden')
            ->add('id')
            ->add('title')
            ->add('type', 'sonata_type_choice_field_mask', array(
                'choices' => array(
                    'texte' => 'texte',
                    'image' => 'image',
                    'gallery' => 'gallerie'
                ),
                'map' => array(
                    'texte' => array('texte'),
                    'image' => array('image'),
                    'gallery' => array('gallery'),
                ),
                'empty_value' => 'Choose an option',
                'required' => true
            ))
            ->add('texte', CKEditorType::class, array(
                'config' => array(
                    'uiColor' => '#ffffff'
                )
            ))
            ->add('image', 'sonata_type_model_list', array(), array('link_parameters' => array('context' => 'cms')))
            ->add('gallery', 'sonata_type_model_list', array(), array(
                'edit' => 'inline',
                'inline' => 'table',
                'link_parameters' => array(
                    'context' => 'cms',
                    'provider' => 'sonata.media.provider.image'
                )
            ))
    ;
}

0 个答案:

没有答案