Export this data so it can be used as the context for a mustache template.

@param renderer_base $output Renderer base.
@return stdClass
970576
public function export_for_template(renderer_base $output) {
        $data = new stdClass();
        $data->competencyframeworks = array();
        $data->pagecontextid = $this->pagecontext->id;
        foreach ($this->competencyframeworks as $framework) {
            $exporter = new competency_framework_exporter($framework);
            $data->competencyframeworks[] = $exporter->export($output);
        }
        $data->pluginbaseurl = (new moodle_url('/admin/tool/lp'))->out(true);
        $data->navigation = array();
        foreach ($this->navigation as $button) {
            $data->navigation[] = $output->render($button);
        }

        return $data;
    }
112288
public function export_for_template(renderer_base $output) {
        $data = parent::export_for_template($output);
        $data->courseid = $this->course->id;
        return $data;
    }
16392
public function export_for_template(renderer_base $output) {

        $data = (object) [
            'pluginbaseurl' => (new moodle_url('/admin/tool/policy'))->out(false),
        ];

        $data->policies = array_values($this->policies);
        if (!empty($this->returnurl)) {
            $data->returnurl = $this->returnurl;
        }

        array_walk($data->policies, function($item, $key) {
            $item->policytypestr = get_string('policydoctype'.$item->type, 'tool_policy');
            $item->policyaudiencestr = get_string('policydocaudience'.$item->audience, 'tool_policy');
        });

        return $data;
    }
926940
public function export_for_template(renderer_base $output) {
        global $DB;

        $usercompetencycourse = api::get_user_competency_in_course($this->courseid, $this->userid, $this->competencyid);
        $competency = $usercompetencycourse->get_competency();
        if (empty($usercompetencycourse) || empty($competency)) {
            throw new \invalid_parameter_exception('Invalid params. The competency does not belong to the course.');
        }

        $relatedcompetencies = api::list_related_competencies($competency->get('id'));
        $user = $DB->get_record('user', array('id' => $this->userid));
        $evidence = api::list_evidence_in_course($this->userid, $this->courseid, $this->competencyid);
        $course = $DB->get_record('course', array('id' => $this->courseid));

        $params = array(
            'competency' => $competency,
            'usercompetencycourse' => $usercompetencycourse,
            'evidence' => $evidence,
            'user' => $user,
            'course' => $course,
            'scale' => $competency->get_scale(),
            'relatedcompetencies' => $relatedcompetencies
        );
        $exporter = new user_competency_summary_in_course_exporter(null, $params);
        $data = $exporter->export($output);

        return $data;
    }
1230362
public function export_for_template(\renderer_base $output) {
        global $PAGE;

        $offset = $this->page * $this->perpage;

        $analysables = $this->model->get_analyser(['notimesplitting' => true])->get_analysables_iterator();

        $skipped = 0;
        $enoughresults = false;
        $morepages = false;
        $results = array();
        foreach ($analysables as $analysable) {

            if (!$analysable) {
                continue;
            }

            $validtraining = $this->model->get_target()->is_valid_analysable($analysable, true);
            if ($validtraining === true) {
                if ($this->model->is_static()) {
                    // We still want to show this analysable if it is not valid to get predictions.
                    $validtraining = get_string('notrainingbasedassumptions', 'analytics');
                } else {
                    // We skip analysables that are valid for training or valid for prediction.
                    continue;
                }
            }

            $validprediction = $this->model->get_target()->is_valid_analysable($analysable, false);
            if ($validprediction === true) {
                // We skip analysables that are valid for training or valid for prediction.
                continue;
            }

            if ($offset && $skipped < $offset) {
                $skipped++;
                continue;
            }

            // Add a new results if we don't have enough yet.
            if (!$enoughresults) {
                $results[$analysable->get_id()] = array($analysable, $validtraining, $validprediction);
                if ($this->perpage && count($results) === $this->perpage) {
                    $enoughresults = true;
                }
            } else {
                // Confirmed that we have results we can not fit into this page.
                $morepages = true;
                break;
            }
        }

        // Prepare the context object.
        $data = new \stdClass();
        $data->modelname = $this->model->get_name();

        if ($this->page > 0) {
            $prev = clone $PAGE->url;
            $prev->param('page', $this->page - 1);
            $button = new \single_button($prev, get_string('previouspage', 'tool_analytics'), 'get');
            $data->prev = $button->export_for_template($output);
        }
        if ($morepages) {
            $next = clone $PAGE->url;
            $next->param('page', $this->page + 1);
            $button = new \single_button($next, get_string('nextpage', 'tool_analytics'), 'get');
            $data->next = $button->export_for_template($output);
        }

        $data->analysables = [];
        foreach ($results as list($analysable, $validtraining, $validprediction)) {
            $obj = new \stdClass();
            $obj->url = \html_writer::link($analysable->get_context()->get_url(), $analysable->get_name(),
                array('target' => '_blank'));

            if ($validtraining !== true) {
                $obj->validtraining = $validtraining;
            }
            if ($validprediction !== true) {
                $obj->validprediction = $validprediction;
            }
            $data->analysables[] = $obj;
        }

        if (empty($data->analysables)) {
            $data->noanalysables = [
                'message' => get_string('noinvalidanalysables', 'tool_analytics'),
                'announce' => true,
            ];
        }
        return $data;
    }
