Overloaded to track all templates used in the current request

{@inheritDoc}
2702
public function process($item, $arguments = null, $inheritedScope = null)
    {
        self::trackTemplateUsed($this->chosen);
        return parent::process($item, $arguments, $inheritedScope);
    }
1167781
public function templater()
    {
        if ($this->_templater === null) {
            $class = $this->getConfig('templateClass') ?: 'Cake\View\StringTemplate';
            $this->_templater = new $class();

            $templates = $this->getConfig('templates');
            if ($templates) {
                if (is_string($templates)) {
                    $this->_templater->add($this->_defaultConfig['templates']);
                    $this->_templater->load($templates);
                } else {
                    $this->_templater->add($templates);
                }
            }
        }

        return $this->_templater;
    }
1356163
public function loadRegisteredTemplates()
    {
        foreach ($this->callbacks as $callback) {
            $callback($this);
        }

        $plugins = PluginManager::instance()->getPlugins();
        foreach ($plugins as $pluginId => $pluginObj) {
            $layouts = $pluginObj->registerMailLayouts();
            if (is_array($layouts)) {
                $this->registerMailLayouts($layouts);
            }

            $templates = $pluginObj->registerMailTemplates();
            if (is_array($templates)) {
                $this->registerMailTemplates($templates);
            }

            $partials = $pluginObj->registerMailPartials();
            if (is_array($partials)) {
                $this->registerMailPartials($partials);
            }
        }
    }
1048790
protected function generateTemplate()
    {
        $st_annotations = $this->extractAnnotations();

        $template = array();
        $counter = 0;
        $section = null;
        $partial_template = $this->loadPartialTemplate('main');

        foreach ($st_annotations as $class => $methods) {
            foreach ($methods as $name => $docs) {
                if (isset($docs['ApiDescription'][0]['section'])) {
                  $section = $docs['ApiDescription'][0]['section'];
                }elseif(isset($docs['ApiSector'][0]['name'])){
                    $section = $docs['ApiSector'][0]['name'];
                }else{
                    $section = $class;
                }
                if (0 === count($docs)) {
                    continue;
                }

                $sampleOutput = $this->generateSampleOutput($docs, $counter);

                $tr = array(
                    '{{ elt_id }}'                  => $counter,
                    '{{ method }}'                  => $this->generateBadgeForMethod($docs),
                    '{{ route }}'                   => $docs['ApiRoute'][0]['name'],
                    '{{ description }}'             => $docs['ApiDescription'][0]['description'],
                    '{{ headers }}'                 => $this->generateHeadersTemplate($counter, $docs),
                    '{{ parameters }}'              => $this->generateParamsTemplate($counter, $docs),
                    '{{ body }}'                    => $this->generateBodyTemplate($counter, $docs),
                    '{{ sandbox_form }}'            => $this->generateSandboxForm($docs, $counter),
                    '{{ sample_response_headers }}' => $sampleOutput[0],
                    '{{ sample_response_body }}'    => $sampleOutput[1]
                );

                $template[$section][] = strtr($partial_template, $tr);
                $counter++;
            }
        }

        $output = '';

        foreach ($template as $key => $value) {
          array_unshift($value, '<h2>' . $key . '</h2>');
          $output .= implode(PHP_EOL, $value);
        }

        $this->saveTemplate($output, $this->_output_file);

        return true;
    }
971766
public function listTemplates( $templateType = null ){
        $queryParams = is_null( $templateType ) ? [] : [ 'type' => $templateType ];
        return $this->httpGet( self::PATH_TEMPLATE_LIST, $queryParams );
    }
11259
public function fetchTemplate(Request $request, $template)
    {
        if (!$this->view instanceof Twig) {
            throw new Exception("Twig provider not registered.");
        }

        foreach ($this->settings['view']['global'] as $key => $map) {
            $key = is_numeric($key) ? $map : $key;

            switch ($key) {
                case 'request':
                    $value = $request;
                    break;

                default:
                    $value = isset($this->container[$key]) ? $this->container[$key] : null;
                    break;
            }

            $this->view->getEnvironment()->addGlobal($map, $value);
        }

        $result = $this->view->fetch(
            $template . $this->settings['view']['extension'],
            $this->data->all()
        );

        return $result;
    }
650251
function getTemplatesTasks(baseTask, app) {
	var tasks = [];
	var templates = getTemplates(app);

	if (templates) {
		for (index = 0; index < templates.length; ++index) {
		    tasks.push(baseTask + '.' + templates[index]);
		}
	}

	return tasks;
}
339646
function transformTemplates(templates) {
  const allTemplates = {
    ...templates,
    submit: templates.searchableSubmit,
    reset: templates.searchableReset,
    loadingIndicator: templates.searchableLoadingIndicator,
  };

  const {
    searchableReset,
    searchableSubmit,
    searchableLoadingIndicator,
    ...transformedTemplates
  } = allTemplates;

  return transformedTemplates;
}
1257446
public function getTemplate() : ?string 
    {
        if ( ! $this->hasTemplate()) {
            $this->setTemplate($this->getDefaultTemplate());
        }
        return $this->template;
    }
