Beispiel #1
0
 /**
  * @test
  */
 public function getGettablePropertiesReturnsPropertiesOfStdClass()
 {
     $stdClassObject = new \stdClass();
     $stdClassObject->property = 'string1';
     $stdClassObject->property2 = NULL;
     $stdClassObject->publicProperty2 = 42;
     $allProperties = \TYPO3\FLOW3\Reflection\ObjectAccess::getGettableProperties($stdClassObject);
     $expectedProperties = array('property' => 'string1', 'property2' => NULL, 'publicProperty2' => 42);
     $this->assertEquals($expectedProperties, $allProperties, 'expectedProperties did not return the right values for the properties.');
 }
 /**
  * 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();
 }