/** * 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); }
/** * @dataProvider setTemplateDataDataProvider */ public function testSetTemplateData($templateData) { $view = new View(); $view->setTemplateData($templateData); $this->assertEquals($templateData, $view->getTemplateData()); }