Esempio n. 1
0
 /**
  * Prepares view data for use by templating engine.
  *
  * @param View $view
  *
  * @return array
  */
 public function prepareTemplateParameters(View $view)
 {
     $data = $view->getData();
     if ($data instanceof FormInterface) {
         return array($view->getTemplateVar() => $data->getData(), 'form' => $data->createView());
     }
     if (empty($data) || !is_array($data) || is_numeric(key($data))) {
         return array($view->getTemplateVar() => $data);
     }
     if (isset($data['form']) && $data['form'] instanceof FormInterface) {
         $data['form'] = $data['form']->createView();
     }
     return $data;
 }
Esempio n. 2
0
 /**
  * Prepares view data for use by templating engine.
  *
  * @param View $view
  *
  * @return array
  */
 public function prepareTemplateParameters(View $view)
 {
     $data = $view->getData();
     if ($data instanceof FormInterface) {
         $data = [$view->getTemplateVar() => $data->getData(), 'form' => $data];
     } elseif (empty($data) || !is_array($data) || is_numeric(key($data))) {
         $data = [$view->getTemplateVar() => $data];
     }
     if (isset($data['form']) && $data['form'] instanceof FormInterface) {
         $data['form'] = $data['form']->createView();
     }
     $templateData = $view->getTemplateData();
     if (is_callable($templateData)) {
         $templateData = call_user_func($templateData, $this, $view);
     }
     return array_merge($data, $templateData);
 }
Esempio n. 3
0
 /**
  * Prepare view data for use by templating engine.
  *
  * @param View $view
  *
  * @return array
  */
 public function prepareTemplateParameters(View $view)
 {
     $data = $view->getData();
     if (empty($data)) {
         return array($view->getTemplateVar() => $data);
     }
     if (!is_array($data)) {
         $data = array($view->getTemplateVar() => $data);
     }
     foreach (array_keys($data) as $key) {
         if ($data[$key] instanceof FormInterface) {
             $data[$key] = $data[$key]->createView();
         }
     }
     if (is_numeric($key)) {
         $data = array($view->getTemplateVar() => $data);
     }
     return $data;
 }