194194
public function export_for_template(renderer_base $output) {
        $data = new stdClass();
        $attributes = $this->attributes;

        if (empty($attributes['id'])) {
            $attributes['id'] = html_writer::random_id('action_link');
        }
        $data->id = $attributes['id'];
        unset($attributes['id']);

        $data->disabled = !empty($attributes['disabled']);
        unset($attributes['disabled']);

        $data->text = $this->text instanceof renderable ? $output->render($this->text) : (string) $this->text;
        $data->url = $this->url ? $this->url->out(false) : '';
        $data->icon = $this->icon ? $this->icon->export_for_pix() : null;
        $data->classes = isset($attributes['class']) ? $attributes['class'] : '';
        unset($attributes['class']);

        $data->attributes = array_map(function($key, $value) {
            return [
                'name' => $key,
                'value' => $value
            ];
        }, array_keys($attributes), $attributes);

        $data->actions = array_map(function($action) use ($output) {
            return $action->export_for_template($output);
        }, !empty($this->actions) ? $this->actions : []);
        $data->hasactions = !empty($this->actions);

        return $data;
    }
704640
public function export_for_template(\renderer_base $output) {
        $data = new \stdClass();
        if ($this->prevlink) {
            $data->prevlink = $this->prevlink->export_for_template($output);
        }

        if ($this->nextlink) {
            $data->nextlink = $this->nextlink->export_for_template($output);
        }

        if ($this->activitylist) {
            $data->activitylist = $this->activitylist->export_for_template($output);
        }

        return $data;
    }
345772
public function export_for_template(renderer_base $output) {
        global $PAGE;

        $params = [\context_system::instance()->id, $this->defaultcontextlevel, $this->defaultcontextid];
        $PAGE->requires->js_call_amd('tool_dataprivacy/data_registry', 'init', $params);

        $data = new stdClass();
        $defaultsbutton = new \action_link(
            new \moodle_url('/admin/tool/dataprivacy/defaults.php'),
            get_string('setdefaults', 'tool_dataprivacy'),
            null,
            ['class' => 'btn btn-primary']
        );
        $data->defaultsbutton = $defaultsbutton->export_for_template($output);

        $actionmenu = new \action_menu();
        $actionmenu->set_menu_trigger(get_string('edit'), 'btn btn-primary');
        $actionmenu->set_owner_selector('dataregistry-actions');
        $actionmenu->set_alignment(\action_menu::TL, \action_menu::BL);

        $url = new \moodle_url('/admin/tool/dataprivacy/categories.php');
        $categories = new \action_menu_link_secondary($url, null, get_string('categories', 'tool_dataprivacy'));
        $actionmenu->add($categories);

        $url = new \moodle_url('/admin/tool/dataprivacy/purposes.php');
        $purposes = new \action_menu_link_secondary($url, null, get_string('purposes', 'tool_dataprivacy'));
        $actionmenu->add($purposes);

        $data->actions = $actionmenu->export_for_template($output);

        if (!data_registry::defaults_set()) {
            $data->info = (object)[
                    'message' => get_string('dataregistryinfo', 'tool_dataprivacy'),
                    'announce' => 1
            ];
            $data->nosystemdefaults = (object)[
                'message' => get_string('nosystemdefaults', 'tool_dataprivacy'),
                'announce' => 1
            ];
        }

        $data->tree = $this->get_default_tree_structure();

        return $data;
    }
