<?php

namespace Opentalent\OtTemplating\ViewHelpers\RootPage;

use Closure;
use FluidTYPO3\Vhs\Service\PageService;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Object\ObjectManager;
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;

/**
 * Viewhelper to retrieve the Uri of the root page of the current site
 * Call it in fluid templates with:
 *
 *     {namespace ot=Opentalent\OtTemplating\ViewHelpers}
 *
 *     {ot:rootPage.getUri()}
 *
 * @package Opentalent\OtTemplating\ViewHelpers
 */
class GetUriViewHelper extends AbstractViewHelper
{
    /**
     * -- This method is expected by Fluid --
     * Renders the content as html
     *
     * @param array $arguments
     * @param Closure $renderChildrenClosure
     * @param RenderingContextInterface $renderingContext
     * @return string
     */
    public static function renderStatic(
        array $arguments,
        Closure $renderChildrenClosure,
        RenderingContextInterface $renderingContext
    ) {
        $pageUid = GetIdViewHelper::renderStatic($arguments, $renderChildrenClosure, $renderingContext);

        $uriBuilder = $renderingContext->getControllerContext()->getUriBuilder();
        $uri = $uriBuilder->setTargetPageUid($pageUid)->build();
        return $uri;
    }
}
