Compare commits
2 Commits
c83cb2622a
...
21725f0f1e
Author | SHA1 | Date | |
---|---|---|---|
21725f0f1e | |||
42a035ccba |
@ -123,7 +123,9 @@ trait ValidationTrait
|
||||
{
|
||||
$validator = new Validator();
|
||||
$input = ArrayUtility::removeEmptyStrings($input);
|
||||
if (is_array($input) && array_key_exists('eID', $input)) {
|
||||
unset($input['eID']);
|
||||
}
|
||||
//@TODO make optional when usiing rest api
|
||||
//array_walk_recursive(
|
||||
// $input,
|
||||
|
75
Classes/ViewHelpers/Format/WordWrapViewHelper.php
Normal file
75
Classes/ViewHelpers/Format/WordWrapViewHelper.php
Normal file
@ -0,0 +1,75 @@
|
||||
<?php
|
||||
namespace Cjel\TemplatesAide\ViewHelpers\Format;
|
||||
|
||||
/*
|
||||
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.md file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
|
||||
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
|
||||
use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithContentArgumentAndRenderStatic;
|
||||
|
||||
/**
|
||||
* ### Wordwrap: Wrap a string at provided character count
|
||||
*
|
||||
* Wraps a string to $limit characters and at $break character
|
||||
* while maintaining complete words. Concatenates the resulting
|
||||
* strings with $glue. Code is heavily inspired
|
||||
* by Codeigniter's word_wrap helper.
|
||||
*/
|
||||
class WordWrapViewHelper extends AbstractViewHelper
|
||||
{
|
||||
use CompileWithContentArgumentAndRenderStatic;
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function initializeArguments()
|
||||
{
|
||||
$this->registerArgument('subject', 'string', 'Text to wrap');
|
||||
$this->registerArgument('limit', 'integer', 'Maximum length of resulting parts after wrapping', false, 80);
|
||||
$this->registerArgument('break', 'string', 'Character to wrap text at', false, PHP_EOL);
|
||||
$this->registerArgument('glue', 'string', 'Character to concatenate parts with after wrapping', false, PHP_EOL);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $arguments
|
||||
* @param \Closure $renderChildrenClosure
|
||||
* @param RenderingContextInterface $renderingContext
|
||||
* @return mixed
|
||||
*/
|
||||
public static function renderStatic(
|
||||
array $arguments,
|
||||
\Closure $renderChildrenClosure,
|
||||
RenderingContextInterface $renderingContext
|
||||
) {
|
||||
$subject = $renderChildrenClosure();
|
||||
$limit = (integer) $arguments['limit'];
|
||||
$break = $arguments['break'];
|
||||
$glue = $arguments['glue'];
|
||||
$subject = preg_replace('/ +/', ' ', $subject);
|
||||
$subject = str_replace(["\r\n", "\r"], PHP_EOL, $subject);
|
||||
$subject = wordwrap($subject, $limit, $break, false);
|
||||
$output = '';
|
||||
foreach (explode($break, $subject) as $line) {
|
||||
if (mb_strlen($line) <= $limit) {
|
||||
$output .= $line . $glue;
|
||||
continue;
|
||||
}
|
||||
$temp = '';
|
||||
//while (mb_strlen($line) > $limit) {
|
||||
// $temp .= mb_substr($line, 0, $limit - 1);
|
||||
// $line = mb_substr($line, $limit - 1);
|
||||
//}
|
||||
if (false === empty($temp)) {
|
||||
$output .= $temp . $glue . $line . $glue;
|
||||
} else {
|
||||
$output .= $line . $glue;
|
||||
}
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
}
|
@ -20,9 +20,9 @@
|
||||
### {row.data -> f:format.nl2br() -> f:format.raw()}
|
||||
</f:case>
|
||||
<f:defaultCase>
|
||||
<f:spaceless><v:format.wordWrap limit="76" glue="{br}">
|
||||
<f:spaceless><c:format.wordWrap limit="76" glue="{br}">
|
||||
{row.data -> f:format.raw()}
|
||||
</v:format.wordWrap>
|
||||
</c:format.wordWrap>
|
||||
</f:spaceless>{br}{br}
|
||||
</f:defaultCase>
|
||||
</f:switch>
|
||||
|
Loading…
x
Reference in New Issue
Block a user