本文整理汇总了PHP中Sonata\AdminBundle\Admin\Pool::getAdminByAdminCode方法的典型用法代码示例。如果您正苦于以下问题:PHP Pool::getAdminByAdminCode方法的具体用法?PHP Pool::getAdminByAdminCode怎么用?PHP Pool::getAdminByAdminCode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Sonata\AdminBundle\Admin\Pool
的用法示例。
在下文中一共展示了Pool::getAdminByAdminCode方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: onKernelRequest
/**
* @param \Symfony\Component\HttpKernel\Event\GetResponseEvent $event
* @throws \RuntimeException
*/
public function onKernelRequest(GetResponseEvent $event)
{
$request = $event->getRequest();
if (!$request) {
return;
}
if (!$request->hasSession()) {
return;
}
$adminCode = $request->get('_sonata_admin');
if (!is_null($adminCode)) {
$this->admin = $this->adminPool->getAdminByAdminCode($adminCode);
if (!$this->admin) {
throw new \RuntimeException(sprintf('Unable to find the admin class related to the current controller (%s)', get_class($this)));
}
if (method_exists($this->admin, 'getTrackedActions')) {
foreach ($this->admin->getTrackedActions() as $trackedAction) {
// if an action which is flagged as 'to be tracked' is matching the end of the route: add info to session
if (preg_match('#' . $trackedAction . '$#', $request->get('_route'), $matches)) {
$this->updateTrackedInfo($request->getSession(), '_networking_initcms_admin_tracker', array('url' => $request->getRequestUri(), 'controller' => $this->admin->getBaseControllerName(), 'action' => $trackedAction));
}
}
}
}
}
示例2: testGetAdminByAdminCodeForChildClass
public function testGetAdminByAdminCodeForChildClass()
{
$adminMock = $this->getMockBuilder('Sonata\\AdminBundle\\Admin\\AdminInterface')->disableOriginalConstructor()->getMock();
$adminMock->expects($this->any())->method('hasChild')->will($this->returnValue(true));
$adminMock->expects($this->once())->method('getChild')->with($this->equalTo('sonata.news.admin.comment'))->will($this->returnValue('commentAdminClass'));
$containerMock = $this->getMock('Symfony\\Component\\DependencyInjection\\ContainerInterface');
$containerMock->expects($this->any())->method('get')->will($this->returnValue($adminMock));
$this->pool = new Pool($containerMock, 'Sonata', '/path/to/logo.png');
$this->assertEquals('commentAdminClass', $this->pool->getAdminByAdminCode('sonata.news.admin.post|sonata.news.admin.comment'));
}
示例3: getAdmin
/**
* @param ComponentInterface $component
*
* @return AdminInterface
*/
protected function getAdmin(ComponentInterface $component, ActionInterface $action = null)
{
if ($action && ($adminComponent = $action->getComponent('admin_code'))) {
return $this->pool->getAdminByAdminCode($adminComponent);
}
try {
return $this->pool->getAdminByClass($component->getModel());
} catch (\RuntimeException $e) {
}
return false;
}
示例4: execute
/**
* {@inheritdoc}
*/
public function execute(BlockContextInterface $blockContext, Response $response = null)
{
$admin = $this->pool->getAdminByAdminCode($blockContext->getSetting('code'));
$datagrid = $admin->getDatagrid();
$filters = $blockContext->getSetting('filters');
if (!isset($filters['_per_page'])) {
$filters['_per_page'] = array('value' => $blockContext->getSetting('limit'));
}
foreach ($filters as $name => $data) {
$datagrid->setValue($name, isset($data['type']) ? $data['type'] : null, $data['value']);
}
$datagrid->buildPager();
return $this->renderPrivateResponse($blockContext->getTemplate(), array('block' => $blockContext->getBlock(), 'settings' => $blockContext->getSettings(), 'admin_pool' => $this->pool, 'admin' => $admin, 'pager' => $datagrid->getPager(), 'datagrid' => $datagrid), $response);
}
示例5: execute
/**
* {@inheritdoc}
*/
public function execute(BlockContextInterface $blockContext, Response $response = null)
{
try {
$admin = $this->pool->getAdminByAdminCode($blockContext->getSetting('admin_code'));
} catch (ServiceNotFoundException $e) {
throw new \RuntimeException('Unable to find the Admin instance', $e->getCode(), $e);
}
if (!$admin instanceof AdminInterface) {
throw new \RuntimeException('The requested service is not an Admin instance');
}
if (!$admin->isGranted('LIST')) {
throw new AccessDeniedException();
}
$pager = $this->searchHandler->search($admin, $blockContext->getSetting('query'), $blockContext->getSetting('page'), $blockContext->getSetting('per_page'));
return $this->renderPrivateResponse($admin->getTemplate('search_result_block'), array('block' => $blockContext->getBlock(), 'settings' => $blockContext->getSettings(), 'admin_pool' => $this->pool, 'pager' => $pager, 'admin' => $admin), $response);
}