Commit 8d94dd02 authored by Carsten  Rose's avatar Carsten Rose
Browse files

OnArray: Add htmlEntititesOnArray()

Support: moved wrapTag() from to Support. Add appendTooltip()
AbstractBuildForm, BuildFormBootstrap BuildFormPlain, BuildFormTable: implemented showDebugInfo. Moved wrapTag() to Support. Fixed Typo in word buildNewSip.
parent 843a3ee2
This diff is collapsed.
......@@ -35,6 +35,7 @@ abstract class AbstractBuildForm {
protected $buildElementFunctionName = array();
protected $pattern = array();
protected $wrap = array();
// protected $feDivClass = array(); // Wrap FormElements in <div class="$feDivClass[type]">
private $formId = null;
......@@ -94,7 +95,7 @@ abstract class AbstractBuildForm {
abstract public function fillWrap();
/**
* Builds complete form. Depending of Formspecification, the layout will plain / table / bootstrap.
* Builds complete form. Depending of Formspecification, the layout will be 'plain' / 'table' / 'bootstrap'.
*
* @return string The whole form as HTML
* @throws CodeException
......@@ -158,7 +159,7 @@ abstract class AbstractBuildForm {
}
/**
* Rreturns complete '<form ...>'-tag
* Returns complete '<form ...>'-tag
*
* @return string
*/
......@@ -176,7 +177,7 @@ abstract class AbstractBuildForm {
*/
public function getFormTagAtrributes() {
//TODO: ttconetn id eintragen
//TODO: ttcontent id eintragen
// $attribute['id'] = $this->store->getVar(STORE_TYPO3,'1234');
$attribute['id'] = $this->getFormId();
$attribute['method'] = 'post';
......@@ -254,6 +255,7 @@ abstract class AbstractBuildForm {
// Iterate over all FormElements
foreach ($this->feSpecNative as $fe) {
$debugStack = array();
if (($filter === FORM_ELEMENTS_NATIVE && $fe['type'] === 'subrecord') ||
($filter === FORM_ELEMENTS_SUBRECORD && $fe['type'] !== 'subrecord')
......@@ -266,10 +268,7 @@ abstract class AbstractBuildForm {
// evaluate current FormElement
$evaluate = new Evaluate($this->store, $this->db);
$formElement = $evaluate->parseArray($fe, $fe['debug'] === 'yes');
if ($fe['debug'] === 'yes') {
throw new UserException($evaluate->getDebug(), ERROR_DEBUG);
}
$formElement = $evaluate->parseArray($fe, $debugStack);
// Get default value
$value = $formElement['value'] === '' ? $this->store->getVar($formElement['name']) : $value = $formElement['value'];
......@@ -280,7 +279,18 @@ abstract class AbstractBuildForm {
$buildElementFunctionName = 'build' . $this->buildElementFunctionName[$formElement['type']];
// Render pure element
$elementHtml = $this->$buildElementFunctionName($formElement, $htmlFormElementId, $value);
$elementHtml = $this->$buildElementFunctionName($formElement, $htmlFormElementId, $value, $debugStack);
// debugStack as Tooltip
if( $this->formSpec['showDebugInfo'] === 'yes' && count($debugStack)>0) {
// $elementHtml = Support::wrapWithTooltip($elementHtml, addslashes(implode("\n", Support::htmlentitiesOnArray($debugStack))));
$elementHtml = Support::appendTooltip($elementHtml, implode("\n", OnArray::htmlentitiesOnArray($debugStack)));
}
// e.g.: <div class="radio">
// if(isset($this->feDivClass[$formElement['type']]) && $this->feDivClass[$formElement['type']] != '') {
// $elementHtml = Support::wrapTag('<div class="' . $this->feDivClass[$formElement['type']] .'">', $elementHtml);
// }
// Construct Marshaller Name
$buildRowName = 'buildRow' . $this->buildRowName[$formElement['type']];
......@@ -306,25 +316,6 @@ abstract class AbstractBuildForm {
abstract public function buildRowSubrecord($formElement, $elementHtml);
/**
* Extract Tag from $tag (might contain further attributes) and wrap it around $value. If $flagOmitEmpty==true && $value=='': return ''.
*
* @param $tag
* @param $value
* @param bool|false $flagOmitEmpty
* @return string
*/
public function wrapTag($tag, $value, $flagOmitEmpty = false) {
if ($flagOmitEmpty && $value === "")
return '';
// <div class="container-fluid"> >> </div>
$arr = explode(' ', $tag);
$closing = '</' . substr($arr[0], 1) . '>';
return $tag . $value . $closing;
}
/**
* Builds a label, typically for an html-'<input>'-element.
*
......@@ -570,7 +561,6 @@ abstract class AbstractBuildForm {
default:
throw new UserException('checkBoxMode: \'' . $formElement['checkBoxMode'] . '\' is unknown.', ERROR_CHECKBOXMODE_UNKNOWN);
}
return $html;
}
......@@ -862,8 +852,17 @@ abstract class AbstractBuildForm {
if ($itemKey[$ii] === $value) {
$attribute .= $this->getAttribute('checked', 'checked');
}
$html .= '<input ' . $attribute . '>';
$html .= $itemValue[$ii];
$element = '<input ' . $attribute . '>' . $itemValue[$ii];
// $element = Support::wrapTag('<label>',$element);
// if(isset($this->feDivClass[$formElement['type']]) && $this->feDivClass[$formElement['type']] != '') {
// $element = Support::wrapTag('<div class="' . $this->feDivClass[$formElement['type']] .'">', $element);
// }
$html .= $element;
if ($jj === $formElement['maxLength']) {
$jj = 0;
$html .= '<br>';
......@@ -1052,8 +1051,7 @@ abstract class AbstractBuildForm {
$queryStringArray = [
'form' => $formElement['form'],
'r' => $targetRecordId,
'r' => $targetRecordId
];
// Add custom query parameter
......@@ -1233,7 +1231,7 @@ abstract class AbstractBuildForm {
*
* @return string
*/
public function builtNewSip() {
public function buildNewSip() {
$sipArray = $this->store->getStore(STORE_SIP);
unset($sipArray[SIP_SIP]);
unset($sipArray[SIP_URLPARAM]);
......
......@@ -68,6 +68,8 @@ class BuildFormBootstrap extends AbstractBuildForm {
$this->wrap[WRAP_SETUP_IN_FIELDSET][WRAP_SETUP_START] = '<p>';
$this->wrap[WRAP_SETUP_IN_FIELDSET][WRAP_SETUP_END] = '</p>';
// $this->feDivClass['radio'] = 'radio';
// $this->feDivClass['checkbox'] = 'checkbox';
}
/**
......@@ -97,13 +99,12 @@ class BuildFormBootstrap extends AbstractBuildForm {
$pill = $this->buildPillNavigation(OnArray::filter($this->feSpecNative, 'type', 'pill'));
$button = $this->buildButtons();
$html .= $this->wrapTag('<div class="row">', $pill . $button);
$html .= Support::wrapTag('<div class="row">', $pill . $button);
$html .= $this->getFormTag();
$html .= '<div class="tab-content">';
return $html;
}
......@@ -146,12 +147,12 @@ class BuildFormBootstrap extends AbstractBuildForm {
// Pill Dropdown necessary?
if ($ii > $maxVisiblePill) {
$html = $this->wrapTag('<ul class="dropdown-menu">', $pillDropdown, true);
$html = Support::wrapTag('<ul class="dropdown-menu">', $pillDropdown, true);
$html .= '<a class="dropdown-toggle" data-toggle="dropdown" href="#" role="button">more <span class="caret"></span></a>';
}
$html = $this->wrapTag('<ul id="' . $this->getTabId() . '" class="nav nav-pills" role="tablist">', $pillButton . $html);
$html = $this->wrapTag('<div class="col-md-10">', $html);
$html = Support::wrapTag('<ul id="' . $this->getTabId() . '" class="nav nav-pills" role="tablist">', $pillButton . $html);
$html = Support::wrapTag('<div class="col-md-9">', $html);
return $html;
}
......@@ -180,7 +181,7 @@ class BuildFormBootstrap extends AbstractBuildForm {
*/
private function buildButtons() {
$html = <<<BUTTONS
<div class="col-md-2 ">
<div class="col-md-3 ">
<div class="btn-toolbar pull-right" role="toolbar">
<div class="btn-group" role="group">
<button id="save-button" type="button" class="btn btn-default navbar-btn"><span class="glyphicon glyphicon-ok"></span></button>
......@@ -217,14 +218,14 @@ BUTTONS;
*/
public function tail() {
$html = '';
$html .= $this->builtNewSip();
$html .= $this->buildNewSip();
$formId = $this->getFormId();
// TODO: bootstrap. See BuildFormTable.tail()
$html .= '</div> <!--class="tab-content" -->'; // <div class="tab-content">
$html .= '<input type="submit" value="Submit">';
// $html .= '<input type="submit" value="Submit">';
$formId = $this->getFormId();
$tabId = $this->getTabId();
......@@ -294,7 +295,7 @@ EOF;
$active = $this->isFirstPill ? ' active' : '';
$html = $this->wrapTag('<div role="tabpanel" class="tab-pane' . $active . '" id="' . $this->createAnker($formElement['id']) . '">', $html);
$html = Support::wrapTag('<div role="tabpanel" class="tab-pane' . $active . '" id="' . $this->createAnker($formElement['id']) . '">', $html);
$this->isFirstPill = false;
......
......@@ -85,7 +85,7 @@ class BuildFormPlain extends AbstractBuildForm {
public function tail() {
$html = '';
$html .= $this->builtNewSip();
$html .= $this->buildNewSip();
$html .= $this->wrapItem(WRAP_SETUP_INPUT, '<input type="submit" value="Submit">');
$html = $this->wrapItem(WRAP_SETUP_ELEMENT, $html);
......
......@@ -41,6 +41,8 @@ class BuildFormTable extends AbstractBuildForm {
$this->wrap[WRAP_SETUP_IN_FIELDSET][WRAP_SETUP_START] = '<p>';
$this->wrap[WRAP_SETUP_IN_FIELDSET][WRAP_SETUP_END] = '</p>';
}
/**
......@@ -117,7 +119,7 @@ class BuildFormTable extends AbstractBuildForm {
$html .= $this->wrapItem(WRAP_SETUP_INPUT, '<input type="submit" value="Submit">');
$html = $this->wrapItem(WRAP_SETUP_ELEMENT, $html);
$html .= '</table>';
$html .= $this->builtNewSip();
$html .= $this->buildNewSip();
$html .= '</form>';
$html .= '</div>'; // main <div class=...> around everything
......
......@@ -104,4 +104,17 @@ class OnArray {
'email' => 'pattern="^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$"'
];
}
/**
* Converts a onedimensional array by using htmlentities on all elements
*
* @param array $arr
* @return array
*/
public static function htmlentitiesOnArray(array $arr) {
foreach ($arr as $key => $value) {
$arr[$key] = htmlentities($arr[$key], ENT_QUOTES);
}
return $arr;
}
}
\ No newline at end of file
......@@ -48,4 +48,43 @@ class Support {
return implode('&', $items);
}
/**
* Extract Tag from $tag (might contain further attributes) and wrap it around $value. If $flagOmitEmpty==true && $value=='': return ''.
*
* @param $tag
* @param $value
* @param bool|false $omitIfValueEmpty
* @return string
*/
public static function wrapTag($tag, $value, $omitIfValueEmpty = false) {
if ($omitIfValueEmpty && $value === "")
return '';
// a) <div class="container-fluid">, b) <label>
$arr = explode(' ', $tag);
$tagPlain = (count($arr) === 1) ? substr($arr[0], 1, strlen($arr[0]) - 2) : substr($arr[0], 1);
$closing = '</' . $tagPlain . '>';
return $tag . $value . $closing;
}
/**
* Wraps some $inner fragment with a CSS styled $tooltipText . CSS is configured in 'Resources/Public/qfq-jqw.css'.
*
* Based on: http://www.w3schools.com/howto/howto_css_tooltip.asp
*
* @param $inner
* @param $tooltipText
* @return string
*/
public static function appendTooltip($inner, $tooltipText) {
// $inner .= '<span class="tooltiptext">' . $tooltipText . '</span>';
// return self::wrapTag('<div class="tooltip">', $inner);
return $inner . "<img src='" . GFX_INFO . "' title='$tooltipText'>";
}
}
\ No newline at end of file
......@@ -49,22 +49,6 @@ class BuildFormPlainTest extends AbstractDatabaseTest {
$this->assertEquals('', $result);
}
public function testWrapTag() {
$build = new \qfq\BuildFormPlain(array(), array(), array());
$result = $build->wrapTag("<p class='test'>", 'Hello World', false);
$this->assertEquals("<p class='test'>Hello World</p>", $result);
$result = $build->wrapTag("<p class='test'>", 'Hello World', true);
$this->assertEquals("<p class='test'>Hello World</p>", $result);
$result = $build->wrapTag("<p class='test'>", '', false);
$this->assertEquals("<p class='test'></p>", $result);
$result = $build->wrapTag("<p class='test'>", '', true);
$this->assertEquals('', $result);
}
public function testBuildLabel() {
$build = new \qfq\BuildFormPlain(array(), array(), array());
......@@ -416,8 +400,6 @@ class FakeTSFE {
public $id = 1;
public $type = 1;
public $sys_language_uid = 1;
}
......@@ -16,7 +16,20 @@ require_once(__DIR__ . '/../../qfq/Constants.php');
class HelperFormElementTest extends \PHPUnit_Framework_TestCase {
public function testExplodeFieldParameter() {
public function testExplodeParameter() {
$a = array();
HelperFormElement::explodeParameter($a);
$this->assertEquals(array(), $a, "Both arrays should be equal and empty");
$a = ['id' => 100, 'parameter' => "work=12\nlist=1:new,2:edit,3:delete"];
$b = ['id' => 100, 'parameter' => "work=12\nlist=1:new,2:edit,3:delete", 'work' => 12, 'list' => '1:new,2:edit,3:delete'];
HelperFormElement::explodeParameter($a);
$this->assertEquals($b, $a, "Both arrays should be equal");
}
public function testExplodeParameterInArrayElements() {
$a = array();
HelperFormElement::explodeParameterInArrayElements($a);
$this->assertEquals(array(), $a, "Both arrays should be equal and empty");
......@@ -28,6 +41,7 @@ class HelperFormElementTest extends \PHPUnit_Framework_TestCase {
$this->assertEquals($b, $a, "Both arrays should be equal");
}
/**
* @expectedException \qfq\UserException
*
......
......@@ -75,4 +75,34 @@ class SupportTest extends \PHPUnit_Framework_TestCase {
$this->assertEquals('id=55&name=He%3Cb%3Einz', $actual);
}
public function testWrapTag() {
$build = new \qfq\BuildFormPlain(array(), array(), array());
$result = Support::wrapTag("<p class='test'>", 'Hello World', false);
$this->assertEquals("<p class='test'>Hello World</p>", $result);
$result = Support::wrapTag("<p class='test'>", 'Hello World', true);
$this->assertEquals("<p class='test'>Hello World</p>", $result);
$result = Support::wrapTag("<p class='test'>", '', false);
$this->assertEquals("<p class='test'></p>", $result);
$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('', $result);
$result = Support::wrapTag("<p>", 'Hello World', true);
$this->assertEquals('', $result);
$result = Support::wrapTag("<p>", 'Hello World', false);
$this->assertEquals('', $result);
}
}
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