Craft\FormBuilder2_LayoutController::actionSetTemplate PHP Method

actionSetTemplate() public method

public actionSetTemplate ( )
    public function actionSetTemplate()
    {
        $this->requirePostRequest();
        $this->requireAjaxRequest();
        $templatePath = craft()->request->getRequiredPost('templatePath');
        $folderContents = IOHelper::getFolderContents(craft()->path->getPluginsPath() . 'formbuilder2/templates/layouts/templates/');
        $theFile = '';
        if ($folderContents && $templatePath) {
            foreach ($folderContents as $key => $file) {
                $fileName = IOHelper::getFileName($file, false);
                if ($fileName == $templatePath) {
                    $theFile = IOHelper::getFile($file);
                }
            }
        }
        if ($theFile == '') {
            $this->returnErrorJson('No template with that name.');
        } else {
            $template = ['fileName' => $theFile->getFileName(false), 'fileOriginalName' => $theFile->getFileName(), 'fileNameCleaned' => IOHelper::cleanFilename(IOHelper::getFileName($theFile->getRealPath(), false)), 'fileExtension' => $theFile->getExtension(), 'filePath' => $theFile->getRealPath(), 'fileContents' => $theFile->getContents()];
            $this->returnJson(['success' => true, 'message' => Craft::t('Template is set.'), 'layout' => $template]);
        }
    }