TYPO3 CMS  TYPO3_7-6
PlainMailViewHelper.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
21 {
31  public function render($labelContent = null, $content = null, $newLineAfterLabel = false, $indent = 0)
32  {
33  $templateVariableContainer = $this->renderingContext->getViewHelperVariableContainer();
34  if (!$templateVariableContainer->exists(\TYPO3\CMS\Form\ViewHelpers\PlainMailViewHelper::class, 'spaces')) {
35  $templateVariableContainer->add(\TYPO3\CMS\Form\ViewHelpers\PlainMailViewHelper::class, 'spaces', 0);
36  }
37 
38  $spaces = $templateVariableContainer->get(\TYPO3\CMS\Form\ViewHelpers\PlainMailViewHelper::class, 'spaces');
39  $output = '';
40  if ($labelContent) {
41  if ($labelContent instanceof \TYPO3\CMS\Form\Domain\Model\Element) {
42  $output = $this->getLabel($labelContent);
43  } else {
44  $output = $labelContent;
45  }
46  if ($newLineAfterLabel) {
47  if ($output !== '') {
48  $output = str_repeat(chr(32), $spaces) . $output . LF;
49  }
50  $this->setIndent($indent);
51  }
52  }
53 
54  if ($content) {
55  if (!$newLineAfterLabel) {
56  $this->setIndent($indent);
57  }
58  if (
59  $labelContent
60  && !$newLineAfterLabel
61  ) {
62  $output = $output . ': ' . $this->getValue($content);
63  } elseif (
64  $labelContent
65  && $newLineAfterLabel
66  ) {
67  $output =
68  $output .
69  str_repeat(chr(32), ($spaces + 4)) .
70  str_replace(LF, LF . str_repeat(chr(32), ($spaces + 4)), $this->getValue($content));
71  } else {
72  $output = $this->getValue($content);
73  }
74  }
75 
76  if (
77  $labelContent
78  || $content
79  ) {
80  if (
81  $output !== ''
82  && !$newLineAfterLabel
83  ) {
84  $output = str_repeat(chr(32), $spaces) . $output;
85  }
86  } else {
87  $this->setIndent($indent);
88  }
89 
90  return $output;
91  }
92 
98  protected function getLabel(\TYPO3\CMS\Form\Domain\Model\Element $model)
99  {
100  $label = '';
101  if ($model->getAdditionalArgument('legend')) {
102  $label = $model->getAdditionalArgument('legend');
103  } elseif ($model->getAdditionalArgument('label')) {
104  $label = $model->getAdditionalArgument('label');
105  }
106  return $label;
107  }
108 
114  protected function getValue($content)
115  {
116  $value = '';
117  if ($content instanceof \TYPO3\CMS\Form\Domain\Model\Element) {
118  $value = $content->getAdditionalArgument('value');
119  } else {
120  $value = $content;
121  }
122  return $value;
123  }
124 
131  public function setIndent($indent = 0)
132  {
133  $templateVariableContainer = $this->renderingContext->getViewHelperVariableContainer();
134  $spaces = $templateVariableContainer->get(\TYPO3\CMS\Form\ViewHelpers\PlainMailViewHelper::class, 'spaces');
135  $spaces += (int)$indent;
136  $templateVariableContainer->addOrUpdate(\TYPO3\CMS\Form\ViewHelpers\PlainMailViewHelper::class, 'indent', $indent);
137  $templateVariableContainer->addOrUpdate(\TYPO3\CMS\Form\ViewHelpers\PlainMailViewHelper::class, 'spaces', $spaces);
138  }
139 }
getLabel(\TYPO3\CMS\Form\Domain\Model\Element $model)
render($labelContent=null, $content=null, $newLineAfterLabel=false, $indent=0)