LimeSurvey API - Master branch

LSETwigViewRenderer extends ETwigViewRenderer
in package

Twig view renderer, LimeSurvey overload

Allow to run sandbox Configuration Provide different render methods for different context:

  • render() : for general use
  • renderQuestion() : to render a question. It checks if a question template view should be use, else core's view (used from qanda helper).
  • convertTwigToHtml() : to render a string without any file (used from replacement helper)

The only tricky point here is the path problematic (where should be searched the views to render?)

Tags
see:

http://twig.sensiolabs.org/doc/2.x/api.html#loaders

author

Leonid Svyatov leonid@svyatov.ru

author

Alexander Makarov sam@rmcreative.ru

link
http://github.com/yiiext/twig-renderer
link
http://twig.sensiolabs.org
version
1.1.15

Table of Contents

Properties

$sandboxConfig  : array<string|int, mixed>
$user_extensions  : array<string|int, mixed>
$_twig  : Twig_Environment|null

Methods

addExtensions()  : mixed
Adds custom extensions.
addUserExtensions()  : mixed
Adds custom user extensions
convertTwigToHtml()  : string
Convert a string containing twig tags to an HTML string.
getLoader()  : FileLoader
This is used to add paths in controller views.
getPathOfFile()  : string
Get the final source file for current context Currently used in theme editor
init()  : mixed
renderAnswerOptions()  : string
This method is used to render question's subquestions and answer options pages .
renderHtmlPage()  : mixed
Render the survey page, with the headers, the css, and the script If LS would use the normal Yii render flow, this function would not be necessary In previous LS version, this logic was here: https://github.com/LimeSurvey/LimeSurvey/blob/700b20e2ae918550bfbf283f433f07622480978b/application/controllers/survey/index.php#L62-L71
renderOptionPage()  : string
Render the option page of a template for the admin interface
renderPartial()  : string
get a twig file and return html produced
renderQuestion()  : string
This method is called from qanda helper to render a question view file.
renderTemplateForQuestionEditPreview()  : mixed|string
Main method to render a question in the question editor preview.
renderTemplateForTemplateEditor()  : string
This method is called from Template Editor.
renderTemplateFromFile()  : mixed|string
Main method to render a survey.
renderViewFromFile()  : string
Main method to render an admin page or block.
addRecursiveTemplatesPath()  : mixed
Twig can look for twig path in different path. This function will add the path of the template and all its parents to the load path So if a twig file is inclueded, it will look in the local template directory and all its parents
fixDataCoherence()  : array<string|int, mixed>
It can happen that user set incoherent values for options (like background is on, but no image file is selected) With some server configuration, it can lead to critical errors : empty values in image src or url() can block submition This function will check thoses cases. It can be used in the future for further checks
getAdditionalInfos()  : array<string|int, mixed>
In the LS2.x code, some of the render logic was duplicated on different files (surveyRuntime, frontend_helper, etc) In LS3, we did a first cycle of refactorisation. Some logic common to the different files are for now here, in this function.
getPluginsData()  : array<string|int, mixed>
Plugin event, should be replaced by Question Template
getTemplateForView()  : Template|bool
Find which template should be used to render a given view

Properties

$sandboxConfig

public array<string|int, mixed> $sandboxConfig = array()

Twig_Extension_Sandbox configuration

$user_extensions

public array<string|int, mixed> $user_extensions = []

Custom LS Users Extensions Example: array('HelloWorld_Twig_Extension')

Methods

addExtensions()

Adds custom extensions.

public addExtensions(array<string|int, mixed> $extensions) : mixed

It's different from the original Yii Twig Extension to take in account our custom sand box

Parameters
$extensions : array<string|int, mixed>

@see self::$extensions

addUserExtensions()

Adds custom user extensions

public addUserExtensions(array<string|int, mixed> $extensions) : mixed
Parameters
$extensions : array<string|int, mixed>

@see self::$user_extensions

convertTwigToHtml()

Convert a string containing twig tags to an HTML string.

