/**
  * Small helper to render templates from strings
  * Cloned from SSViewerTest
  */
 private function render($templateString, $data = null)
 {
     $t = SSViewer::fromString($templateString);
     if (!$data) {
         $data = new SSViewerTestFixture();
     }
     return $t->process($data);
 }
 /**
  * Execute the evaluated string, passing it the given data.
  * Used by partial caching to evaluate custom cache keys expressed using
  * template expressions
  *
  * @param string $content Input string
  * @param mixed $data Data context
  * @param array $arguments Additional arguments
  * @return string Evaluated result
  */
 public static function execute_string($content, $data, $arguments = null)
 {
     $v = SSViewer::fromString($content);
     $v->includeRequirements(false);
     return $v->process($data, $arguments);
 }
 /**
  * Returns a json array of a search results that can be used by for example Jquery.ui.autosuggestion
  *
  * @param GridField $gridField
  * @param HTTPRequest $request
  * @return string
  */
 public function doSearch($gridField, $request)
 {
     $dataClass = $gridField->getModelClass();
     $allList = $this->searchList ? $this->searchList : DataList::create($dataClass);
     $searchFields = $this->getSearchFields() ? $this->getSearchFields() : $this->scaffoldSearchFields($dataClass);
     if (!$searchFields) {
         throw new LogicException(sprintf('GridFieldAddExistingAutocompleter: No searchable fields could be found for class "%s"', $dataClass));
     }
     $params = array();
     foreach ($searchFields as $searchField) {
         $name = strpos($searchField, ':') !== FALSE ? $searchField : "{$searchField}:StartsWith";
         $params[$name] = $request->getVar('gridfield_relationsearch');
     }
     $results = $allList->subtract($gridField->getList())->filterAny($params)->sort(strtok($searchFields[0], ':'), 'ASC')->limit($this->getResultsLimit());
     $json = array();
     Config::nest();
     SSViewer::config()->update('source_file_comments', false);
     $viewer = SSViewer::fromString($this->resultsFormat);
     foreach ($results as $result) {
         $title = html_entity_decode($viewer->process($result));
         $json[] = array('label' => $title, 'value' => $title, 'id' => $result->ID);
     }
     Config::unnest();
     return Convert::array2json($json);
 }
 /**
  * See {@link ViewableDataTest} for more extensive casting tests,
  * this test just ensures that basic casting is correctly applied during template parsing.
  */
 public function testCastingHelpers()
 {
     $vd = new SSViewerTest_ViewableData();
     $vd->TextValue = '<b>html</b>';
     $vd->HTMLValue = '<b>html</b>';
     $vd->UncastedValue = '<b>html</b>';
     // Value casted as "Text"
     $this->assertEquals('&lt;b&gt;html&lt;/b&gt;', $t = SSViewer::fromString('$TextValue')->process($vd));
     $this->assertEquals('<b>html</b>', $t = SSViewer::fromString('$TextValue.RAW')->process($vd));
     $this->assertEquals('&lt;b&gt;html&lt;/b&gt;', $t = SSViewer::fromString('$TextValue.XML')->process($vd));
     // Value casted as "HTMLText"
     $this->assertEquals('<b>html</b>', $t = SSViewer::fromString('$HTMLValue')->process($vd));
     $this->assertEquals('<b>html</b>', $t = SSViewer::fromString('$HTMLValue.RAW')->process($vd));
     $this->assertEquals('&lt;b&gt;html&lt;/b&gt;', $t = SSViewer::fromString('$HTMLValue.XML')->process($vd));
     // Uncasted value (falls back to ViewableData::$default_cast="Text")
     $vd = new SSViewerTest_ViewableData();
     $vd->UncastedValue = '<b>html</b>';
     $this->assertEquals('&lt;b&gt;html&lt;/b&gt;', $t = SSViewer::fromString('$UncastedValue')->process($vd));
     $this->assertEquals('<b>html</b>', $t = SSViewer::fromString('$UncastedValue.RAW')->process($vd));
     $this->assertEquals('&lt;b&gt;html&lt;/b&gt;', $t = SSViewer::fromString('$UncastedValue.XML')->process($vd));
 }