Edit an incident template.

@param \CachetHQ\Cachet\Models\IncidentTemplate $template

@return \Illuminate\Http\RedirectResponse
199164
public function editTemplateAction(IncidentTemplate $template)
    {
        try {
            $template->update(Binput::get('template'));
        } catch (ValidationException $e) {
            return cachet_redirect('dashboard.templates.edit', ['id' => $template->id])
                ->withUpdatedTemplate($template)
                ->withTemplateErrors($e->getMessageBag()->getErrors());
        }

        return cachet_redirect('dashboard.templates.edit', ['id' => $template->id])
            ->withUpdatedTemplate($template);
    }
995218
public function get($template)
    {
        $response = $this->request(self::REQUEST_GET, 'templates/'.$template);
        return $response->response;
    }
185268
public function edit(Request $request, $template)
    {
        $data = $this->getData();

        /**
         * Set workspace identifier
         */
        \PDFGeneratorAPI::setWorkspace($this->userRepository->getWorkspaceIdentifier(Auth::user()));

        return redirect()->away(\PDFGeneratorAPI::editor($template, $data));
    }
828744
public function createIncidentTemplateAction()
    {
        try {
            IncidentTemplate::create([
                'name'     => Binput::get('name'),
                'template' => Binput::get('template', null, false, false),
            ]);
        } catch (ValidationException $e) {
            return cachet_redirect('dashboard.templates.create')
                ->withInput(Binput::all())
                ->withTitle(sprintf('%s %s', trans('dashboard.notifications.whoops'), trans('dashboard.incidents.templates.add.failure')))
                ->withErrors($e->getMessageBag());
        }

        return cachet_redirect('dashboard.templates')
            ->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.incidents.templates.add.success')));
    }
375059
public function render_controller($template)
    {
        $this->controllerReplacements[':app_namespace'] = $this->getAppNamespace();
        $this->controllerReplacements[':resource'] = $this->identifier;
        $this->controllerReplacements[':model_name'] = $this->command->model_name($this->identifier);
        $this->controllerReplacements[':request_name'] = $this->command->request_name($this->identifier);
        $this->controllerReplacements[':controller_name'] = $this->command->controller_name($this->identifier);
        $this->controllerReplacements[':identifier'] = $this->identifier;

        $routeName = empty($this->routeNames) ? $this->identifier : 'admin.'.$this->identifier;

        if ($this->options['create']) {
            $this->controllerReplacements[':create_route'] = '$this->viewData'."['createRoute'] = '".$routeName.".create';";
        }

        if ($this->options['edit']) {
            $this->controllerReplacements[':edit_route'] = '$this->viewData'."['editRoute'] = '".$routeName.".edit';";
        }

        if ($this->options['destroy']) {
            $this->controllerReplacements[':destroy_route'] = '$this->viewData'."['deleteRoute'] = '".$routeName.".destroy';";
        }

        $template = strtr($template, $this->controllerReplacements);

        return $template;
    }
276422
public function createTemplate(Template &$template)
		{
			$form_data = array(
				'template_name' => $template->getName(),
				'template_subject' => $template->getSubject(),
				'template_body_plain' => $template->getBodyPlain(),
				'template_body_html' => $template->getBodyHtml(),
				'template_body_mobile' => $template->getBodyMobile(),
				'charset' => $template->getCharacterSet(),
				'encoding' => $template->getCharacterEncoding(),
				'folder_id' => $template->getFolderId()
			);
			$data = $this->call('createtemplate', $form_data);

			$template->setTemplateId(trim($data[1]));

			//return $template;
		}
620412
public function addTranslationAction($template = 'expendable::admin.form.components.datatable.translations', $route = '')
    {
        $this->add('translation', function($model) use ($template, $route) {

            $languages    = Language::withoutCurrentLanguage()->get();
            $translations = Translation::byElement($model)->pluck('id_element', 'iso')->toArray();
            return view($template, array(
                'languages'    => $languages,
                'translations' => $translations,
                'data'         => $model->toArray(),
                'route'        => !empty($route) ? $route.'@' : $this->getControllerNameForAction().'@'
            ))->render();
        });

    }
723581
private function publish($template)
    {
        if (! file_exists(app_path('Http' . DIRECTORY_SEPARATOR . 'Controllers' . DIRECTORY_SEPARATOR . 'Admin'))) {
            mkdir(app_path('Http' . DIRECTORY_SEPARATOR . 'Controllers' . DIRECTORY_SEPARATOR . 'Admin'));
            chmod(app_path('Http' . DIRECTORY_SEPARATOR . 'Controllers' . DIRECTORY_SEPARATOR . 'Admin'), 0777);
        }
        file_put_contents(app_path('Http' . DIRECTORY_SEPARATOR . 'Controllers' . DIRECTORY_SEPARATOR . 'Admin' . DIRECTORY_SEPARATOR . $this->fileName),
            $template);
    }
