我有以下问题:
文章页面包含 - >多个ArticleUnit块包含 - >多媒体块
(编辑:请参阅下面的评论,了解我要缩进的内容摘要。)
我使用buttom-up方法单独构建表单,我目前处于工作状态的是:
<div id="field_container_s559a3c68b30e7_children" class="field-container">
<span id="field_widget_s559a3c68b30e7_children" >
<div>
</div>
</span>
<span id="field_actions_s559a3c68b30e7_children" >
<a
href="/Proximity_Projects/xx/refonte_2015/www/trunk/web/admin/xx/block/articleunitblock/create?uniqid=s559a3c8bf24d1&code=xx.block.admin.article_unit_block_admin&pcode=xx.article.admin.article.news&puniqid=s559a3c68b30e7"
onclick="return start_field_retrieve_s559a3c68b30e7_children(this);"
class="btn btn-success btn-sm btn-outline sonata-ba-action"
title="Add new"
>
<i class="icon-plus fa fa-plus-circle"></i>
Add new
</a>
</span>
<!-- edit one association -->
<script type="text/javascript">
// handle the add link
var field_add_s559a3c68b30e7_children = function(event) {
event.preventDefault();
event.stopPropagation();
var form = jQuery(this).closest('form');
// the ajax post
jQuery(form).ajaxSubmit({
url: 'http://localhost:8080/Proximity_Projects/xx/refonte_2015/www/trunk/web/admin/core/append-form-field-element?code=xx.article.admin.article.news&elementId=s559a3c68b30e7_children&uniqid=s559a3c68b30e7',
type: "POST",
dataType: 'html',
data: { _xml_http_request: true },
success: function(html) {
jQuery('#field_container_s559a3c68b30e7_children').replaceWith(html); // replace the html
if(jQuery('input[type="file"]', form).length > 0) {
jQuery(form).attr('enctype', 'multipart/form-data');
jQuery(form).attr('encoding', 'multipart/form-data');
}
jQuery('#sonata-ba-field-container-s559a3c68b30e7_children').trigger('sonata.add_element');
jQuery('#field_container_s559a3c68b30e7_children').trigger('sonata.add_element');
}
});
return false;
};
var field_widget_s559a3c68b30e7_children = false;
// this function initialize the popup
// this can be only done this way has popup can be cascaded
function start_field_retrieve_s559a3c68b30e7_children(link) {
link.onclick = null;
// initialize component
field_widget_s559a3c68b30e7_children = jQuery("#field_widget_s559a3c68b30e7_children");
// add the jQuery event to the a element
jQuery(link)
.click(field_add_s559a3c68b30e7_children)
.trigger('click')
;
return false;
}
</script>
<!-- / edit one association -->
</div>
/**
* Service name of the sonata_type_collection service to embed
* @var string
*/
protected $embeddedArticleUnit;
/**
* Configure the service name (admin_code) of the admin service for the embedded units
*
* @param string $adminCode
*/
public function setEmbeddedArticleUnitAdmin($adminCode)
{
$this->embeddedArticleUnit = $adminCode;
}
protected function configureFormFields(FormMapper $formMapper)
{
parent::configureFormFields($formMapper);
$formMapper
->with('form.group_general', ['name' => 'Details'])
->add('body', 'hidden', ['data' => 'default'])
->add('colour', 'choice', [
'choices' => [
'red' => 'Red',
'blue' => 'Blue',
'yellow' => 'Yellow',
],
])
->end()
->with('Items')
->add('children', 'sonata_type_collection',
['label' => 'Text'],
[
'edit' => 'inline',
'inline' => 'standard',
'admin_code' => $this->embeddedArticleUnit,
])
->end();
}
xx.article.admin.article.news:
class: xx\ArticleBundle\Admin\NewsAdmin
arguments:
- ''
- xx\ArticleBundle\Document\News
- 'SonataAdminBundle:CRUD'
tags:
- { name: sonata.admin, manager_type: doctrine_phpcr, group: 'xx Dashboard', label: 'News' }
calls:
- [setRouteBuilder, ['@sonata.admin.route.path_info_slashes']]
- [setRootPath, ['%cmf_base_page_article_news%']]
- [setContainer,[@service_container]]
- [setEmbeddedArticleUnitAdmin, ['xx.block.admin.article_unit_block_admin']]
- [setEmbeddedMediaBlockAdmin, ['xx.block.admin.media_block_admin_header_image']]
/**
* {@inheritdoc}
*/
protected function configureFormFields(FormMapper $formMapper)
{
$formMapper
->with('form.group_general', ['name' => 'General'])
->add('body', 'textarea', ['required' => false])
->add('mediaPosition', 'choice', [
'choices' => [
'bottom' => 'Bottom',
'right' => 'Right',
'left' => 'Left',
],
])
->add('parentDocument', 'doctrine_phpcr_odm_tree', ['root_node' => $this->getRootPath(), 'choice_list' => [], 'select_root_node' => true])
->add('position', 'hidden', array('mapped' => false))
->end()
->with('Items')
->add('children', 'sonata_type_collection',
['label' => 'Image(s)'],
[
'edit' => 'inline',
'inline' => 'table',
'admin_code' => $this->embeddedAdminCode,
'sortable' => 'position',
])
->end()
;
}
xx.block.admin.article_unit_block_admin:
class: xx\BlockBundle\Admin\ArticleUnitBlockAdmin
arguments:
- ''
- xx\BlockBundle\Document\ArticleUnitBlock
- 'SonataAdminBundle:CRUD'
tags:
- { name: sonata.admin, manager_type: doctrine_phpcr, group: 'xx Dashboard', label: 'Article Unit Block' }
calls:
- [setRouteBuilder, ['@sonata.admin.route.path_info_slashes']]
- [setEmbeddedMediaAdmin, ['xx.block.admin.media_block_admin']]
- [setRootPath, ['%cmf_base_block%']]
/**
* {@inheritdoc}
*/
protected function configureFormFields(FormMapper $formMapper)
{
parent::configureFormFields($formMapper);
$formMapper
->with('form.group_general')
->remove('filter')
->remove('name')
->remove('position')
->add('imageMobile', 'cmf_media_image', ['required' => false])
->add('imageTablet', 'cmf_media_image', ['required' => false])
->add('label', 'text', ['label' => 'Label (Alt)'])
->add('position', 'hidden', array('mapped' => false))
->end();
}
xx.block.admin.media_block_admin:
class: xx\BlockBundle\Admin\MediaBlockAdmin
arguments:
- ''
- xx\BlockBundle\Document\MediaBlock
- 'SonataAdminBundle:CRUD'
tags:
- { name: sonata.admin, manager_type: doctrine_phpcr, group: 'xx Dashboard', label: 'Media Block' }
calls:
- [setRouteBuilder, ['@sonata.admin.route.path_info_slashes']]
- [setRootPath, ['%cmf_base_block%']]
感谢阅读。有什么想法/建议吗? :)