Created
June 3, 2015 14:13
-
-
Save sorenmalling/b38bd88b15baf266532d to your computer and use it in GitHub Desktop.
A link viewhelper that can add a "active" class to a link
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| namespace Vendor\Namespace\ViewHelpers\Navigation; | |
| use TYPO3\Fluid\ViewHelpers\Link\ActionViewHelper; | |
| use TYPO3\Flow\Mvc\ActionRequest; | |
| class ItemViewHelper extends ActionViewHelper { | |
| public function render($action, $arguments = array(), $controller = NULL, $package = NULL, $subpackage = NULL, $section = '', $format = '', array $additionalParams = array(), $addQueryString = FALSE, array $argumentsToBeExcludedFromQueryString = array(), $useParentRequest = FALSE, $absolute = TRUE) { | |
| if ($action === NULL || $controller === NULL || $package === NULL) { | |
| throw new \Exception('I need action, controller and package arguments'); | |
| } | |
| /** @var ActionRequest $request */ | |
| $request = $this->controllerContext->getRequest(); | |
| if (/*$action === $request->getControllerActionName() &&*/ $controller === $request->getControllerName() && $package === $request->getControllerPackageKey()) { | |
| if ($this->tag->hasAttribute('class') === TRUE) { | |
| $classAttribute = 'active ' . $this->tag->getAttribute('class'); | |
| $this->tag->removeAttribute('class'); | |
| } else { | |
| $classAttribute = 'active'; | |
| } | |
| $this->tag->addAttribute('class', $classAttribute); | |
| } | |
| return parent::render($action, $arguments, $controller, $package, $subpackage, $section, $format, $additionalParams, $addQueryString, $argumentsToBeExcludedFromQueryString, $useParentRequest, $absolute); // TODO: Change the autogenerated stub | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment