function setUpTemplate($parent, $name) { $template = new DynamicTemplate(); $template->ParentID = $parent->ID; $template->Name = $name; $template->Title = $name; $template->write(); return $template; }
function doImport($data, $form) { $errors = array(); DynamicTemplate::import_file($data['TemplateFile']['tmp_name'], $errors, $data['TemplateFile']['name']); if (count($errors) == 0) { $this->sessionMessage("Successfully imported template", 'good'); } else { die(print_r($errors, true)); $this->sessionMessage($errors[0], 'bad'); } $this->controller->redirectBack(); }
/** * After upload, extract the uploaded bundle. * @return */ function onAfterUpload() { // Extraction is only performed if the holder is present and the uploaded // file is being put in that folder. if (!($folder = DataObject::get_one("Folder", "\"Filename\"='assets/" . DynamicTemplate::$dynamic_template_folder . "'"))) { return; } if ($this->owner->ParentID != $folder->ID) { return; } $errors = array(); DynamicTemplate::extract_bundle($this->owner, &$errors); if (count($errors) > 0) { die("The following errors occurred on upload:<br/>" . implode("<br/>", $errors)); } }
public function importtarball($data, $form) { // Protect against CSRF on destructive action if (!SecurityToken::inst()->checkRequest($this->request)) { return $this->httpError(400); } $result = DynamicTemplate::import_file($data['ImportFile']['tmp_name'], $errors, $data['ImportFile']['name']); return $this->returnItemToUser($result); }
/** * Test loading the simple dynamic template with manifest. */ function testManifestLoad() { // $this->dump_files("testManifestLoad start"); $folder = DynamicTemplate::get()->filter("Name", "tmp-TemplateWithManifest")->First(); $manifest = $folder->getManifest(); $this->assertTrue(isset($manifest->actions['index']), "manifest has index action"); $this->assertEquals(count($manifest->actions), 1, "manifest has one action"); $this->assertTrue(isset($manifest->actions['index']['templates']), "manifest default action has templates"); $this->assertEquals(count($manifest->actions['index']['templates']), 1, "manifest default action has one template"); $this->assertTrue(strpos($manifest->actions['index']['templates'][0]['path'], 'test.ss') !== FALSE, "manifest default action has test.ss"); // Test manifest is cached. $m = unserialize($folder->ManifestCache); $this->assertTrue(is_object($m) && is_a($m, 'DynamicTemplateManifest'), "Cached manifest is a DynamicTemplateManifest"); $this->assertTrue(isset($m->actions["index"]), "Cached manifest has index"); }