public convertTwigToHtml(string $sString[, array<string|int, mixed> $aData = array() ][, TemplateConfiguration|null $oTemplate = null ]) : string
Parameters
$sString : string

The string of HTML/Twig to convert

$aData : array<string|int, mixed> = array()

Array containing the datas needed to render the view ($thissurvey)

$oTemplate : TemplateConfiguration|null = null
Tags
throws
Throwable
throws
Twig_Error_Loader
throws
Twig_Error_Syntax
Return values
string

getLoader()

This is used to add paths in controller views.

public getLoader() : FileLoader
Return values
FileLoader

getPathOfFile()

Get the final source file for current context Currently used in theme editor

public getPathOfFile(string $twigView[, TemplateConfiguration $oTemplate = null ][, array<string|int, string> $extraPath = array() ][, string|null $dirName = null ]) : string
Parameters
$twigView : string

twigfile to be used (with twig extension)

$oTemplate : TemplateConfiguration = null
$extraPath : array<string|int, string> = array()

path to be added before plugins add and core views

$dirName : string|null = null

directory name to be added as extra directory inside template view

Tags
throws
Exception
Return values
string

complete filename to be used

renderAnswerOptions()

This method is used to render question's subquestions and answer options pages .

public renderAnswerOptions(string $sView, array<string|int, mixed> $aData) : string

It first checks if the question use a template (set in display attributes) If it is the case, it will use the views of that template, else, it will render the core view.

Parameters
$sView : string

the view (layout) to render

$aData : array<string|int, mixed>

the datas needed for the view rendering

Tags
throws
CException
throws
Twig_Error_Loader
throws
Twig_Error_Syntax
Return values
string

the generated html

renderHtmlPage()

Render the survey page, with the headers, the css, and the script If LS would use the normal Yii render flow, this function would not be necessary In previous LS version, this logic was here: https://github.com/LimeSurvey/LimeSurvey/blob/700b20e2ae918550bfbf283f433f07622480978b/application/controllers/survey/index.php#L62-L71

public renderHtmlPage(string $sHtml, Template $oTemplate) : mixed
Parameters
$sHtml : string

The Html content of the page (it must not contain anymore any twig statement)

$oTemplate : Template

The name of the template to use to register the packages

renderOptionPage()

Render the option page of a template for the admin interface

public renderOptionPage(Template $oTemplate[, array<string|int, mixed> $renderArray = array() ]) : string
Parameters
$oTemplate : Template

the template where the custom option page should be looked for

$renderArray : array<string|int, mixed> = array()

Array that will be passed to the options.twig as variables.

Tags
throws
Throwable
throws
Twig_Error_Loader
throws
Twig_Error_Syntax
Return values
string

renderPartial()

get a twig file and return html produced

public renderPartial(string $twigView, array<string|int, mixed> $aData) : string
Parameters
$twigView : string

twigfile to be used (with twig extension)

$aData : array<string|int, mixed>

to be used

Tags
todo

find a way to fix in beforeCloseHtml @see https://bugs.limesurvey.org/view.php?id=13889

throws
Twig_Error_Loader
throws
Twig_Error_Syntax
Return values
string

renderQuestion()

This method is called from qanda helper to render a question view file.

public renderQuestion(string $sView, array<string|int, mixed> $aData) : string

It first checks if the question use a template (set in display attributes) If it is the case, it will use the views of that template, else, it will render the core view.

Parameters
$sView : string

the view (layout) to render

$aData : array<string|int, mixed>

the datas needed for the view rendering

Tags
throws
CException
throws
Twig_Error_Loader
throws
Twig_Error_Syntax
Return values
string

the generated html

renderTemplateForQuestionEditPreview()

Main method to render a question in the question editor preview.

public renderTemplateForQuestionEditPreview(string $sLayout, array<string|int, mixed> $aData[, bool $root = false ][, bool $bReturn = false ]) : mixed|string
Parameters
$sLayout : string

the name of the layout to render

$aData : array<string|int, mixed>

the datas needed to fill the layout

$root : bool = false
$bReturn : bool = false

