FluidTYPO3\Flux\Service\FluxService::getFormFromTemplateFile PHP Method

getFormFromTemplateFile() public method

public getFormFromTemplateFile ( FluidTYPO3\Flux\View\ViewContext $viewContext, string $formName = 'form' ) : Form | null
$viewContext FluidTYPO3\Flux\View\ViewContext
$formName string
return FluidTYPO3\Flux\Form | null
    public function getFormFromTemplateFile(ViewContext $viewContext, $formName = 'form')
    {
        $templatePathAndFilename = $viewContext->getTemplatePathAndFilename();
        if (FALSE === file_exists($templatePathAndFilename)) {
            return NULL;
        }
        $section = $viewContext->getSectionName();
        $variables = $viewContext->getVariables();
        $extensionName = $viewContext->getExtensionName();
        $variableCheck = json_encode($variables);
        $cacheKey = md5($templatePathAndFilename . $formName . $extensionName . $section . $variableCheck);
        if (FALSE === isset(self::$cache[$cacheKey])) {
            try {
                $exposedView = $this->getPreparedExposedTemplateView($viewContext);
                self::$cache[$cacheKey] = $exposedView->getForm($section, $formName);
            } catch (\RuntimeException $error) {
                $this->debug($error);
                /** @var Form $form */
                self::$cache[$cacheKey] = $this->objectManager->get(FluxPackageFactory::getPackageWithFallback($extensionName)->getImplementation(FluxPackage::IMPLEMENTATION_FORM));
                self::$cache[$cacheKey]->createField('UserFunction', 'error')->setFunction('FluidTYPO3\\Flux\\UserFunction\\ErrorReporter->renderField')->setArguments(array($error));
            }
        }
        return self::$cache[$cacheKey];
    }

Usage Example

 /**
  * @param array $row
  * @return Form|NULL
  */
 public function getForm(array $row)
 {
     if (NULL !== $this->form) {
         return $this->form;
     }
     $templatePathAndFilename = $this->getTemplatePathAndFilename($row);
     if (FALSE === file_exists($templatePathAndFilename)) {
         return NULL;
     }
     $section = $this->getConfigurationSectionName($row);
     $formName = 'form';
     $paths = $this->getTemplatePaths($row);
     $extensionKey = $this->getExtensionKey($row);
     $extensionName = ExtensionNamingUtility::getExtensionName($extensionKey);
     $fieldName = $this->getFieldName($row);
     // Special case: when saving a new record variable $row[$fieldName] is already an array
     // and must not be processed by the configuration service.
     if (FALSE === is_array($row[$fieldName])) {
         $variables = $this->configurationService->convertFlexFormContentToArray($row[$fieldName]);
     } else {
         $variables = array();
     }
     $variables['record'] = $row;
     $variables = GeneralUtility::array_merge_recursive_overrule($this->templateVariables, $variables);
     $form = $this->configurationService->getFormFromTemplateFile($templatePathAndFilename, $section, $formName, $paths, $extensionName, $variables);
     $form = $this->setDefaultValuesInFieldsWithInheritedValues($form, $row);
     return $form;
 }
All Usage Examples Of FluidTYPO3\Flux\Service\FluxService::getFormFromTemplateFile