/**
  * Returns the path of a $renderable in the format <formIdentifier>/<sectionIdentifier>/<sectionIdentifier>/.../<elementIdentifier>
  *
  * @param RootRenderableInterface $renderable
  * @return string
  */
 protected function getRenderablePath(RootRenderableInterface $renderable)
 {
     $path = $renderable->getIdentifier();
     while ($renderable = $renderable->getParentRenderable()) {
         $path = $renderable->getIdentifier() . '/' . $path;
     }
     return $path;
 }
Exemple #2
0
 /**
  * @param RootRenderableInterface $renderable
  * @param string $as
  * @return string the rendered form values
  */
 public function render(RootRenderableInterface $renderable, $as = 'formValue')
 {
     if ($renderable instanceof CompositeRenderableInterface) {
         $elements = $renderable->getRenderablesRecursively();
     } else {
         $elements = [$renderable];
     }
     /** @var RendererInterface $fluidFormRenderer */
     $fluidFormRenderer = $this->viewHelperVariableContainer->getView();
     $formRuntime = $fluidFormRenderer->getFormRuntime();
     $formState = $formRuntime->getFormState();
     $output = '';
     foreach ($elements as $element) {
         if (!$element instanceof FormElementInterface) {
             continue;
         }
         $value = $formState->getFormValue($element->getIdentifier());
         $formValue = ['element' => $element, 'value' => $value, 'processedValue' => $this->processElementValue($element, $value), 'isMultiValue' => is_array($value) || $value instanceof \Iterator];
         $this->templateVariableContainer->add($as, $formValue);
         $output .= $this->renderChildren();
         $this->templateVariableContainer->remove($as);
     }
     return $output;
 }
Exemple #3
0
 /**
  * Render the passed $renderable and return the rendered Renderable.
  *
  * @param \Neos\Form\Core\Model\Renderable\RootRenderableInterface $renderable
  * @return string the rendered $renderable
  * @throws \Neos\Form\Exception\RenderingException
  * @api
  */
 public function renderRenderable(\Neos\Form\Core\Model\Renderable\RootRenderableInterface $renderable)
 {
     $renderable->beforeRendering($this->formRuntime);
     $renderableType = $renderable->getType();
     if ($renderable->getRendererClassName() !== null && $renderable->getRendererClassName() !== get_class($this)) {
         $rendererClassName = $renderable->getRendererClassName();
         $renderer = new $rendererClassName();
         if (!$renderer instanceof RendererInterface) {
             throw new \Neos\Form\Exception\RenderingException(sprintf('The renderer class "%s" for "%s" does not implement RendererInterface.', $rendererClassName, $renderableType), 1326098022);
         }
         $renderer->setControllerContext($this->controllerContext);
         $renderer->setFormRuntime($this->formRuntime);
         return $renderer->renderRenderable($renderable);
     }
     $renderingOptions = $renderable->getRenderingOptions();
     $renderablePathAndFilename = $this->getPathAndFilenameForRenderable($renderableType, $renderingOptions);
     $parsedRenderable = $this->getParsedRenderable($renderable->getType(), $renderablePathAndFilename);
     $currentTemplatePathsResolver = $this->getTemplatePaths();
     $newTemplatePathsResolver = $this->createTemplatePathsResolverWithRenderingOptions($renderingOptions);
     $this->baseRenderingContext->setTemplatePaths($newTemplatePathsResolver);
     isset($renderingOptions['templatePathPattern']);
     if ($this->getCurrentRenderingContext() === null) {
         // We do not have a "current" rendering context yet, so we use the base rendering context
         $this->baseRenderingContext->setControllerContext($this->controllerContext);
         $renderingContext = $this->baseRenderingContext;
     } else {
         $renderingContext = clone $this->getCurrentRenderingContext();
     }
     $renderingContext->getViewHelperVariableContainer()->addOrUpdate(FluidFormRenderer::class, 'currentRenderable', $renderable);
     if (!isset($renderingOptions['renderableNameInTemplate'])) {
         throw new \Neos\Form\Exception\RenderingException(sprintf('The Renderable "%s" did not have the rendering option "renderableNameInTemplate" defined.', $renderableType), 1326094948);
     }
     $templateVariableContainer = new TemplateVariableContainer(array($renderingOptions['renderableNameInTemplate'] => $renderable));
     $renderingContext->setVariableProvider($templateVariableContainer);
     if ($parsedRenderable->hasLayout()) {
         $renderableLayoutName = $parsedRenderable->getLayoutName($renderingContext);
         $renderableLayoutPathAndFilename = $this->getPathAndFilenameForRenderableLayout($renderableLayoutName, $renderingOptions);
         $parsedLayout = $this->getParsedRenderable($renderableLayoutName, $renderableLayoutPathAndFilename);
         $this->startRendering(self::RENDERING_LAYOUT, $parsedRenderable, $renderingContext);
         $output = $parsedLayout->render($renderingContext);
         $this->stopRendering();
     } else {
         $this->startRendering(self::RENDERING_TEMPLATE, $parsedRenderable, $renderingContext);
         $output = $parsedRenderable->render($renderingContext);
         $this->stopRendering();
     }
     $this->baseRenderingContext->setTemplatePaths($currentTemplatePathsResolver);
     return $output;
 }