if true, it will return the html string without rendering the whole page. Usefull for debuging, and used for Print Answers

Tags
throws
CException
throws
Throwable
throws
Twig_Error_Loader
throws
Twig_Error_Syntax
throws
WrongTemplateVersionException
Return values
mixed|string

renderTemplateForTemplateEditor()

This method is called from Template Editor.

public renderTemplateForTemplateEditor(string $sView, array<string|int, mixed> $aData, Template $oEditedTemplate) : string

It returns the HTML string needed for the tmp file using the template twig file.

Parameters
$sView : string

the view (layout) to render

$aData : array<string|int, mixed>

the datas needed for the view rendering

$oEditedTemplate : Template

the template to use

Tags
throws
Throwable
throws
Twig_Error_Loader
throws
Twig_Error_Syntax
todo

missing return statement (php warning)

Return values
string

the generated html

renderTemplateFromFile()

Main method to render a survey.

public renderTemplateFromFile(string $sLayout, array<string|int, mixed> $aData, bool $bReturn) : mixed|string
Parameters
$sLayout : string

the name of the layout to render

$aData : array<string|int, mixed>

the datas needed to fill the layout

$bReturn : bool

if true, it will return the html string without rendering the whole page. Usefull for debuging, and used for Print Answers

Tags
throws
CException
throws
Throwable
throws
Twig_Error_Loader
throws
Twig_Error_Syntax
throws
WrongTemplateVersionException
Return values
mixed|string

renderViewFromFile()

Main method to render an admin page or block.

public renderViewFromFile( $sLayoutFilePath, array<string|int, mixed> $aData[, bool $bReturn = false ][, bool $bUseRootDir = true ]) : string

Extendable to use admin templates in the future currently running on pathes, like the yii render methods go.

Parameters
$sLayoutFilePath :
$aData : array<string|int, mixed>

the datas needed to fill the layout

$bReturn : bool = false

if true, it will return the html string without rendering the whole page. Usefull for debuging, and used for Print Answers

$bUseRootDir : bool = true

Prepend application root dir to sLayoutFilePath if true.

Tags
throws
CException
throws
Throwable
throws
Twig_Error_Loader
throws
Twig_Error_Syntax
todo

missing return statement (php warning)

Return values
string

HTML

addRecursiveTemplatesPath()

Twig can look for twig path in different path. This function will add the path of the template and all its parents to the load path So if a twig file is inclueded, it will look in the local template directory and all its parents

private addRecursiveTemplatesPath(TemplateConfiguration $oTemplate[, array<string|int, string> $extraPaths = array() ][, string|null $dirName = null ]) : mixed
Parameters
$oTemplate : TemplateConfiguration

the template where to start

$extraPaths : array<string|int, string> = array()

to be added before template, parent template plugin add and core views. Example : question template

$dirName : string|null = null

directory name to be added as extra directory inside template view

fixDataCoherence()

It can happen that user set incoherent values for options (like background is on, but no image file is selected) With some server configuration, it can lead to critical errors : empty values in image src or url() can block submition This function will check thoses cases. It can be used in the future for further checks

private fixDataCoherence(array<string|int, mixed> $aData) : array<string|int, mixed>
Parameters
$aData : array<string|int, mixed>
Return values
array<string|int, mixed>

getAdditionalInfos()

In the LS2.x code, some of the render logic was duplicated on different files (surveyRuntime, frontend_helper, etc) In LS3, we did a first cycle of refactorisation. Some logic common to the different files are for now here, in this function.

private getAdditionalInfos(mixed $aData, TemplateConfiguration $oTemplate) : array<string|int, mixed>
Parameters
$aData : mixed
$oTemplate : TemplateConfiguration
Tags
todo

move all the display logic to surveyRuntime so we don't need this function here

Return values
array<string|int, mixed>

getPluginsData()

Plugin event, should be replaced by Question Template

private getPluginsData(string $sString, array<string|int, mixed> $aData) : array<string|int, mixed>
Parameters
$sString : string
$aData : array<string|int, mixed>
Return values
array<string|int, mixed>

        
On this page

Search results