‪TYPO3CMS  10.4
FormatDetailsViewHelper.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
20 use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
21 use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
22 use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
23 
28 class ‪FormatDetailsViewHelper extends AbstractViewHelper
29 {
30  use CompileWithRenderStatic;
31 
35  public function ‪initializeArguments()
36  {
37  $this->registerArgument('logEntry', LogEntry::class, '', true);
38  }
39 
55  public static function ‪renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
56  {
58  $logEntry = $arguments['logEntry'];
59  $detailString = $logEntry->getDetails();
60  $substitutes = $logEntry->getLogData();
61  // Strip paths from file names if the log was a file action
62  if ($logEntry->getType() === 2) {
63  $substitutes = ‪self::stripPathFromFilenames($substitutes);
64  }
65  // Substitute
66  if (!empty($substitutes)) {
67  $detailString = vsprintf($detailString, $substitutes);
68  }
69  // Remove possible pending other %s
70  $detailString = str_replace('%s', '', $detailString);
71  return $detailString;
72  }
73 
80  protected static function ‪stripPathFromFilenames(array $files = [])
81  {
82  foreach ($files as $key => $file) {
83  $files[$key] = ‪PathUtility::basename($file);
84  }
85  return $files;
86  }
87 }
‪TYPO3\CMS\Belog\ViewHelpers\FormatDetailsViewHelper\initializeArguments
‪initializeArguments()
Definition: FormatDetailsViewHelper.php:34
‪TYPO3\CMS\Core\Utility\PathUtility
Definition: PathUtility.php:24
‪TYPO3\CMS\Belog\ViewHelpers
‪TYPO3\CMS\Belog\ViewHelpers\FormatDetailsViewHelper\renderStatic
‪static string renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
Definition: FormatDetailsViewHelper.php:54
‪TYPO3\CMS\Belog\ViewHelpers\FormatDetailsViewHelper
Definition: FormatDetailsViewHelper.php:29
‪TYPO3\CMS\Core\Utility\PathUtility\basename
‪static string basename($path)
Definition: PathUtility.php:165
‪TYPO3\CMS\Belog\Domain\Model\LogEntry
Definition: LogEntry.php:28
‪TYPO3\CMS\Belog\ViewHelpers\FormatDetailsViewHelper\stripPathFromFilenames
‪static array stripPathFromFilenames(array $files=[])
Definition: FormatDetailsViewHelper.php:79