542782
public function postTemplate(Page $page, Template $template)
    {
        $this->authorize('editTemplate', $page);

        $page->setTemplate($template);

        Event::fire(new Events\PageTemplateWasChanged($page, $template));

        return $page->getCurrentVersion()->getStatus();
    }
39573
public function getIncidentTemplate()
    {
        $templateSlug = Binput::get('slug');

        if ($template = IncidentTemplate::where('slug', '=', $templateSlug)->first()) {
            return $template;
        }

        throw new ModelNotFoundException("Incident template for $templateSlug could not be found.");
    }
810240
public function addTemplate(AlTemplate $template)
    {
        $key = $this->normalizeKey($template->getTemplateName());
        $this->templates[$key] = $template;
    }
72410
private function addResolvedRoute(array $context, $template)
    {
        if (!isset($context['record'])) {
            return;
        }

        $content = $context['record'];
        $request = $this->app['request_stack']->getCurrentRequest();

        $homepage = $this->getOption('theme/homepage') ?: $this->getOption('general/homepage');
        $uriID = $content->contenttype['singular_slug'] . '/' . $content->get('id');
        $uriSlug = $content->contenttype['singular_slug'] . '/' . $content->get('slug');

        if (($uriID === $homepage || $uriSlug === $homepage) && ($template === $this->getOption('general/homepage_template'))) {
            $request->attributes->add(['_route' => 'homepage', '_route_params' => []]);

            return;
        }

        // In case we're previewing a record, this will override the `_route`, but keep the original
        // one, used to see if we need to disable the XSS protection header.
        // See PR https://github.com/bolt/bolt/pull/7458
        list($routeName, $routeParams) = $content->getRouteNameAndParams();
        if ($routeName) {
            /** @deprecated since 3.4 to be removed in 4.0 */
            $request->attributes->add([
                '_route'          => $routeName,
                '_route_params'   => $routeParams,
                '_internal_route' => $request->attributes->get('_route'),
            ]);
        }
    }
899961
protected function renderTemplate($template)
    {
        // Build allowed extensions
        $allowedExtensions = new ArrayList();
        foreach (File::getAllowedExtensions() as $extension) {
            if ($extension) {
                $allowedExtensions->push(new ArrayData([
                    'Extension' => preg_quote($extension)
                ]));
            }
        }

        Config::nest();
        Config::modify()->set(SSViewer::class, 'source_file_comments', false);

        $viewer = SSViewer::create([$template]);
        $result = (string)$viewer->process(new ArrayData([
            'AllowedExtensions' => $allowedExtensions
        ]));

        Config::unnest();

        return $result;
    }
426619
public function update(TemplateRequest $request, $template)
    {
        try {
            $template = $request->template;
            $path = theme_path('views').$template;
            $content = $request->content;

            // Notify if file was not changed.
            if (\File::exists($path) and \File::get($path) == $content) {
                return response()->json([
                    'status' => false,
                    'message' => sprintf(__('msg.not_updated'), $template),
                ], 200);
            }

            \File::put($path, $content, true);

            return response()->json([
                'status' => true,
                'message' => sprintf(__('msg.updated'), $template),
                'file' => [
                    'size' => formatBytes(\File::size($path)),
                    'modified' => strftime('%Y-%m-%d %H:%M', \File::lastModified($path))
                ]
            ], 200);

        } catch (ValidationException $e) {
            $message = $e->validator->errors()->first();
            return response()->json(['status' => false, 'message' => $message], 200);
        } catch (\Exception $e) {
            $message = $e->getMessage();
            return response()->json(['status' => false, 'message' => $message], 404 );
        }
    }
1111041
public static function create(Template $template): self
    {
        $renderTemplateDirective = new self();

        $renderTemplateDirective->type     = self::TYPE;
        $renderTemplateDirective->template = $template;

        return $renderTemplateDirective;
    }
1175952
public function setTemplate(Template $template = null)
	{
		if ($this->writeOnce($this->template, $template)) {
			$this->template->addTemplateLayout($this);
		}
	}
561381
public function resolveErrorTemplate()
    {
        $this->buildTemplateIndex();

        $template = (array_key_exists(self::ERROR_TEMPLATE, $this->templateIndex)) ?
            $this->templateIndex[self::ERROR_TEMPLATE] :
            false;

        return($template);
    }