/** * Render a menu item (li) with correct icon color and active state. * * @param string $controller * @param string $action * @param string $icon * @param string $activeLevel * @return string */ public function render($controller, $action = NULL, $packageKey = NULL, $icon = NULL, $activeLevel = 'controller') { $link = new \TYPO3\Fluid\Core\ViewHelper\TagBuilder('a'); $uriBuilder = $this->controllerContext->getUriBuilder(); $uri = $uriBuilder->reset()->uriFor($action, array(), $controller, $packageKey); $active = TRUE; if ($this->controllerContext->getRequest()->getControllerName() !== $controller) { $active = FALSE; } if ($activeLevel === 'action' && $this->controllerContext->getRequest()->getControllerActionName() !== $action) { $active = FALSE; } $prependLabelContent = ''; if ($icon !== NULL) { $iconClass = $icon; if ($active) { $iconClass .= ' icon-white'; } $prependLabelContent = '<i class="' . $iconClass . '"></i> '; } if ($active) { $this->tag->addAttribute('class', 'active'); } $link->addAttribute('href', $uri); $link->setContent($prependLabelContent . $this->renderChildren()); $this->tag->setContent($link->render()); return $this->tag->render(); }
/** * @test */ public function tagIsNotRenderedIfTagNameIsEmpty() { $tagBuilder = new \TYPO3\Fluid\Core\ViewHelper\TagBuilder('foo'); $tagBuilder->setTagName(''); $this->assertEquals('', $tagBuilder->render()); }
/** * * @param \Sandstorm\PhpProfiler\Domain\Model\ProfilingRun $profile * @param array $calculationOptions */ protected function calculateRegex(ProfilingRun $profile, array $calculationOptions) { if (!isset($calculationOptions['regex'])) { throw new Exception('Regex not set'); } $metrics = array('time' => 'wt', 'calls' => 'ct', 'memory' => 'mu'); $metric = isset($calculationOptions['metric']) ? $metrics[$calculationOptions['metric']] : 'ct'; $results = array(); $detailedResult = array(); foreach ($profile->getXhprofTrace() as $id => $data) { $matches = NULL; if (preg_match($calculationOptions['regex'], $id, $matches)) { $results[] = $data[$metric]; if (isset($matches[1])) { $className = $matches[1]; if (!isset($detailedResult[$className])) { $detailedResult[$className] = array(); } $detailedResult[$className][] = $data[$metric]; } } } $subtype = isset($calculationOptions['subtype']) ? $calculationOptions['subtype'] : 'sum'; foreach ($detailedResult as $className => $counts) { $result = $this->calculateSubtype($counts, $subtype); $detailedResult[$className] = $result; } $detailedResultHtml = '<table class="condensed-table" style="font-size:60%">'; $i = 0; arsort($detailedResult); foreach ($detailedResult as $className => $result) { if ($i > 10) { break; } $i++; $detailedResultHtml .= sprintf('<tr><td>%s</td><td>%s</td></tr>', $className, $result); } $detailedResultHtml .= '</table>'; $aTag = new \TYPO3\Fluid\Core\ViewHelper\TagBuilder('a'); $aTag->addAttribute('rel', 'popover'); $aTag->addAttribute('title', 'Top 10'); $aTag->addAttribute('data-content', $detailedResultHtml); $totalResult = $this->calculateSubtype($results, $subtype); $aTag->setContent($totalResult); return array('value' => $totalResult, 'tableCellHtml' => $aTag->render()); }
/** * Wrap the $content identified by $node with the needed markup for * the backend. * $parameters can be used to further pass parameters to the content element. * * @param \TYPO3\TYPO3CR\Domain\Model\NodeInterface $node * @param string $typoscriptPath * @param string $content * @param boolean $isPage * @return string */ public function wrapContentObject(\TYPO3\TYPO3CR\Domain\Model\NodeInterface $node, $typoscriptPath, $content, $isPage = FALSE) { $contentType = $node->getContentType(); $tagBuilder = new \TYPO3\Fluid\Core\ViewHelper\TagBuilder('div'); $tagBuilder->forceClosingTag(TRUE); if (!$node->isRemoved()) { $tagBuilder->setContent($content); } if (!$isPage) { $cssClasses = array('t3-contentelement'); $cssClasses[] = str_replace(array(':', '.'), '-', strtolower($contentType->getName())); if ($node->isHidden()) { $cssClasses[] = 't3-contentelement-hidden'; } if ($node->isRemoved()) { $cssClasses[] = 't3-contentelement-removed'; } $tagBuilder->addAttribute('class', implode(' ', $cssClasses)); $tagBuilder->addAttribute('id', 'c' . $node->getIdentifier()); } try { $this->accessDecisionManager->decideOnResource('TYPO3_TYPO3_Backend_BackendController'); } catch (\TYPO3\FLOW3\Security\Exception\AccessDeniedException $e) { return $tagBuilder->render(); } $tagBuilder->addAttribute('typeof', 'typo3:' . $contentType->getName()); $tagBuilder->addAttribute('about', $node->getContextPath()); $this->addScriptTag($tagBuilder, '__workspacename', $node->getWorkspace()->getName()); $this->addScriptTag($tagBuilder, '_removed', $node->isRemoved() ? 'true' : 'false', 'boolean'); $this->addScriptTag($tagBuilder, '_typoscriptPath', $typoscriptPath); foreach ($contentType->getProperties() as $propertyName => $propertyConfiguration) { $dataType = isset($propertyConfiguration['type']) ? $propertyConfiguration['type'] : 'string'; if ($propertyName[0] === '_') { $propertyValue = \TYPO3\FLOW3\Reflection\ObjectAccess::getProperty($node, substr($propertyName, 1)); } else { $propertyValue = $node->getProperty($propertyName); } // Serialize boolean values to String if (isset($propertyConfiguration['type']) && $propertyConfiguration['type'] === 'boolean') { $propertyValue = $propertyValue ? 'true' : 'false'; } // Serialize date values to String if ($propertyValue !== NULL && isset($propertyConfiguration['type']) && $propertyConfiguration['type'] === 'date') { $propertyValue = $propertyValue->format('Y-m-d'); } // Serialize objects to JSON strings if (is_object($propertyValue) && $propertyValue !== NULL && isset($propertyConfiguration['type']) && $this->objectManager->isRegistered($propertyConfiguration['type'])) { $gettableProperties = \TYPO3\FLOW3\Reflection\ObjectAccess::getGettableProperties($propertyValue); $convertedProperties = array(); foreach ($gettableProperties as $key => $value) { if (is_object($value)) { $entityIdentifier = $this->persistenceManager->getIdentifierByObject($value); if ($entityIdentifier !== NULL) { $value = $entityIdentifier; } } $convertedProperties[$key] = $value; } $propertyValue = json_encode($convertedProperties); $dataType = 'jsonEncoded'; } $this->addScriptTag($tagBuilder, $propertyName, $propertyValue, $dataType); } if (!$isPage) { // add CSS classes $this->addScriptTag($tagBuilder, '__contenttype', $contentType->getName()); } else { $tagBuilder->addAttribute('id', 't3-page-metainformation'); $tagBuilder->addAttribute('data-__sitename', $this->nodeRepository->getContext()->getCurrentSite()->getName()); $tagBuilder->addAttribute('data-__siteroot', sprintf('/sites/%s@%s', $this->nodeRepository->getContext()->getCurrentSite()->getNodeName(), $this->nodeRepository->getContext()->getWorkspace()->getName())); } return $tagBuilder->render(); }