コード例 #1
0
 /**
  * Evaluate the TypoScript object at $path and return the rendered result.
  *
  * @param string $path Relative TypoScript path to be rendered
  * @param array $context Additional context variables to be set.
  * @param string $typoScriptPackageKey The key of the package to load TypoScript from, if not from the current context.
  * @return string
  * @throws \InvalidArgumentException
  */
 public function render($path, array $context = null, $typoScriptPackageKey = null)
 {
     if (strpos($path, '/') === 0 || strpos($path, '.') === 0) {
         throw new \InvalidArgumentException('When calling the TypoScript render view helper only relative paths are allowed.', 1368740480);
     }
     if (preg_match('/^[a-z0-9.]+$/i', $path) !== 1) {
         throw new \InvalidArgumentException('Invalid path given to the TypoScript render view helper ', 1368740484);
     }
     $slashSeparatedPath = str_replace('.', '/', $path);
     if ($typoScriptPackageKey === null) {
         /** @var $typoScriptObject AbstractTypoScriptObject */
         $typoScriptObject = $this->viewHelperVariableContainer->getView()->getTypoScriptObject();
         if ($context !== null) {
             $currentContext = $typoScriptObject->getTsRuntime()->getCurrentContext();
             foreach ($context as $key => $value) {
                 $currentContext[$key] = $value;
             }
             $typoScriptObject->getTsRuntime()->pushContextArray($currentContext);
         }
         $absolutePath = $typoScriptObject->getPath() . '/' . $slashSeparatedPath;
         $output = $typoScriptObject->getTsRuntime()->render($absolutePath);
         if ($context !== null) {
             $typoScriptObject->getTsRuntime()->popContext();
         }
     } else {
         $this->initializeTypoScriptView();
         $this->typoScriptView->setPackageKey($typoScriptPackageKey);
         $this->typoScriptView->setTypoScriptPath($slashSeparatedPath);
         if ($context !== null) {
             $this->typoScriptView->assignMultiple($context);
         }
         $output = $this->typoScriptView->render();
     }
     return $output;
 }
コード例 #2
0
 /**
  * Create a new list item
  *
  * @param string $label
  * @param ToDoList $list
  * @return void
  */
 public function addAction($label, ToDoList $list)
 {
     $item = new Item();
     $item->setLabel($label);
     $item->setList($list);
     $typoScriptView = new TypoScriptView();
     $typoScriptView->setControllerContext($this->controllerContext);
     $typoScriptView->setTypoScriptPath(self::TS_PATH_ITEM);
     $typoScriptView->assign('item', $item);
     $this->itemRepository->add($item);
     $this->view->assign('value', array('type' => 'success:add', 'entity' => get_class($item), 'view' => $typoScriptView->render()));
 }