public function generateLayout($filename, Site $site = null, $extention = self::EXTENSION) { try { $data = Yaml::parse($filename); $uid = $this->getUidGenerator()->generateUid($filename, $data, $site); $layout = new Layout($uid); $layout->setPicPath($layout->getUid() . '.png'); if ($site !== null) { $layout->setSite($site); } if (array_key_exists('label', $data) && $data['label'] !== null) { $layout->setLabel($data['label']); } else { $layout->setLabel(basename($filename, '.' . self::EXTENSION)); } if (array_key_exists('template', $data)) { $this->computeTemplate($layout, $data['template']); } if (array_key_exists('columns', $data)) { $layout->setData($this->computeColumns($data['columns'])); } else { throw new LayoutYamlException('Layout ' . $layout->getLabel() . ' definition need columns', LayoutYamlException::NO_COLUMN_ERROR); } } catch (ParseException $e) { throw new LayoutYamlException($e->getMessage(), LayoutYamlException::LAYOUT_BUILD_ERROR, $e, $e->getParsedFile(), $e->getParsedLine()); } return $layout; }
protected function setUp() { $this->initAutoload(); $this->bbapp = $this->getBBApp(); $this->initDb($this->bbapp); $this->initAcl(); $this->bbapp->start(); // craete site $this->site = new Site(); $this->site->setLabel('sitelabel'); $this->site->setServerName('www.example.org'); // craete layout $this->layout = new Layout(); $this->layout->setSite($this->site); $this->layout->setLabel('defaultLayoutLabel'); $this->layout->setPath($this->bbapp->getBBDir() . '/Rest/Tests/Fixtures/Controller/defaultLayout.html.twig'); $this->layout->setData(json_encode(array('templateLayouts' => array('title' => 'zone_1234567')))); $this->site->addLayout($this->layout); $this->getEntityManager()->persist($this->layout); $this->getEntityManager()->persist($this->site); $this->getEntityManager()->flush(); }