typo3 currently selected page id backend

raw

README.rst

inside a view helper

keywords: typo3 backend get page id php

raw

code.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<?php
use FluidTYPO3\Vhs\Traits\DefaultRenderMethodViewHelperTrait;
use FluidTYPO3\Vhs\Traits\TemplateVariableViewHelperTrait;
use TYPO3\CMS\Fluid\Core\Rendering\RenderingContextInterface;
use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper;
use TYPO3\CMS\Backend\Utility\BackendUtility;
 
class FooViewHelper extends AbstractViewHelper
{
    use DefaultRenderMethodViewHelperTrait;
    use TemplateVariableViewHelperTrait;
 
    public static function renderStatic(
        array $arguments,
        \Closure $renderChildrenClosure,
        RenderingContextInterface $renderingContext
    ) {
        $tvc = $renderingContext->getTemplateVariableContainer();
        if ($tvc->exists('record')) {
            //TYPO3 backend list view
            $pageRecord = $tvc->get('record');
            $pageUid = $pageRecord['uid'];
        } else {
            //TYPO3 backend page record edit
            //FIXME: is there a better way to detect the currently selected page
            // in the typo3 backend?
            $pageUid = current(array_keys($_GET['edit']['pages']));
        }
 
        //...
    }
}
?>
 
Christian Weiske Christian Weiske
owner

History