/**
  * Render a node label
  *
  * @param NodeInterface $node
  * @param boolean $crop This argument is deprecated as of Neos 1.2 and will be removed. Don't rely on this behavior and crop labels in the view.
  * @return string
  */
 public function getLabel(NodeInterface $node, $crop = true)
 {
     $label = Utility::evaluateEelExpression($this->getExpression(), $this->eelEvaluator, array('node' => $node), $this->defaultContextConfiguration);
     if ($crop === false) {
         return $label;
     }
     $croppedLabel = Functions::substr($label, 0, 30);
     return $croppedLabel . (strlen($croppedLabel) < strlen($label) ? ' …' : '');
 }
 /**
  * Returns a random string with alpha-numeric characters.
  *
  * @param integer $count Number of characters to generate
  * @param string $characters Allowed characters, defaults to alpha-numeric (a-zA-Z0-9)
  * @return string A random string
  */
 public static function generateRandomString($count, $characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789')
 {
     $characterCount = \Neos\Utility\Unicode\Functions::strlen($characters);
     $string = '';
     for ($i = 0; $i < $count; $i++) {
         $string .= \Neos\Utility\Unicode\Functions::substr($characters, random_int(0, $characterCount - 1), 1);
     }
     return $string;
 }
 /**
  * @param array $arguments
  * @param callable $renderChildrenClosure
  * @param RenderingContextInterface $renderingContext
  * @return string
  */
 public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
 {
     $value = $arguments['value'];
     if ($value === null) {
         $value = $renderChildrenClosure();
     }
     if (UnicodeUtilityFunctions::strlen($value) > $arguments['maxCharacters']) {
         return UnicodeUtilityFunctions::substr($value, 0, $arguments['maxCharacters']) . $arguments['append'];
     }
     return $value;
 }
 /**
  * Render a node label
  *
  * @param AbstractNodeData $nodeData
  * @param boolean $crop This argument is deprecated as of Neos 1.2 and will be removed. Don't rely on this behavior and crop labels in the view.
  * @return string
  */
 public function getLabel(AbstractNodeData $nodeData, $crop = true)
 {
     if ($nodeData->hasProperty('title') === true && $nodeData->getProperty('title') !== '') {
         $label = strip_tags($nodeData->getProperty('title'));
     } elseif ($nodeData->hasProperty('text') === true && $nodeData->getProperty('text') !== '') {
         $label = strip_tags($nodeData->getProperty('text'));
     } else {
         $label = ($nodeData->getNodeType()->getLabel() ?: $nodeData->getNodeType()->getName()) . ' (' . $nodeData->getName() . ')';
     }
     if ($crop === false) {
         return $label;
     }
     $croppedLabel = trim(Functions::substr($label, 0, 30));
     return $croppedLabel . (strlen($croppedLabel) < strlen($label) ? ' …' : '');
 }
 /**
  * Crop a string to ``maximumCharacters`` length, taking sentences into account,
  * optionally appending ``suffix`` if cropping was necessary.
  *
  * @param string $string The input string
  * @param integer $maximumCharacters Number of characters where cropping should happen
  * @param string $suffix Suffix to be appended if cropping was necessary
  * @return string The cropped string
  */
 public function cropAtSentence($string, $maximumCharacters, $suffix = '')
 {
     if (UnicodeFunctions::strlen($string) > $maximumCharacters) {
         $iterator = new TextIterator($string, TextIterator::SENTENCE);
         $string = UnicodeFunctions::substr($string, 0, $iterator->preceding($maximumCharacters));
         $string .= $suffix;
     }
     return $string;
 }
Пример #6
0
 /**
  * Checks if substr() can handle UTF8 strings, specifying no length
  *
  * @test
  */
 public function substrWorksWithUTF8CharactersSpecifyingNoLength()
 {
     $testString = 'Kasper Skårhøj implemented most versions of TYPO3.';
     $this->assertEquals('implemented most versions of TYPO3.', Functions::substr($testString, 15), 'substr() with UTF8 characters did not return the expected string after specifying no length.');
 }