Skip to content

Commit

Permalink
[BUGFIX] Fix If ViewHelper for edit / delete buttons
Browse files Browse the repository at this point in the history
Fixes: #19
(cherry picked from commit c6ae998)
  • Loading branch information
nhovratov committed Sep 27, 2023
1 parent f37abb4 commit c4b330d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 35 deletions.
7 changes: 5 additions & 2 deletions Classes/Service/AccessControlService.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,11 @@ public function getFrontendUserUid()
*/
public function getFrontendUserObject()
{
if ($this->hasLoggedInFrontendUser() && !empty($GLOBALS['TSFE']->fe_user->user['uid'])) {
return $this->userRepository->findByUid($GLOBALS['TSFE']->fe_user->user['uid']);
if ($this->hasLoggedInFrontendUser()) {
$frontendUserId = GeneralUtility::makeInstance(Context::class)->getPropertyFromAspect('frontend.user', 'id');
/** @var User $user */
$user = $this->userRepository->findByUid($frontendUserId);
return $user;
}
return null;
}
Expand Down
35 changes: 2 additions & 33 deletions Classes/ViewHelpers/Security/EditLinkViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,14 @@

use Dan\Jobfair\Domain\Model\Job;
use Dan\Jobfair\Service\AccessControlService;
use TYPO3Fluid\Fluid\Core\Compiler\TemplateCompiler;
use TYPO3Fluid\Fluid\Core\Parser\SyntaxTree\ViewHelperNode;
use TYPO3Fluid\Fluid\ViewHelpers\IfViewHelper;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractConditionViewHelper;

/**
* View helper to create additional parameters for link to user profile
*
* @author Dan <[email protected]>
*/
class EditLinkViewHelper extends IfViewHelper
class EditLinkViewHelper extends AbstractConditionViewHelper
{

/**
Expand Down Expand Up @@ -55,39 +53,10 @@ public function initializeArguments()
*/
public function render()
{
//\TYPO3\CMS\Extbase\Utility\DebuggerUtility::var_dump($this->arguments['job']);
$job = $this->arguments['job'];
if ($this->accessControlService->isOwner($job)) {
return $this->renderThenChild();
}
return $this->renderElseChild();
}

/**
* The compiled ViewHelper adds two new ViewHelper arguments: __thenClosure and __elseClosure.
* These contain closures which are be executed to render the then(), respectively else() case.
*
* @param string $argumentsName
* @param string $closureName
* @param string $initializationPhpCode
* @param ViewHelperNode $node
* @param TemplateCompiler $compiler
* @return string
*/
public function compile(
$argumentsName,
$closureName,
&$initializationPhpCode,
ViewHelperNode $node,
TemplateCompiler $compiler
) {
parent::compile(
$argumentsName,
$closureName,
$initializationPhpCode,
$node,
$compiler
);
return TemplateCompiler::SHOULD_GENERATE_VIEWHELPER_INVOCATION;
}
}

0 comments on commit c4b330d

Please sign in to comment.