1107185
function loadTemplates()
    {
        $result[0] = array();
        $result[1] = array();
        $templates = Templates::getInstance();
        $list = $templates->enum();
        $result[0]= array_values($list);
        $result[1]= array_keys($list);
        return $result;
    }
99132
public function updateTemplateDataAction()
    {
        $request = $this->getRequest();
        $templateId = null;
        $status  = 0;
        $errors  = array();
        $textTitle = 'tr_tool_template_fm_update_title';
        $textMessage = '';

        $eventDatas = array();
        $this->getEventManager()->trigger('meliscms_template_save_start', $this, $eventDatas);

        // translator
        $translator = $this->getServiceLocator()->get('translator');

        // get the service for Templates Model & Table
        $templatesModel = $this->getServiceLocator()->get('MelisEngineTableTemplate');
        $siteTable = $this->getServiceLocator()->get('MelisEngineTableSite');
        // declare the Tool service that we will be using to completely create our tool.
        $melisTool = $this->getServiceLocator()->get('MelisCoreTool');

        // tell the Tool what configuration in the app.tool.php that will be used.
        $melisTool->setMelisToolKey('meliscms', 'meliscms_tool_templates');

        $templateUpdateForm = $melisTool->getForm('meliscms_tool_template_generic_form');

        // get the currently logged in user
        $melisCoreAuth = $this->serviceLocator->get('MelisCoreAuth');
        $userAuthDatas =  $melisCoreAuth->getStorage()->read();

        // make sure it's a POST call
        if($request->isPost())
        {

            $postValues = get_object_vars($this->getRequest()->getPost());
            $postValues = $melisTool->sanitizePost($postValues);

            $templateId = (int) $request->getPost('tpl_id');
            $templateUpdateForm->setData($postValues);

            if($templateUpdateForm->isValid())
            {
                $data = $templateUpdateForm->getData();
                $data['tpl_creation_date'] = date('Y-m-d H:i:s');
                $data['tpl_last_user_id'] = $userAuthDatas->usr_id;
                $site = $data['tpl_site_id'];

                $siteData = $siteTable->getEntryById($site)->current();
                $data['tpl_zf2_website_folder'] = !empty($siteData->site_name)? $siteData->site_name : '';

                if($data['tpl_type'] == 'PHP') {
                    $phpPath = $data['tpl_php_path'];

                    if(empty($phpPath)) {
                        $textMessage = 'tr_tool_template_fm_new_content_error';
                        $status = 0;
                        $errors= array(
                            'tpl_php_path' => array(
                                'empty_path' => $translator->translate('tr_meliscms_template_form_tpl_path_error_empty')
                            ),
                        );
                    }
                    elseif(strlen($phpPath)>150) {
                        $textMessage = 'tr_tool_template_fm_new_content_error';
                        $status = 0;
                        $errors= array(
                            'tpl_php_path' => array(
                                'path_too_long' => $translator->translate('tr_meliscms_template_form_tpl_path_error_high')
                            ),
                        );
                    }
                    elseif(empty($site)){
                        $textMessage = 'tr_tool_template_fm_new_content_error';
                        $status = 0;
                        $errors= array(
                            'tpl_site_id' => array(
                                'invalid_selection' => $translator->translate('tr_meliscms_template_form_tpl_site_id_error_empty')
                            ),
                        );
                    }
                    else {
                        $templatesModel->save($data, $templateId);
                        $textMessage = 'tr_tool_template_fm_update_content';
                        $status = 1;
                    }
                }
                elseif($data['tpl_type'] == 'ZF2') {
                    $tmpError = array();

                    $tplLayout = $data['tpl_zf2_layout'];
                    $tplController = $data['tpl_zf2_controller'];
                    $tplAction = $data['tpl_zf2_action'];

                    if(empty($tplLayout)) {
                        $textMessage = 'tr_tool_template_fm_new_content_error';
                        $status = 0;
                        $errors= array(
                            'tpl_zf2_layout' => array(
                                'empty' => $translator->translate('tr_meliscms_template_form_tpl_layout_error_empty')
                            ),
                        );
                    }
                    elseif(strlen($tplLayout)>50) {
                        $textMessage = 'tr_tool_template_fm_new_content_error';
                        $status = 0;
                        $errors= array(
                            'tpl_zf2_layout' => array(
                                'too_long' => $translator->translate('tr_meliscms_template_form_tpl_layout_error_high')
                            ),
                        );
                    }


                    if(empty($tplController)) {
                        $textMessage = 'tr_tool_template_fm_new_content_error';
                        $status = 0;
                        $errors= array(
                            'tpl_zf2_controller' => array(
                                'empty' => $translator->translate('tr_meliscms_template_form_tpl_controller_error_empty')
                            ),
                        );
                    }
                    elseif(strlen($tplController)>50) {
                        $textMessage = 'tr_tool_template_fm_new_content_error';
                        $status = 0;
                        $errors= array(
                            'tpl_zf2_controller' => array(
                                'too_long' => $translator->translate('tr_meliscms_template_form_tpl_controller_error_high')
                            ),
                        );
                    }

                    if(empty($tplAction)) {
                        $textMessage = 'tr_tool_template_fm_new_content_error';
                        $status = 0;
                        $errors= array(
                            'tpl_zf2_action' => array(
                                'empty' => $translator->translate('tr_meliscms_template_form_tpl_action_error_empty')
                            ),
                        );
                    }
                    elseif(strlen($tplAction)>50) {
                        $textMessage = 'tr_tool_template_fm_new_content_error';
                        $status = 0;
                        $errors= array(
                            'tpl_zf2_action' => array(
                                'too_long' => $translator->translate('tr_meliscms_template_form_tpl_action_error_high')
                            ),
                        );
                    }
                    elseif(empty($site)){
                        $textMessage = 'tr_tool_template_fm_new_content_error';
                        $status = 0;
                        $errors= array(
                            'tpl_site_id' => array(
                                'invalid_selection' => $translator->translate('tr_meliscms_template_form_tpl_site_id_error_empty')
                            ),
                        );
                    }

                    if(empty($errors)) {
                        $templatesModel->save($data, $templateId);
                        $textMessage = 'tr_tool_template_fm_update_content';
                        $status = 1;
                    }
                }


            }
            else {
                $textMessage = 'tr_tool_template_fm_update_content_error';
                $status = 0;
                $errors = $templateUpdateForm->getMessages();
            }

            // insert labels and error messages in error array
            $melisMelisCoreConfig = $this->serviceLocator->get('MelisCoreConfig');
            $appConfigForm = $melisMelisCoreConfig->getItem('meliscms/tools/meliscms_tool_templates/forms/meliscms_tool_template_generic_form');
            $appConfigForm = $appConfigForm['elements'];

            foreach ($errors as $keyError => $valueError)
            {
                foreach ($appConfigForm as $keyForm => $valueForm)
                {
                    if ($valueForm['spec']['name'] == $keyError &&
                        !empty($valueForm['spec']['options']['label']))
                        $errors[$keyError]['label'] = $valueForm['spec']['options']['label'];
                }
            }
        }

        $response = array(
            'success' => $status,
            'textTitle' => $textTitle,
            'textMessage' => $textMessage,
            'errors' => $errors,
        );

        $this->getEventManager()->trigger('meliscms_template_save_end', $this, array_merge($response, array('typeCode' => 'CMS_TEMPLATE_UPDATE', 'itemId' => $templateId)));

        return new JsonModel($response);
    }
