Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Store grid rendering state in ViewHelperVariableContainer #15

Closed
jdoubleu opened this issue Sep 2, 2018 · 3 comments
Closed

Store grid rendering state in ViewHelperVariableContainer #15

jdoubleu opened this issue Sep 2, 2018 · 3 comments
Labels
enhancement New feature or request

Comments

@jdoubleu
Copy link

jdoubleu commented Sep 2, 2018

At the moment the state of the grid rendering (containing full_width, row_begin, row_end, etc.) is stored in the $_GLOBALS array.

Due to the fact, that both row and column rendering is implemented inside a ViewHelper the \TYPO3Fluid\Fluid\Core\ViewHelper\ViewHelperVariableContainer should be used to communicate between them and hold the state. It can be accessed through \TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface::getViewHelperVariableContainer.

@jdoubleu jdoubleu added the enhancement New feature or request label Sep 2, 2018
@jdoubleu jdoubleu changed the title Store grid rendering state int ViewHelperVariableContainer Store grid rendering state in ViewHelperVariableContainer Sep 2, 2018
@jdoubleu
Copy link
Author

jdoubleu commented Sep 3, 2018

At the moment this is not possible because the RowWrapViewHelper is used in a different (the page rendering) RenderingContext than the ColumnWrapViewHelper (Content Rendering).

The stored ViewHelper variables inside the page rendering context have to be passed to the content rendering context somehow.

WIP Patch:
Removed patch because a newer is available below.

@jdoubleu jdoubleu closed this as completed Sep 3, 2018
@jdoubleu jdoubleu reopened this Sep 3, 2018
@jdoubleu
Copy link
Author

jdoubleu commented Sep 3, 2018

With 4ebbce6 both Row and Column templates share the same rendering context (through the StandaloneView in the GridSystemTemplateService).

It should be possible now. That's not true. This change does not help to resolve this issue. The RowWrap and ColumnWrap ViewHelpers still don't share the same context.

Diff:

diff --git a/Classes/ViewHelpers/ColumnWrapViewHelper.php b/Classes/ViewHelpers/ColumnWrapViewHelper.php
index 41076f3..b47c3ba 100644
--- a/Classes/ViewHelpers/ColumnWrapViewHelper.php
+++ b/Classes/ViewHelpers/ColumnWrapViewHelper.php
@@ -47,29 +47,29 @@ class ColumnWrapViewHelper extends AbstractGridViewHelper
         $settings = [
             'row_begin' => false,
             'row_end' => false,
-            'fullwidth' => $GLOBALS['TX_COLUMN_LAYOUT']['isFullwidthElement']
+            'fullwidth' => $renderingContext->getViewHelperVariableContainer()->get(AbstractGridViewHelper::class, 'isFullwidthElement')
         ];
 
         // Check if the last element was a fullwidth element. We have to close the column for the new element in that case.
