Creates instances of FluxPackage based on provided extension name. Stores created instances in memory.
Example #1
0
 /**
  * @param array $arguments
  * @param \Closure $renderChildrenClosure
  * @param RenderingContextInterface $renderingContext
  * @return void
  */
 public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
 {
     $viewHelperVariableContainer = $renderingContext->getViewHelperVariableContainer();
     $templateVariableContainer = $renderingContext->getTemplateVariableContainer();
     $extensionName = static::getExtensionNameFromRenderingContextOrArguments($renderingContext, $arguments);
     $formClassName = FluxPackageFactory::getPackageWithFallback($extensionName)->getImplementation(FluxPackage::IMPLEMENTATION_FORM);
     $form = call_user_func_array(array($formClassName, 'create'), array());
     $container = $form->last();
     // configure Form instance
     $form->setId($arguments['id']);
     $form->setName($arguments['id']);
     $form->setLabel($arguments['label']);
     $form->setDescription($arguments['description']);
     $form->setEnabled($arguments['enabled']);
     $form->setCompact($arguments['compact']);
     $form->setExtensionName($extensionName);
     $form->setLocalLanguageFileRelativePath($arguments['localLanguageFileRelativePath']);
     $form->setVariables((array) $arguments['variables']);
     $form->setOptions((array) $arguments['options']);
     if (FALSE === $form->hasOption(Form::OPTION_ICON)) {
         $form->setOption(Form::OPTION_ICON, $arguments['icon']);
     }
     if (FALSE === $form->hasOption(Form::OPTION_GROUP)) {
         $form->setOption(Form::OPTION_GROUP, $arguments['wizardTab']);
     }
     // rendering child nodes with Form's last sheet as active container
     $viewHelperVariableContainer->addOrUpdate(static::SCOPE, static::SCOPE_VARIABLE_FORM, $form);
     $viewHelperVariableContainer->addOrUpdate(static::SCOPE, static::SCOPE_VARIABLE_EXTENSIONNAME, $extensionName);
     $templateVariableContainer->add(static::SCOPE_VARIABLE_FORM, $form);
     static::setContainerInRenderingContext($renderingContext, $container);
     $renderChildrenClosure();
     $viewHelperVariableContainer->remove(static::SCOPE, static::SCOPE_VARIABLE_EXTENSIONNAME);
     $viewHelperVariableContainer->remove(static::SCOPE, static::SCOPE_VARIABLE_CONTAINER);
     $templateVariableContainer->remove(static::SCOPE_VARIABLE_CONTAINER);
 }
Example #2
0
 /**
  * @param array $settings
  * @return FormInterface
  */
 public static function create(array $settings = array())
 {
     /** @var ObjectManagerInterface $objectManager */
     $objectManager = GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager');
     if (isset($settings['extensionName'])) {
         $className = FluxPackageFactory::getPackageWithFallback($settings['extensionName'])->getImplementation(FluxPackage::IMPLEMENTATION_FORM);
     } else {
         $className = get_called_class();
     }
     /** @var FormInterface $object */
     $object = $objectManager->get($className);
     return $object->modify($settings);
 }
Example #3
0
 /**
  * @param ViewContext $viewContext
  * @param string $formName
  * @return 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];
 }