, . $parentAssociationMapping CommentAdmin, Thread, "admin" ( StoryThread). , , .
, StoryAdmin ( , CommentAdmin ), addChild:
acme_story.admin.story:
class: Acme\Bundle\StoryBundle\Admin\StoryAdmin
tags:
- { name: sonata.admin, manager_type: orm, group: content, label: Stories }
arguments: [null, Acme\Bundle\StoryBundle\Entity\Story, AcmeStoryBundle:StoryAdmin]
calls:
- [ addChild, [ @acme_comment.admin.comment ] ]
- [ setSecurityContext, [ @security.context ] ]
, , :
protected function configureSideMenu(MenuItemInterface $menu, $action, Admin $childAdmin = null)
{
$menu->addChild(
'comments',
array('uri' => $admin->generateUrl('acme_comment.admin.comment.list', array('id' => $id)))
);
}
CommentAdmin Thread (, StoryThread ) . $parentAssociationMapping, , , , , . CommentAdmin:
protected function configureDatagridFilters(DatagridMapper $filter)
{
$filter->add('thread');
}
public function getFilterParameters()
{
$parameters = parent::getFilterParameters();
return array_merge($parameters, array(
'thread' => array('value' => $this->getThread()->getId())
));
}
public function getNewInstance()
{
$comment = parent::getNewInstance();
$comment->setThread($this->getThread());
$comment->setAuthor($this->securityContext->getToken()->getUser());
return $comment;
}
protected function getParentObject()
{
return $this->getParent()->getObject($this->getParent()->getRequest()->get('id'));
}
protected function getThread()
{
$threadRepository = $this->em->getRepository($this->getParentObject()->getThreadEntityName());
return $threadRepository->findOneBy(array(
$threadRepository->getObjectColumn() => $this->getParentObject()->getId()
));
}
public function setEntityManager($em)
{
$this->em = $em;
}
public function setSecurityContext(SecurityContextInterface $securityContext)
{
$this->securityContext = $securityContext;
}