665287
public function export_for_template(renderer_base $output) {
        global $USER;

        $nocoursesurl = $output->image_url('courses', 'block_recentlyaccessedcourses')->out(false);

        return [
            'userid' => $USER->id,
            'nocoursesimgurl' => $nocoursesurl,
            'pagingbar' => [
                'next' => true,
                'previous' => true
            ]
        ];
    }
16695
public function export_for_template(\renderer_base $output) {
        global $PAGE;

        $data = new \stdClass();

        $newmodelmenu = new \action_menu();
        $newmodelmenu->set_menu_trigger(get_string('newmodel', 'tool_analytics'), 'btn btn-default');
        $newmodelmenu->set_alignment(\action_menu::TL, \action_menu::BL);

        $newmodelmenu->add(new \action_menu_link(
            new \moodle_url('/admin/tool/analytics/createmodel.php'),
            new \pix_icon('i/edit', ''),
            get_string('createmodel', 'tool_analytics'),
            false
        ));

        $newmodelmenu->add(new \action_menu_link(
            new \moodle_url('/admin/tool/analytics/importmodel.php'),
            new \pix_icon('i/import', ''),
            get_string('importmodel', 'tool_analytics'),
            false
        ));

        $newmodelmenu->add(new \action_menu_link(
            new \moodle_url('/admin/tool/analytics/restoredefault.php'),
            new \pix_icon('i/reload', ''),
            get_string('restoredefault', 'tool_analytics'),
            false
        ));

        $data->newmodelmenu = $newmodelmenu->export_for_template($output);

        $onlycli = get_config('analytics', 'onlycli');
        if ($onlycli === false) {
            // Default applied if no config found.
            $onlycli = 1;
        }

        // Evaluation options.
        $timesplittingmethods = [
            ['id' => 'all', 'text' => get_string('alltimesplittingmethods', 'tool_analytics')],
        ];
        foreach (\core_analytics\manager::get_time_splitting_methods_for_evaluation(true) as $timesplitting) {
            $timesplittingmethods[] = [
                'id' => \tool_analytics\output\helper::class_to_option($timesplitting->get_id()),
                'text' => $timesplitting->get_name()->out(),
            ];
        }

        $data->models = array();
        foreach ($this->models as $model) {
            $modeldata = $model->export($output);

            // Check if there is a help icon for the target to show.
            $identifier = $modeldata->target->get_identifier();
            $component = $modeldata->target->get_component();
            if (get_string_manager()->string_exists($identifier . '_help', $component)) {
                $helpicon = new \help_icon($identifier, $component);
                $modeldata->targethelp = $helpicon->export_for_template($output);
            } else {
                // We really want to encourage developers to add help to their targets.
                debugging("The target '{$modeldata->target}' should include a '{$identifier}_help' string to
                    describe its purpose.", DEBUG_DEVELOPER);
            }

            // Check if there is a help icon for the indicators to show.
            if (!empty($modeldata->indicators)) {
                $indicators = array();
                foreach ($modeldata->indicators as $ind) {
                    // Create the indicator with the details we want for the context.
                    $indicator = new \stdClass();
                    $indicator->name = $ind->out();
                    $identifier = $ind->get_identifier();
                    $component = $ind->get_component();
                    if (get_string_manager()->string_exists($identifier . '_help', $component)) {
                        $helpicon = new \help_icon($identifier, $component);
                        $indicator->help = $helpicon->export_for_template($output);
                    } else {
                        // We really want to encourage developers to add help to their indicators.
                        debugging("The indicator '{$ind}' should include a '{$identifier}_help' string to
                            describe its purpose.", DEBUG_DEVELOPER);
                    }
                    $indicators[] = $indicator;
                }
                $modeldata->indicators = $indicators;
            }

            $modeldata->indicatorsnum = count($modeldata->indicators);

            // Check if there is a help icon for the time splitting method.
            if (!empty($modeldata->timesplitting)) {
                $identifier = $modeldata->timesplitting->get_identifier();
                $component = $modeldata->timesplitting->get_component();
                if (get_string_manager()->string_exists($identifier . '_help', $component)) {
                    $helpicon = new \help_icon($identifier, $component);
                    $modeldata->timesplittinghelp = $helpicon->export_for_template($output);
                } else {
                    // We really want to encourage developers to add help to their time splitting methods.
                    debugging("The time splitting method '{$modeldata->timesplitting}' should include a '{$identifier}_help'
                        string to describe its purpose.", DEBUG_DEVELOPER);
                }
            } else {
                $helpicon = new \help_icon('timesplittingnotdefined', 'tool_analytics');
                $modeldata->timesplittinghelp = $helpicon->export_for_template($output);
            }

            // Has this model generated predictions?.
            $predictioncontexts = $model->get_predictions_contexts();

            // Model predictions list.
            if (!$model->is_enabled()) {
                $modeldata->noinsights = get_string('disabledmodel', 'analytics');
            } else if ($model->uses_insights()) {
                if ($predictioncontexts) {

                    foreach ($predictioncontexts as $contextid => $unused) {
                        // We prepare this to be used as single_select template options.
                        $context = \context::instance_by_id($contextid);

                        // Special name for system level predictions as showing "System is not visually nice".
                        if ($contextid == SYSCONTEXTID) {
                            $contextname = get_string('allpredictions', 'tool_analytics');
                        } else {
                            $contextname = shorten_text($context->get_context_name(true, true), 90);
                        }
                        $predictioncontexts[$contextid] = $contextname;
                    }
                    \core_collator::asort($predictioncontexts);

                    if (!empty($predictioncontexts)) {
                        $url = new \moodle_url('/report/insights/insights.php', array('modelid' => $model->get_id()));
                        $singleselect = new \single_select($url, 'contextid', $predictioncontexts);
                        $modeldata->insights = $singleselect->export_for_template($output);
                    }
                }

                if (empty($modeldata->insights)) {
                    if ($model->any_prediction_obtained()) {
                        $modeldata->noinsights = get_string('noinsights', 'analytics');
                    } else {
                        $modeldata->noinsights = get_string('nopredictionsyet', 'analytics');
                    }
                }

            } else {
                $modeldata->noinsights = get_string('noinsightsmodel', 'analytics');
            }

            // Actions.
            $actionsmenu = new \action_menu();
            $actionsmenu->set_menu_trigger(get_string('actions'));
            $actionsmenu->set_owner_selector('model-actions-' . $model->get_id());
            $actionsmenu->set_alignment(\action_menu::TL, \action_menu::BL);

            $urlparams = ['id' => $model->get_id(), 'sesskey' => sesskey()];

            // Get predictions.
            if (!$onlycli && $modeldata->enabled && !empty($modeldata->timesplitting)) {
                $urlparams['action'] = 'getpredictions';
                $url = new \moodle_url('model.php', $urlparams);
                $icon = new \action_menu_link_secondary($url, new \pix_icon('i/notifications',
                    get_string('getpredictions', 'tool_analytics')), get_string('getpredictions', 'tool_analytics'));
                $actionsmenu->add($icon);
            }

            // Evaluate machine-learning-based models.
            if (!$onlycli && $model->get_indicators() && !$model->is_static()) {

                // Extra is_trained call as trained_locally returns false if the model has not been trained yet.
                $trainedonlyexternally = !$model->trained_locally() && $model->is_trained();

                $actionid = 'evaluate-' . $model->get_id();

                $modeltimesplittingmethods = $timesplittingmethods;
                // Include the current time-splitting method as the default selection method the model already have one.
                if ($model->get_model_obj()->timesplitting) {
                    $currenttimesplitting = ['id' => 'current', 'text' => get_string('currenttimesplitting', 'tool_analytics')];
                    array_unshift($modeltimesplittingmethods, $currenttimesplitting);
                }

                $evaluateparams = [$actionid, $trainedonlyexternally, $modeltimesplittingmethods];
                $PAGE->requires->js_call_amd('tool_analytics/model', 'selectEvaluationOptions', $evaluateparams);
                $urlparams['action'] = 'evaluate';
                $url = new \moodle_url('model.php', $urlparams);
                $icon = new \action_menu_link_secondary($url, new \pix_icon('i/calc', get_string('evaluate', 'tool_analytics')),
                    get_string('evaluate', 'tool_analytics'), ['data-action-id' => $actionid]);
                $actionsmenu->add($icon);
            }

            // Machine-learning-based models evaluation log.
            if (!$model->is_static() && $model->get_logs()) {
                $urlparams['action'] = 'log';
                $url = new \moodle_url('model.php', $urlparams);
                $icon = new \action_menu_link_secondary($url, new \pix_icon('i/report', get_string('viewlog', 'tool_analytics')),
                    get_string('viewlog', 'tool_analytics'));
                $actionsmenu->add($icon);
            }

            // Edit model.
            $urlparams['action'] = 'edit';
            $url = new \moodle_url('model.php', $urlparams);
            $icon = new \action_menu_link_secondary($url, new \pix_icon('t/edit', get_string('edit')), get_string('edit'));
            $actionsmenu->add($icon);

            // Enable / disable.
            if ($model->is_enabled() || !empty($modeldata->timesplitting)) {
                // If there is no timesplitting method set, the model can not be enabled.
                if ($model->is_enabled()) {
                    $action = 'disable';
                    $text = get_string('disable');
                    $icontype = 't/block';
                } else {
                    $action = 'enable';
                    $text = get_string('enable');
                    $icontype = 'i/checked';
                }
                $urlparams['action'] = $action;
                $url = new \moodle_url('model.php', $urlparams);
                $icon = new \action_menu_link_secondary($url, new \pix_icon($icontype, $text), $text);
                $actionsmenu->add($icon);
            }

            // Export.
            if (!$model->is_static()) {

                $fullysetup = $model->get_indicators() && !empty($modeldata->timesplitting);
                $istrained = $model->is_trained();

                if ($fullysetup || $istrained) {

                    $url = new \moodle_url('model.php', $urlparams);
                    // Clear the previous action param from the URL, we will set it in JS.
                    $url->remove_params('action');

                    $actionid = 'export-' . $model->get_id();
                    $PAGE->requires->js_call_amd('tool_analytics/model', 'selectExportOptions',
                        [$actionid, $istrained]);

                    $icon = new \action_menu_link_secondary($url, new \pix_icon('i/export',
                        get_string('export', 'tool_analytics')), get_string('export', 'tool_analytics'),
                        ['data-action-id' => $actionid]);
                    $actionsmenu->add($icon);
                }
            }

            // Invalid analysables.
            $analyser = $model->get_analyser(['notimesplitting' => true]);
            if (!$analyser instanceof \core_analytics\local\analyser\sitewide) {
                $urlparams['action'] = 'invalidanalysables';
                $url = new \moodle_url('model.php', $urlparams);
                $pix = new \pix_icon('i/report', get_string('invalidanalysables', 'tool_analytics'));
                $icon = new \action_menu_link_secondary($url, $pix, get_string('invalidanalysables', 'tool_analytics'));
                $actionsmenu->add($icon);
            }

            // Clear model.
            if (!empty($predictioncontexts) || $model->is_trained()) {
                $actionid = 'clear-' . $model->get_id();
                $PAGE->requires->js_call_amd('tool_analytics/model', 'confirmAction', [$actionid, 'clear']);
                $urlparams['action'] = 'clear';
                $url = new \moodle_url('model.php', $urlparams);
                $icon = new \action_menu_link_secondary($url, new \pix_icon('e/cleanup_messy_code',
                    get_string('clearpredictions', 'tool_analytics')), get_string('clearpredictions', 'tool_analytics'),
                    ['data-action-id' => $actionid]);
                $actionsmenu->add($icon);
            }

            // Delete model.
            $actionid = 'delete-' . $model->get_id();
            $PAGE->requires->js_call_amd('tool_analytics/model', 'confirmAction', [$actionid, 'delete']);
            $urlparams['action'] = 'delete';
            $url = new \moodle_url('model.php', $urlparams);
            $icon = new \action_menu_link_secondary($url, new \pix_icon('t/delete',
                get_string('delete', 'tool_analytics')), get_string('delete', 'tool_analytics'),
                ['data-action-id' => $actionid]);
            $actionsmenu->add($icon);

            $modeldata->actions = $actionsmenu->export_for_template($output);

            $data->models[] = $modeldata;
        }

        if (!$onlycli) {
            $data->warnings = array(
                (object)array('message' => get_string('bettercli', 'tool_analytics'), 'closebutton' => true)
            );
        } else {
            $url = new \moodle_url('/admin/settings.php', array('section' => 'analyticssettings'),
                'id_s_analytics_onlycli');

            $langstrid = 'clievaluationandpredictionsnoadmin';
            if (is_siteadmin()) {
                $langstrid = 'clievaluationandpredictions';
            }
            $data->infos = array(
                (object)array('message' => get_string($langstrid, 'tool_analytics', $url->out()),
                    'closebutton' => true)
            );
        }

        return $data;
    }
45065
public function export_for_template(renderer_base $output) {
        $data = new stdClass();

        $url = new moodle_url('/admin/tool/dataprivacy/datadeletion.php');
        $options = [
            CONTEXT_USER => get_string('user'),
            CONTEXT_COURSE => get_string('course'),
            CONTEXT_MODULE => get_string('activitiesandresources', 'tool_dataprivacy'),
            CONTEXT_BLOCK => get_string('blocks'),
        ];
        $filterselector = new single_select($url, 'filter', $options, $this->filter, null);
        $data->filter = $filterselector->export_for_template($output);

        ob_start();
        $this->expiredcontextstable->out(helper::DEFAULT_PAGE_SIZE, true);
        $expiredcontexts = ob_get_contents();
        ob_end_clean();
        $data->expiredcontexts = $expiredcontexts;

        $data->existingcontexts = $this->expiredcontextstable->rawdata ? true : false;

        return $data;
    }
459159
public function export_for_template(renderer_base $output) {
        $data = new stdClass();

        $compstoreview = array();
        foreach ($this->compstoreview['competencies'] as $compdata) {
            $ucexporter = new user_competency_exporter($compdata->usercompetency,
                array('scale' => $compdata->competency->get_scale()));
            $compexporter = new competency_exporter($compdata->competency,
                array('context' => $compdata->competency->get_context()));
            $userexporter = new user_summary_exporter($compdata->user);
            $compstoreview[] = array(
                'usercompetency' => $ucexporter->export($output),
                'competency' => $compexporter->export($output),
                'user' => $userexporter->export($output),
            );
        }

        $data = array(
            'competencies' => $compstoreview,
            'pluginbaseurl' => (new moodle_url('/blocks/lp'))->out(false),
        );

        return $data;
    }
154868
public function export_for_template(renderer_base $output) {

        $nocoursesurl = $output->image_url('courses', 'block_myoverview')->out();

        $defaultvariables = [
            'nocoursesimg' => $nocoursesurl,
            'grouping' => $this->grouping,
            'sort' => $this->sort == BLOCK_MYOVERVIEW_SORTING_TITLE ? 'fullname' : 'ul.timeaccess desc',
            'view' => $this->view,
            'paging' => $this->paging,
            'displaycategories' => $this->displaycategories,
        ];

        $preferences = $this->get_preferences_as_booleans();
        return array_merge($defaultvariables, $preferences);

    }
1084528
public function export_for_template(renderer_base $output) {
        global $SITE, $CFG;

        $sitename = format_string($SITE->fullname);
        $supportname = $CFG->supportname;
        $supportemail = $CFG->supportemail;

        $context = [
            'sitename' => $sitename,
            'supportname' => $supportname,
            'supportemail' => $supportemail,
            'homelink' => new \moodle_url('/')
        ];

        return $context;
    }
853977
public function export_for_template(\renderer_base $output) {
        $data = new \stdClass();
        $data->action = (new \moodle_url('/admin/tool/policy/acceptances.php'))->out(false);

        $data->filteroptions = [];
        $originalfilteroptions = [];
        list($avilablefilters, $selectedoptions) = $this->build_available_filters();
        foreach ($avilablefilters as $value => $label) {
            $selected = in_array($value, $selectedoptions);
            $filteroption = (object)[
                'value' => $value,
                'label' => $label
            ];
            $originalfilteroptions[] = $filteroption;
            $filteroption->selected = $selected;
            $data->filteroptions[] = $filteroption;
        }
        $data->originaloptionsjson = json_encode($originalfilteroptions);
        return $data;
    }
214838
public function export_for_template(renderer_base $output) {
        global $CFG;

        require_once($CFG->libdir . '/externallib.php');

        $syscontext = context_system::instance();

        $context = new stdClass();
        $context->text = external_format_string($this->text, $syscontext->id);
        $context->url = $this->url ? $this->url->out() : null;
        $context->title = external_format_string($this->title, $syscontext->id);
        $context->sort = $this->sort;
        $context->children = array();
        if (preg_match("/^#+$/", $this->text)) {
            $context->divider = true;
        }
        $context->haschildren = !empty($this->children) && (count($this->children) > 0);
        foreach ($this->children as $child) {
            $child = $child->export_for_template($output);
            array_push($context->children, $child);
        }

        return $context;
    }
206152
public function export_for_template(\renderer_base $output) {
        $data = new \stdClass();

        $fieldtypes = $this->handler->get_available_field_types();

        $data->component = $this->handler->get_component();
        $data->area = $this->handler->get_area();
        $data->itemid = $this->handler->get_itemid();
        $data->usescategories = $this->handler->uses_categories();
        $categories = $this->handler->get_categories_with_fields();

        $categoriesarray = array();

        foreach ($categories as $category) {

            $categoryarray = array();
            $categoryarray['id'] = $category->get('id');
            $categoryarray['nameeditable'] = $output->render(api::get_category_inplace_editable($category, true));
            $categoryarray['movetitle'] = get_string('movecategory', 'core_customfield',
                $category->get_formatted_name());

            $categoryarray['fields'] = array();

            foreach ($category->get_fields() as $field) {

                $fieldname = $field->get_formatted_name();
                $fieldarray['type'] = $fieldtypes[$field->get('type')];
                $fieldarray['id'] = $field->get('id');
                $fieldarray['name'] = $fieldname;
                $fieldarray['shortname'] = $field->get('shortname');
                $fieldarray['movetitle'] = get_string('movefield', 'core_customfield', $fieldname);

                $fieldarray['editfieldurl'] = (new \moodle_url('/customfield/edit.php', [
                        'id' => $fieldarray['id'],
                ]))->out(false);

                $categoryarray['fields'][] = $fieldarray;
            }

            $menu = new \action_menu();
            $menu->set_alignment(\action_menu::BL, \action_menu::BL);
            $menu->set_menu_trigger(get_string('createnewcustomfield', 'core_customfield'));

            $baseaddfieldurl = new \moodle_url('/customfield/edit.php',
                    array('action' => 'editfield', 'categoryid' => $category->get('id')));
            foreach ($fieldtypes as $type => $fieldname) {
                $addfieldurl = new \moodle_url($baseaddfieldurl, array('type' => $type));
                $action = new \action_menu_link_secondary($addfieldurl, null, $fieldname);
                $menu->add($action);
            }
            $menu->attributes['class'] .= ' float-left mr-1';

            $categoryarray['addfieldmenu'] = $output->render($menu);

            $categoriesarray[] = $categoryarray;
        }

        $data->categories = $categoriesarray;

        if (empty($data->categories)) {
            $data->nocategories = get_string('nocategories', 'core_customfield');
        }

        return $data;
    }