85080
public function resolveTemplate($request_string)
    {
        $this->debug(sprintf('resolveTemplate: Resolving %s.', $request_string));

        $template = false;

        $this->buildTemplateIndex();

        // First break off any GET vars appended to the URL, splitting
        // either on '?' or '.html'.
        if (false !== strpos($request_string, '?')) {
            $request_string = substr($request_string, 0, strpos($request_string, '?'));
        } elseif (false !== strpos($request_string, '.html')) {
            $request_string = substr($request_string, 0, strpos($request_string, '.html') + 5);
        }

        // Append .html if not already there
        if ('.html' !== substr($request_string, -5)) {
            $request_string .= '.html';
        }

        $this->debug(sprintf('resolveTemplate: Matching relative template path %s.', $request_string));

        // Search the index for a matching template
        if (array_key_exists($request_string, $this->templateIndex)) {
            $template = $this->templateIndex[$request_string];

            $this->debug(sprintf(
                'resolveTemplate: Resolved Template %s (%s).',
                $template->getRenderName(),
                $template->getFilename()
            ));
        }

        return($template);
    }
1313107
public static function update_template($template) {

        $params = self::validate_parameters(self::update_template_parameters(), array('template' => $template));
        $params = $params['template'];
        $template = api::read_template($params['id']);
        self::validate_context($template->get_context());

        $params = (object) $params;

        return api::update_template($params);
    }
182063
public function getTemplates()
    {
        $templates_array = [];

        $templates_trait = new \ReflectionClass('App\GeoTemplates');
        $templates = $templates_trait->getMethods();

        if (! count($templates)) {
            abort('403', 'No templates have been found.');
        }

        return $templates;
    }
108247
function executeCompiledTemplate( $tpl, &$textElements,
                                      $keyData, $uri, $resourceData, $templatePath,
                                      &$extraParameters, $timestamp,
                                      $rootNamespace, $currentNamespace )
    {
        $key = $this->cacheKey( $keyData, $resourceData, $templatePath, $extraParameters );
        return eZTemplateCompiler::executeCompilation( $tpl, $textElements, $key, $resourceData,
                                                       $rootNamespace, $currentNamespace );
    }
467328
public function templateOptionsMetadata()
    {
        if ($this->areTemplateOptionsFinalized === false) {
            $this->areTemplateOptionsFinalized = true;
            $this->prepareTemplateOptions();
        }

        return $this->templateOptionsMetadata;
    }
99681
public function indexAction(Template $template)
    {
        $templating = $this->container->get('templating');

        $response = $this->getResponse(
            $templating->render(
                $template->getRenderName(),
                $template->getRenderData()
            )
        );

        return($response);
    }