Commit 286ad90b authored by Carsten  Rose's avatar Carsten Rose
Browse files

#4425/ Subrecords: Table head is not wrapped in <thead>

Support.php: wrapTag() extend to wrap multiple tags.
AbstractBuildForm.php: wrap thead in subrecord header.
parent 7e489693
......@@ -2274,7 +2274,8 @@ abstract class AbstractBuildForm {
/**
* Construct a HTML table of the subrecord data.
* Column syntax definition:https://docs.typo3.org/typo3cms/drafts/github/T3DocumentationStarter/Public-Info-053/Manual.html#type-subrecord
* Column syntax
* definition:https://docs.typo3.org/typo3cms/drafts/github/T3DocumentationStarter/Public-Info-053/Manual.html#type-subrecord
*
* @param array $formElement
* @param string $htmlFormElementName
......@@ -2332,7 +2333,7 @@ abstract class AbstractBuildForm {
}
// Table head
$html = Support::wrapTag('<tr>', $columns);
$html = Support::wrapTag('<thead><tr>', $columns);
foreach ($formElement[FE_SQL1] as $row) {
$rowHtml = '';
......
......@@ -104,7 +104,6 @@ class HelperFormElement {
* @param string $id
*
* @return string
* @internal param string $field
*/
public static function buildFormElementName(array $formElement, $id) {
$field = ($formElement[FE_NAME] == '') ? $formElement[FE_ID] : $formElement[FE_NAME];
......
......@@ -65,7 +65,7 @@ class Support {
}
/**
* Extract Tag from $tag (eg: <input class="form-control">, might contain further attributes) and wrap it around
* Extract Tag(s) from $tag (eg: <div><input class="form-control">, might contain further attributes) and wrap it around
* $value. If $flagOmitEmpty==true && $value=='': return ''.
*
* @param string $tag
......@@ -75,8 +75,18 @@ class Support {
* @return string
*/
public static function wrapTag($tag, $value, $omitIfValueEmpty = false) {
if ($omitIfValueEmpty && $value === "")
return '';
$tag = trim($tag);
if ($tag == '' || ($omitIfValueEmpty && $value == "")) {
return $value;
}
$tagArray = explode('>', $tag, 2);
if (count($tagArray) > 1 && $tagArray[1] != '') {
$value = self::wrapTag($tagArray[1], $value, $omitIfValueEmpty);
$tag = $tagArray[0] . '>';
}
// a) <div class="container-fluid">, b) <label>
$arr = explode(' ', $tag);
......@@ -461,7 +471,7 @@ class Support {
*
* @param string $dateFormat FORMAT_DATE_INTERNATIONAL | FORMAT_DATE_GERMAN
* @param string $showZero
* @param string $showTime '0' | '1'
* @param string $showTime '0' | '1'
* @param string $showSeconds '0' | '1'
*
* @return string
......@@ -712,7 +722,7 @@ class Support {
* Looks in $arr if there is an element $index. If not, set it to $value.
* If $overwriteThis!=false, replace the the original value with $value, if $arr[$index]==$overwriteThis.
*
* @param array $arr
* @param array $arr
* @param string $index
* @param string $value
* @param string|bool $overwriteThis If there is already something which is equal to $overwrite: take new default.
......
......@@ -76,6 +76,42 @@ class SupportTest extends \PHPUnit_Framework_TestCase {
public function testWrapTag() {
// $build = new \qfq\BuildFormPlain(array(), array(), array());
$result = Support::wrapTag("", '');
$this->assertEquals('', $result);
$result = Support::wrapTag(" ", '');
$this->assertEquals('', $result);
$result = Support::wrapTag("", ' ');
$this->assertEquals(' ', $result);
$result = Support::wrapTag(" ", ' ');
$this->assertEquals(' ', $result);
$result = Support::wrapTag("", '', true);
$this->assertEquals('', $result);
$result = Support::wrapTag(" ", '', true);
$this->assertEquals('', $result);
$result = Support::wrapTag("", ' ', true);
$this->assertEquals(' ', $result);
$result = Support::wrapTag(" ", ' ', true);
$this->assertEquals(' ', $result);
$result = Support::wrapTag("<p>", '', true);
$this->assertEquals('', $result);
$result = Support::wrapTag("<p>", '', false);
$this->assertEquals('<p></p>', $result);
$result = Support::wrapTag("<p> ", '', true);
$this->assertEquals('', $result);
$result = Support::wrapTag(" <p>", '', false);
$this->assertEquals('<p></p>', $result);
$result = Support::wrapTag("<p class='test'>", 'Hello World', false);
$this->assertEquals("<p class='test'>Hello World</p>", $result);
......@@ -88,17 +124,27 @@ class SupportTest extends \PHPUnit_Framework_TestCase {
$result = Support::wrapTag("<p class='test'>", '', true);
$this->assertEquals('', $result);
$result = Support::wrapTag("<p>", '', true);
$this->assertEquals('', $result);
$result = Support::wrapTag("<p>", '', false);
$this->assertEquals('<p></p>', $result);
$result = Support::wrapTag("<p>", 'Hello World', true);
$this->assertEquals('<p>Hello World</p>', $result);
$result = Support::wrapTag("<p>", 'Hello World', false);
$this->assertEquals('<p>Hello World</p>', $result);
$result = Support::wrapTag("<p><i>", 'Hello World', false);
$this->assertEquals('<p><i>Hello World</i></p>', $result);
$result = Support::wrapTag(" <p> <i> ", 'Hello World', false);
$this->assertEquals('<p><i>Hello World</i></p>', $result);
$result = Support::wrapTag("<p><i><strong>", 'Hello World', false);
$this->assertEquals('<p><i><strong>Hello World</strong></i></p>', $result);
$result = Support::wrapTag("<p class='test'><i>", 'Hello World', false);
$this->assertEquals("<p class='test'><i>Hello World</i></p>", $result);
$result = Support::wrapTag("<p class='test1'><i class='test2'><strong class='test3'>", 'Hello World', false);
$this->assertEquals("<p class='test1'><i class='test2'><strong class='test3'>Hello World</strong></i></p>", $result);
}
public function testDateTime2mysql() {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment