Created
November 9, 2015 07:52
-
-
Save damyon/6f4ba523eeff1c0cb9ef to your computer and use it in GitHub Desktop.
external_hack_text
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Function to export the renderer data in a format that is suitable for a | |
* mustache template. This means raw records are generated as in to_record, | |
* but all strings are correctly passed through external_format_text (or external_format_string). | |
* | |
* @param renderer_base $output Used to do a final render of any components that need to be rendered for export. | |
* @return stdClass|array | |
*/ | |
public function export_for_template(renderer_base $output) { | |
$data = new stdClass(); | |
$properties = static::properties_definition(); | |
if (method_exists($this, 'get_context')) { | |
$context = $this->get_context(); | |
} else { | |
$context = context_system::instance(); | |
} | |
foreach ($properties as $property => $definition) { | |
if (!isset($data->$property)) { | |
$data->$property = $this->get($property); | |
if ($definition['type'] === PARAM_TEXT) { | |
$propertyformat = $property . 'format'; | |
if (isset($properties[$propertyformat])) { | |
$format = $this->get($propertyformat); | |
list($text, $format) = external_format_text($data->$property, $format, $context->id); | |
$data->$property = $text; | |
$data->$propertyformat = $format; | |
} else { | |
$data->$property = external_format_string($data->$property, $context->id); | |
} | |
} | |
} | |
} | |
return $data; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment