2021-08-17 19:45:38 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This file is part of the package thucke/th-rating.
|
|
|
|
*
|
|
|
|
* For the full copyright and license information, please read the
|
|
|
|
* LICENSE file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace WapplerSystems\BookmarksLikesRatings\ViewHelpers;
|
|
|
|
|
|
|
|
use TYPO3\CMS\Core\Log\LogLevel;
|
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
|
|
|
use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
|
2021-08-20 13:33:13 +02:00
|
|
|
use TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder;
|
2021-08-17 19:45:38 +02:00
|
|
|
use TYPO3\CMS\Extbase\Object\ObjectManager;
|
|
|
|
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
|
|
|
|
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
|
|
|
|
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
|
|
|
|
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
|
2021-08-20 13:33:13 +02:00
|
|
|
use TYPO3Fluid\Fluid\Core\ViewHelper\TagBuilder;
|
2021-08-17 19:45:38 +02:00
|
|
|
use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
class LikeViewHelper extends AbstractViewHelper
|
|
|
|
{
|
|
|
|
|
|
|
|
protected $escapeOutput = false;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var \WapplerSystems\BookmarksLikesRatings\Service\ExtensionHelperService
|
|
|
|
*/
|
|
|
|
protected $extensionHelperService;
|
|
|
|
|
|
|
|
public function initializeArguments(): void
|
|
|
|
{
|
2021-08-20 13:33:13 +02:00
|
|
|
$this->registerArgument('table', 'string', 'The rating tablename');
|
|
|
|
$this->registerArgument('uid', 'integer', 'The uid of the object', true);
|
|
|
|
$this->registerArgument('class', 'string', 'The class', true);
|
|
|
|
$this->registerArgument('id', 'string', 'The id');
|
|
|
|
|
2021-08-17 19:45:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Renders the ratingView
|
|
|
|
*
|
|
|
|
* @param array $arguments
|
|
|
|
* @param \Closure $renderChildrenClosure
|
|
|
|
* @param RenderingContextInterface $renderingContext
|
|
|
|
* @return mixed
|
|
|
|
* @throws \TYPO3Fluid\Fluid\Core\ViewHelper\Exception
|
|
|
|
* @noinspection PhpFullyQualifiedNameUsageInspection
|
|
|
|
*/
|
|
|
|
public static function renderStatic(
|
|
|
|
array $arguments,
|
|
|
|
\Closure $renderChildrenClosure,
|
|
|
|
RenderingContextInterface $renderingContext
|
|
|
|
) {
|
|
|
|
|
2021-08-20 13:33:13 +02:00
|
|
|
$tagBuilder = new TagBuilder('button');
|
|
|
|
if ($arguments['id']) {
|
|
|
|
$tagBuilder->addAttribute('id',$arguments['id']);
|
2021-08-17 19:45:38 +02:00
|
|
|
}
|
2021-08-20 13:33:13 +02:00
|
|
|
$tagBuilder->addAttribute('class',$arguments['class']);
|
|
|
|
$tagBuilder->addAttribute('data-table',$arguments['table']);
|
|
|
|
$tagBuilder->addAttribute('data-uid',$arguments['uid']);
|
|
|
|
$tagBuilder->addAttribute('data-blr-type','like');
|
2021-08-17 19:45:38 +02:00
|
|
|
|
2021-08-20 13:33:13 +02:00
|
|
|
/** @var UriBuilder $uriBuilder */
|
|
|
|
$uriBuilder = $renderingContext->getControllerContext()->getUriBuilder();
|
|
|
|
$uriBuilder->reset();
|
|
|
|
$uriBuilder->setTargetPageType(874645);
|
|
|
|
$tagBuilder->addAttribute('data-status-url',$uriBuilder->buildFrontendUri());
|
2021-08-17 19:45:38 +02:00
|
|
|
|
2021-08-20 13:33:13 +02:00
|
|
|
$uriBuilder->reset();
|
|
|
|
$uriBuilder->setTargetPageType(874644);
|
|
|
|
$tagBuilder->addAttribute('data-toggle-url',$uriBuilder->buildFrontendUri());
|
2021-08-17 19:45:38 +02:00
|
|
|
|
2021-08-20 13:33:13 +02:00
|
|
|
$tagBuilder->setContent((string)$renderChildrenClosure());
|
2021-08-17 19:45:38 +02:00
|
|
|
|
2021-08-20 13:33:13 +02:00
|
|
|
return $tagBuilder->render();
|
2021-08-17 19:45:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|