Exemplo n.º 1
0
 /**
  * @param ViewEvent $event
  */
 public function onView(ViewEvent $event)
 {
     if ($this->getParameterResolver()->resolveApi()) {
         return;
     }
     $view = $event->getView();
     $view->setTemplate($this->getParameterResolver()->resolveTemplate())->setData([$view->getTemplateVar() ?: 'data' => $view->getData(), 'resource' => $event->getResource()]);
 }
Exemplo n.º 2
0
 /**
  * @param ViewEvent $event
  */
 public function onView(ViewEvent $event)
 {
     if ($this->getParameterResolver()->resolveApi()) {
         return;
     }
     $view = $event->getView();
     if ($view->getData() instanceof Pagerfanta) {
         $view->setTemplateVar(Inflector::pluralize($event->getResource()->getName()));
     }
 }
Exemplo n.º 3
0
 /**
  * @param ViewEvent $event
  */
 public function onView(ViewEvent $event)
 {
     if ($this->getParameterResolver()->resolveApi()) {
         return;
     }
     $view = $event->getView();
     $data = $view->getData();
     if ($data instanceof FormInterface) {
         $view->setTemplateVar('form')->setData($this->createFormView($data));
         return;
     }
     if (!is_array($data)) {
         return;
     }
     foreach ($data as $key => $value) {
         if ($value instanceof FormInterface) {
             $data[$key] = $this->createFormView($value);
         }
     }
     $view->setData($data);
 }
Exemplo n.º 4
0
 /**
  * @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);
 }
Exemplo n.º 5
0
 public function testInitialState()
 {
     $this->assertSame($this->resource, $this->event->getResource());
     $this->assertSame($this->action, $this->event->getAction());
     $this->assertSame($this->view, $this->event->getView());
 }
Exemplo n.º 6
0
 /**
  * @param string $action
  * @param View   $view
  *
  * @return Response
  */
 protected function processView($action, View $view)
 {
     $this->getRestEventDispatcher()->dispatch(RestEvents::VIEW, $event = new ViewEvent($this->resource, $action, $view));
     return $this->handleView($event->getView());
 }