public function testBlockRendering() { $view = new BlockView(); $blockName = 'test'; $variables = ['foo' => 'bar']; $this->renderer->expects($this->once())->method('renderBlock')->with($this->identicalTo($view), $blockName, $variables); $this->helper->block($view, $blockName, $variables); }
/** * @param FormInterface $form * * @return FormView */ private function createFormView(FormInterface $form) { $themes = $this->getParameterResolver()->resolveThemes(); $view = $form->createView(); if (!empty($themes)) { $this->formRenderer->setTheme($view, $themes); } return $view; }
public function testViewWithForms() { $this->parameterResolver->expects($this->once())->method('resolveApi')->will($this->returnValue(false)); $event = $this->createViewEventMock(); $event->expects($this->once())->method('getView')->will($this->returnValue($view = $this->createViewMock())); $view->expects($this->once())->method('getData')->will($this->returnValue([$object = new \stdClass(), $form = $this->createFormMock()])); $form->expects($this->once())->method('createView')->will($this->returnValue($formView = $this->createFormViewMock())); $this->parameterResolver->expects($this->once())->method('resolveThemes')->will($this->returnValue($themes = ['theme'])); $this->formRenderer->expects($this->once())->method('setTheme')->with($this->identicalTo($formView), $this->identicalTo($themes)); $view->expects($this->once())->method('setData')->with($this->identicalTo([$object, $formView])); $this->subscriber->onView($event); }
/** * @param ViewEvent $event */ public function onView(ViewEvent $event) { if ($this->getParameterResolver()->resolveApi()) { return; } $view = $event->getView(); $data = $grid = $view->getData(); if (is_array($data) && isset($data['grid']) && $data['grid'] instanceof GridViewInterface) { $grid = $data['grid']; } if (!$grid instanceof GridViewInterface) { return; } if ($grid->getBatchForm() === null) { $batchForm = !isset($data['batch_form']) || !$data['batch_form'] instanceof FormInterface ? $this->formFactory->create(GridBatchType::class, null, ['grid' => $grid]) : $data['batch_form']; $grid->setBatchForm($batchForm->createView()); } $themes = $this->getParameterResolver()->resolveThemes(); if (!empty($themes)) { $this->formRenderer->setTheme($grid->getForm(), $themes); $this->formRenderer->setTheme($grid->getBatchForm(), $themes); } $view->setTemplateVar('grid')->setData($grid); }
public function testViewFormThemes() { $this->parameterResolver->expects($this->once())->method('resolveApi')->will($this->returnValue(false)); $this->parameterResolver->expects($this->once())->method('resolveThemes')->will($this->returnValue($themes = ['theme'])); $event = $this->createViewEventMock(); $event->expects($this->once())->method('getView')->will($this->returnValue($view = $this->createViewMock())); $view->expects($this->once())->method('getData')->will($this->returnValue(['grid' => $gridView = $this->createGridViewMock(), 'batch_form' => $batchForm = $this->createFormMock()])); $batchForm->expects($this->once())->method('createView')->will($this->returnValue($batchFormView = $this->createFormViewMock())); $gridView->expects($this->once())->method('setBatchForm')->with($this->identicalTo($batchFormView)); $gridView->expects($this->once())->method('getForm')->will($this->returnValue($formView = $this->createFormViewMock())); $gridView->expects($this->exactly(2))->method('getBatchForm')->willReturnOnConsecutiveCalls(null, $batchFormView); $this->formRenderer->expects($this->exactly(2))->method('setTheme')->withConsecutive([$formView, $themes], [$batchFormView, $themes]); $view->expects($this->once())->method('setTemplateVar')->with($this->identicalTo('grid'))->will($this->returnSelf()); $view->expects($this->once())->method('setData')->with($this->identicalTo($gridView)); $this->subscriber->onView($event); }
public function testApiWithHateoas() { $this->parameterResolver->expects($this->once())->method('resolveApi')->will($this->returnValue(true)); $this->parameterResolver->expects($this->once())->method('resolveHateoas')->will($this->returnValue(true)); $event = $this->createViewEventMock(); $event->expects($this->once())->method('getView')->will($this->returnValue($view = $this->createViewMock())); $view->expects($this->once())->method('getData')->will($this->returnValue($pagerfanta = $this->createPagerfantaMock())); $this->requestStack->expects($this->once())->method('getMasterRequest')->will($this->returnValue($request = $this->createRequestMock())); $request->attributes->expects($this->exactly(2))->method('get')->will($this->returnValueMap([['_route', null, $route = 'route'], ['_route_params', [], $routeParameters = ['foo' => 'bar']]])); $request->query->expects($this->once())->method('all')->will($this->returnValue($queryParameters = ['baz' => 'bat'])); $this->pagerfantaFactory->expects($this->once())->method('createRepresentation')->with($this->identicalTo($pagerfanta), $this->callback(function ($config) use($route, $routeParameters, $queryParameters) { return $config instanceof Route && $config->getName() === $route && $config->getParameters() === array_merge($routeParameters, $queryParameters); }))->will($this->returnValue($representation = 'representation')); $view->expects($this->once())->method('setData')->with($this->identicalTo($representation)); $this->subscriber->onApi($event); }
public function humanize($text) { return $this->renderer->humanize($text); }
/** * Renders the HTML enctype in the form tag, if necessary. * * Example usage in Smarty templates: * * <form action="..." method="post" {form_enctype form=$form}> * * @param array $params Attributes passed from the template. * @param object $template The \Smarty_Internal_Template instance. * * @return string The HTML markup */ public function renderEnctype($params, \Smarty_Internal_Template $template) { list($view, $parameters) = $this->extractFunctionParameters($params); return $this->renderer->searchAndRenderBlock($view, 'enctype'); }
/** * Renders all unrendered children of the given form. * * @param FormView $view * @param array $variables * @return string */ public function rest(FormView $view, array $variables = []) { return $this->renderer->searchAndRenderBlock($view, 'rest', $variables); }
/** * Render Function Form Javascript * * @param FormView $view * @param bool $prototype * * @return string */ public function renderJavascript(FormView $view, $prototype = false) { $block = $prototype ? 'javascript_prototype' : 'javascript'; return $this->renderer->searchAndRenderBlock($view, $block); }
/** * Renders a block of the template * * @param BlockView $view The view for determining the used themes. * @param string $blockName The name of the block to render. * @param array $variables The variable to pass to the template. * * @return string */ public function block(BlockView $view, $blockName, array $variables = []) { return $this->renderer->renderBlock($view, $blockName, $variables); }
/** * Render Function Form Stylesheet * @param FormView $view * * @return string */ public function renderStylesheet(FormView $view) { return $this->renderer->searchAndRenderBlock($view, 'afe_stylesheet'); }
/** * {@inheritdoc} */ public function setBlockTheme(BlockView $view, $themes) { $this->innerRenderer->setTheme($view, $themes); }
/** * {@inheritdoc} */ public function initRuntime(\Twig_Environment $environment) { $this->renderer->setEnvironment($environment); }