-        if ($GLOBALS['TX_COLUMN_LAYOUT']['isFullwidthElement'] === true) {
+        if ($renderingContext->getViewHelperVariableContainer()->get(AbstractGridViewHelper::class, 'isFullwidthElement') === true) {
             $settings['row_begin'] = true;
             $settings['row_end'] = true;
-            $GLOBALS['TX_COLUMN_LAYOUT']['isFullwidthElement']  = false;
+            $renderingContext->getViewHelperVariableContainer()->addOrUpdate(AbstractGridViewHelper::class, 'isFullwidthElement', false);
         }
 
         // Determine, if there should be a new row for this column.
-        if ($GLOBALS['TX_COLUMN_LAYOUT']['contentElementIndex'] === 0) {
+        if ($renderingContext->getViewHelperVariableContainer()->get(AbstractGridViewHelper::class, 'contentElementIndex') === 0) {
             // If is the first element. Force opening a new row - regardless of the configuration.
             $settings['row_begin'] = true;
 
             if ((int)$currentLayoutConfig['row_fullwidth'] === 1) {
-                $GLOBALS['TX_COLUMN_LAYOUT']['isFullwidthElement'] = true;
+                $renderingContext->getViewHelperVariableContainer()->addOrUpdate(AbstractGridViewHelper::class, 'isFullwidthElement', true);
             }
         } elseif ((int)$currentLayoutConfig['row_fullwidth'] === 1) {
             // When the element is full with, there has to a be new row.
             $settings['row_begin'] = true;
             $settings['row_end'] = true;
-            $GLOBALS['TX_COLUMN_LAYOUT']['isFullwidthElement'] = true;
+            $renderingContext->getViewHelperVariableContainer()->addOrUpdate(AbstractGridViewHelper::class, 'isFullwidthElement', true);
         } elseif ((int)$currentLayoutConfig['row_behaviour'] === 1) {
             // Force closing the current row and opening a new one, if configured in element.
             $settings['row_begin'] = true;
@@ -97,7 +97,8 @@ class ColumnWrapViewHelper extends AbstractGridViewHelper
         $output = $templateService->renderColumnHtml($variables);
 
         // Raise index of content elements.
-        $GLOBALS['TX_COLUMN_LAYOUT']['contentElementIndex']++;
+        $contentElementIndex = $renderingContext->getViewHelperVariableContainer()->get(AbstractGridViewHelper::class, 'contentElementIndex', 0);
+        $renderingContext->getViewHelperVariableContainer()->addOrUpdate(AbstractGridViewHelper::class, 'contentElementIndex', ++$contentElementIndex);
 
         return $output;
     }
@@ -124,6 +125,6 @@ class ColumnWrapViewHelper extends AbstractGridViewHelper
      */
     protected static function isGridRenderingEnabled(array $arguments, RenderingContextInterface $context): bool
     {
-        return isset($GLOBALS['TX_COLUMN_LAYOUT']['enabled']) && $GLOBALS['TX_COLUMN_LAYOUT']['enabled'];
+        return $context->getViewHelperVariableContainer()->get(AbstractGridViewHelper::class, 'enabled', false);
     }
 }
diff --git a/Classes/ViewHelpers/RowWrapViewHelper.php b/Classes/ViewHelpers/RowWrapViewHelper.php
index dcae3b1..ae964bd 100644
--- a/Classes/ViewHelpers/RowWrapViewHelper.php
+++ b/Classes/ViewHelpers/RowWrapViewHelper.php
@@ -37,11 +37,11 @@ class RowWrapViewHelper extends AbstractGridViewHelper
     protected static function wrapContent(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext): string
     {
         // Setup row context
-        $GLOBALS['TX_COLUMN_LAYOUT'] = [
+        $renderingContext->getViewHelperVariableContainer()->addAll(AbstractGridViewHelper::class, [
             'enabled' => true,
             'contentElementIndex' => 0,
             'isFullwidthElement' => false
-        ];
+        ]);
 
         // Get grid system template service
         $templateService = static::getTemplateService();
@@ -51,13 +51,13 @@ class RowWrapViewHelper extends AbstractGridViewHelper
         $content = new RenderableClosure();
         $content
             ->setName('row-content')
-            ->setClosure(function () use ($renderChildrenClosure, &$endRow) {
+            ->setClosure(function () use ($renderChildrenClosure, &$endRow, $renderingContext) {
                 $output = $renderChildrenClosure();
                 /*
                  * After content is rendered check for whether to close the row.
                  * Changes the value of a variable passed by reference to the rendering variable container.
                  */
-                $endRow = $GLOBALS['TX_COLUMN_LAYOUT']['contentElementIndex'] > 0;
+                $endRow = $renderingContext->getViewHelperVariableContainer()->get(AbstractGridViewHelper::class, 'contentElementIndex') > 0;
 
                 return $output;
             });
@@ -65,7 +65,7 @@ class RowWrapViewHelper extends AbstractGridViewHelper
         // Setup rendering settings
         $settings = [
             'content' => $content,
-            'fullscreen' => $GLOBALS['TX_COLUMN_LAYOUT']['isFullscreenElement'],
+            'fullscreen' => $renderingContext->getViewHelperVariableContainer()->get(AbstractGridViewHelper::class, 'isFullscreenElement'),
             'row_end' => &$endRow
         ];
 
@@ -74,7 +74,7 @@ class RowWrapViewHelper extends AbstractGridViewHelper
             'settings' => $settings
         ]);
 
-        unset($GLOBALS['TX_COLUMN_LAYOUT']);
+        self::cleanStateVariables($renderingContext);
 
         return $output;
     }
@@ -92,4 +92,17 @@ class RowWrapViewHelper extends AbstractGridViewHelper
 
         return !in_array($arguments['colPos'], $emConfig->getColPosListForDisable());
     }
+
+    /**
+     * Removes all stored variables of the grid rendering state from the ViewHelperVariableContainer
+     *
+     * @param RenderingContextInterface $renderingContext
+     */
+    protected static function cleanStateVariables(RenderingContextInterface $renderingContext)
+    {
+        $storedValues = $renderingContext->getViewHelperVariableContainer()->getAll(AbstractGridViewHelper::class);
+        foreach ($storedValues as $name => $_) {
+            $renderingContext->getViewHelperVariableContainer()->remove(AbstractGridViewHelper::class, $name);
+        }
+    }
 }

@jdoubleu
Copy link
Author

jdoubleu commented Sep 4, 2018

Because the grid rendering was moved into a custom renderer class this is no longer necessary.

The renderer class holds a state of the grid.

@jdoubleu jdoubleu closed this as completed Sep 4, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant