2 namespace TYPO3\CMS\Form\Utility;
34 $compatibilityService = \TYPO3\CMS\Form\Utility\FormUtility::getObjectManager()->get(CompatibilityLayerUtility::class);
36 return $compatibilityService;
112 GeneralUtility::deprecationLog(
'EXT:form: Do not use "layout." anymore. Deprecated since TYPO3 CMS 7, this function will be removed in TYPO3 CMS 8.');
114 foreach (
$layout as $elementType => $elementValue) {
115 $elementType = strtoupper($elementType);
116 $this->layout[$elementType] = $elementValue;
132 GeneralUtility::deprecationLog(
'EXT:form: Do not use "layout." anymore. Deprecated since TYPO3 CMS 7, this function will be removed in TYPO3 CMS 8.');
134 if (!empty($this->layout[$elementType])) {
135 $layout = $this->layout[$elementType];
137 $action = $this->formBuilder->getControllerAction();
138 switch ($elementType) {
140 $layout =
'<form><containerWrap /></form>';
146 $layout =
'<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /></head><body><table cellspacing="0"><containerWrap /></table></body></html>';
148 case 'CONTAINERWRAP':
149 if ($action !==
'process') {
150 $layout =
'<ol><elements /></ol>';
152 $layout =
'<tbody><elements /></tbody>';
156 if ($action !==
'process') {
157 $layout =
'<li><element /></li>';
159 $layout =
'<tr><element /></tr>';
163 if ($action ===
'show') {
164 $layout =
'<label><labelvalue /><mandatory /><error /></label>';
165 }
elseif ($action ===
'confirmation') {
166 $layout =
'<label><labelvalue /></label>';
168 $layout =
'<em><labelvalue /></em>';
172 if ($action ===
'show') {
173 $layout =
'<legend><legendvalue /><mandatory /><error /></legend>';
174 }
elseif ($action ===
'confirmation') {
175 $layout =
'<legend><legendvalue /></legend>';
177 $layout =
'<thead><tr><th colspan="2" align="left"><legendvalue /></th></tr></thead>';
181 if ($action !==
'process') {
182 $layout =
'<em><mandatoryvalue /></em>';
188 if ($action !==
'process') {
189 $layout =
'<strong><errorvalue /></strong>';
195 case 'CHECKBOXGROUP':
197 if ($action !==
'process') {
198 $layout =
'<fieldset><legend /><containerWrap /></fieldset>';
200 $layout =
'<td colspan="2"><table cellspacing="0" style="padding-left: 20px; margin-bottom: 20px;"><legend /><containerWrap /></table></td>';
204 if ($action !==
'process') {
211 if ($action ===
'show') {
212 $layout =
'<label /><select><elements /></select>';
213 }
elseif ($action ===
'confirmation') {
214 $layout =
'<label /><ol><elements /></ol>';
216 $layout =
'<td style="width: 200px;"><label /></td><td><elements /></td>';
220 if ($action ===
'show') {
221 $layout =
'<label /><textarea />';
222 }
elseif ($action ===
'confirmation') {
223 $layout =
'<label /><inputvalue />';
225 $layout =
'<td style="width: 200px;" valign="top"><label /></td><td><inputvalue /></td>';
233 if ($action !==
'show') {
241 if ($action ===
'show') {
242 $layout =
'<label /><input />';
243 }
elseif ($action ===
'confirmation') {
244 $layout =
'<label /><inputvalue />';
246 $layout =
'<td style="width: 200px;"><label /></td><td><inputvalue /></td>';
250 if ($action ===
'show') {
272 GeneralUtility::deprecationLog(
'EXT:form: Do not use "layout." anymore. Deprecated since TYPO3 CMS 7, this function will be removed in TYPO3 CMS 8.');
275 if ($this->formBuilder->getControllerAction() ===
'show') {
277 }
elseif ($this->formBuilder->getControllerAction() ===
'confirmation') {
282 $formLayout = str_replace($formWrapReturn[
'marker'], $containerWrapReturn[
'html'], $formWrapReturn[
'html']);
283 $formContainerWrap = explode($containerWrapReturn[
'marker'], $formLayout);
284 $layout[
'containerInnerWrap'] = $formContainerWrap;
287 if (!empty($classFromLayout)) {
297 if (isset($userConfiguredElementTyposcript[
'layout'])) {
298 $elementLayout = $userConfiguredElementTyposcript[
'layout'];
304 if ($elementLayout) {
306 if ($elementWrap[
'html'] !==
'') {
311 if (!$descriptionElementLayouts[
'labelContainContent']) {
312 $descriptionElementLayouts[
'labelLayout'] =
'';
314 $libxmlUseInternalErrors = libxml_use_internal_errors(
true);
315 $dom = new \DOMDocument(
'1.0',
'utf-8');
316 $dom->formatOutput =
true;
317 $dom->preserveWhiteSpace =
false;
318 if ($dom->loadXML($descriptionElementLayouts[
'labelLayout'])) {
319 $nodes = $dom->getElementsByTagName(
'label');
320 if ($nodes->length) {
321 $node = $nodes->item(0);
323 $node->setAttribute(
'for', $element->
getId());
324 $descriptionElementLayouts[
'labelLayout'] = $dom->saveXML($dom->firstChild);
328 libxml_use_internal_errors($libxmlUseInternalErrors);
332 if ($labelReturn[
'html'] !==
'') {
333 $elementWrap[
'html'] = str_replace($labelReturn[
'marker'], $descriptionElementLayouts[
'labelLayout'], $labelReturn[
'html']);
336 if ($errorReturn[
'html'] !==
'') {
337 $elementWrap[
'html'] = str_replace($errorReturn[
'marker'], $descriptionElementLayouts[
'errorLayout'], $errorReturn[
'html']);
340 if ($mandatoryReturn[
'html'] !==
'') {
341 $elementWrap[
'html'] = str_replace($mandatoryReturn[
'marker'], $descriptionElementLayouts[
'mandatoryLayout'], $mandatoryReturn[
'html']);
344 $elementWrap = explode($elementWrap[
'marker'], $elementWrap[
'html']);
350 $elementOuterWrap = null;
352 $libxmlUseInternalErrors = libxml_use_internal_errors(
true);
353 $dom = new \DOMDocument(
'1.0',
'utf-8');
354 $dom->formatOutput =
true;
355 $dom->preserveWhiteSpace =
false;
356 if ($dom->loadXML($this->getGlobalLayoutByElementType(
'ELEMENTWRAP'))) {
357 $node = $dom->firstChild;
360 if ($node->getAttribute(
'class') !==
'') {
361 $class = $node->getAttribute(
'class') .
' ';
364 $node->setAttribute(
'class', $class);
365 $elementOuterWrap = $dom->saveXML($dom->firstChild);
367 if ($return[
'marker'] !==
'') {
368 $elementOuterWrap = explode($return[
'marker'], $return[
'html']);
371 $layout[
'optionOuterWrap'] = $elementOuterWrap;
376 $elementOuterWrap = null;
380 $elementOuterWrap = null;
382 libxml_use_internal_errors($libxmlUseInternalErrors);
387 && !$elementOuterWrap
391 $layout[
'elementOuterWrap'] = $elementWrap;
399 $layout[
'elementOuterWrap'] = $elementOuterWrap;
406 $elementWrap = array(
407 $elementOuterWrap[0] . $elementWrap[0],
408 $elementWrap[1] . $elementOuterWrap[1],
411 $layout[
'elementOuterWrap'] = $elementWrap;
420 if (!$descriptionElementLayouts[
'labelContainContent']) {
421 $descriptionElementLayouts[
'labelLayout'] =
'';
426 if ($elementWrap[
'html'] ===
'') {
428 if ($containerWrapReturn[
'marker'] && $containerWrapReturn[
'html']) {
431 if ($legendReturn[
'html'] !==
'') {
432 $containerWrapReturn[
'html'] = str_replace($legendReturn[
'marker'], $descriptionElementLayouts[
'labelLayout'], $legendReturn[
'html']);
434 $containerWrap = explode($containerWrapReturn[
'marker'], $containerWrapReturn[
'html']);
436 $containerWrap = array(
'',
'');
440 $layout[
'containerInnerWrap'] = $containerWrap;
441 $layout[
'noFieldsetTag'] =
true;
442 $layout[
'legend'] = $descriptionElementLayouts[
'labelLayout'];
446 $containerOuterWrap = array(
'',
'');
447 $containerOuterWrap = explode($elementWrap[
'marker'], $elementWrap[
'html']);
449 $containerInnerWrap = explode($containerWrapReturn[
'marker'], $containerWrapReturn[
'html']);
451 $containerWrap = array(
452 $containerOuterWrap[0] . $containerInnerWrap[0],
453 $containerInnerWrap[1] . $containerOuterWrap[1],
457 $layout[
'containerInnerWrap'] = $containerWrap;
458 $layout[
'legend'] = $descriptionElementLayouts[
'labelLayout'];
461 if (!empty($classFromLayout)) {
470 if ($this->formBuilder->getControllerAction() ===
'show') {
471 if ($elementType ===
'TEXTAREA') {
472 $tagName =
'textarea';
473 }
elseif ($elementType ===
'SELECT') {
480 if (!empty($classFromLayout)) {
501 $messages = implode(
' - ', $messages);
503 $html = str_replace($return[
'marker'], $messages, $return[
'html']);
520 $labelContainContent =
false;
521 $mandatoryLayout =
'';
523 if ($this->formBuilder->getControllerAction() ===
'show') {
526 $mandatoryMessages = $this->formBuilder->getValidationBuilder()->getMandatoryValidationMessagesByElementName($element->
getName());
527 if (!empty($mandatoryMessages)) {
531 if (!empty($mandatoryReturn[
'html'])) {
532 if (!empty($mandatoryLayout)) {
533 $labelContainContent =
true;
535 $labelLayout = str_replace($mandatoryReturn[
'marker'], $mandatoryLayout, $mandatoryReturn[
'html']);
540 if (!empty($errorMessages)) {
544 if (!empty($errorReturn[
'html'])) {
545 if (!empty($errorLayout)) {
546 $labelContainContent =
true;
548 $labelLayout = str_replace($errorReturn[
'marker'], $errorLayout, $errorReturn[
'html']);
553 if (!empty($labelValueReturn[
'html'])) {
555 $labelContainContent =
true;
557 $labelLayout = str_replace($labelValueReturn[
'marker'], $element->
getAdditionalArgument($scope), $labelValueReturn[
'html']);
561 'labelContainContent' => $labelContainContent,
562 'labelLayout' => $labelLayout,
563 'errorLayout' => $errorLayout,
564 'mandatoryLayout' => $mandatoryLayout
578 $libxmlUseInternalErrors = libxml_use_internal_errors(
true);
579 $dom = new \DOMDocument(
'1.0',
'utf-8');
580 $dom->formatOutput =
true;
581 $dom->preserveWhiteSpace =
false;
582 if ($dom->loadXML($this->getGlobalLayoutByElementType(strtoupper($elementType)))) {
583 if ($tagName ===
'') {
584 $tagName = $elementType;
586 $nodes = $dom->getElementsByTagName($tagName);
587 if ($nodes->length) {
588 $node = $nodes->item(0);
589 if ($node && $node->getAttribute(
'class') !==
'') {
590 $class = $node->getAttribute(
'class');
594 libxml_use_internal_errors($libxmlUseInternalErrors);
609 if ($this->formBuilder->getControllerAction() ===
'show') {
610 if ($elementType ===
'TEXTAREA') {
612 }
elseif ($elementType ===
'CONTENTELEMENT') {
614 }
elseif ($elementType ===
'SELECT') {
616 }
elseif (in_array($elementType, $this->containerElements)) {
622 if ($elementType ===
'CONTENTELEMENT') {
624 }
elseif ($elementType ===
'SELECT') {
626 }
elseif (in_array($elementType, $this->containerElements)) {
627 if ($this->formBuilder->getControllerAction() ===
'confirmation') {
658 $libxmlUseInternalErrors = libxml_use_internal_errors(
true);
659 $dom = new \DOMDocument(
'1.0',
'utf-8');
660 $dom->preserveWhiteSpace =
false;
661 if (!$dom->loadHTML($html)) {
662 libxml_use_internal_errors($libxmlUseInternalErrors);
668 libxml_use_internal_errors($libxmlUseInternalErrors);
669 $nodes = $dom->getElementsByTagName($tagName);
670 if (!$nodes->length) {
676 $nodeToReplace = $nodes->item(0);
678 $marker =
'###' . uniqid() .
'###';
679 $markerNode = $dom->createTextNode($marker);
680 $replaceNode = $dom->createDocumentFragment();
681 $domNode = $dom->importNode($markerNode,
true);
682 $replaceNode->appendChild($domNode);
683 $parentNode = $nodeToReplace->parentNode;
684 $parentNode->insertBefore($replaceNode, $nodeToReplace);
685 $parentNode->removeChild($nodeToReplace);
686 $nextParent = $parentNode;
688 while ($nextParent !== null) {
689 if ($nextParent->tagName === $stopTag) {
692 $nextParent = $nextParent->parentNode;
696 if ($stopTag ===
'html') {
697 $html = $nextParent->ownerDocument->saveHTML($nextParent);
700 $children = $nextParent->childNodes;
701 foreach ($children as $child) {
702 $html .= $nextParent->ownerDocument->saveHTML($child);
721 if ($elementType ===
'OPTION') {
722 if ($attributeName ===
'data') {
724 $attributeName =
'text';
726 }
elseif ($elementType ===
'TEXTAREA') {
727 if ($attributeName ===
'data') {
729 $attributeName =
'text';
731 }
elseif ($elementType ===
'TEXTBLOCK') {
732 if ($attributeName ===
'content') {
734 $attributeName =
'text';
737 return $attributeName;