MDL-75149 mod_data: add preview to presets

This commit is contained in:
Ferran Recio
2022-09-14 12:30:13 +02:00
parent c6211a68b4
commit 2b48b29c86
41 changed files with 1891 additions and 273 deletions
+8 -5
View File
@@ -76,6 +76,9 @@ class template {
/** @var array All template tags (calculated in load_template_tags). */
protected $tags = [];
/** @var array The mod_data fields. */
protected $fields = [];
/**
* Class contructor.
*
@@ -84,8 +87,9 @@ class template {
* @param manager $manager the current instance manager
* @param string $templatecontent the template string to use
* @param array $options an array of extra diplay options
* @param array $fields alternative array of fields (for preview presets)
*/
public function __construct(manager $manager, string $templatecontent, array $options = []) {
public function __construct(manager $manager, string $templatecontent, array $options = [], array $fields = null) {
$this->manager = $manager;
$this->instance = $manager->get_instance();
$this->templatecontent = $templatecontent;
@@ -93,6 +97,7 @@ class template {
$context = $manager->get_context();
$this->canmanageentries = has_capability('mod/data:manageentries', $context);
$this->icons = $this->get_icons();
$this->fields = $fields ?? $manager->get_fields();
$this->add_options($options);
$this->load_template_tags($templatecontent);
}
@@ -215,8 +220,7 @@ class template {
*/
private function get_fields_replacements(stdClass $entry): array {
$result = [];
$fields = $this->manager->get_fields();
foreach ($fields as $field) {
foreach ($this->fields as $field) {
// Field value.
$pattern = '[[' . $field->field->name . ']]';
$result[$pattern] = highlight(
@@ -448,8 +452,7 @@ class template {
['id' => $cm->id, 'recordid' => $entry->id],
'mod_data'
);
$fields = $this->manager->get_fields();
list($formats, $files) = data_portfolio_caller::formats($fields, $entry);
list($formats, $files) = data_portfolio_caller::formats($this->fields, $entry);
$button->set_formats($formats);
$result = $button->to_html(PORTFOLIO_ADD_ICON_LINK);
if (is_null($result)) {