mirror of
https://github.com/e107inc/e107.git
synced 2025-08-05 06:07:32 +02:00
Simplified snippet example. Added caching of loaded snippet.
This commit is contained in:
@@ -3,10 +3,32 @@ version: "2"
|
||||
checks:
|
||||
file-lines:
|
||||
enabled: false
|
||||
method-complexity:
|
||||
enabled: true
|
||||
argument-count:
|
||||
config:
|
||||
threshold: 4
|
||||
complex-logic:
|
||||
config:
|
||||
threshold: 4
|
||||
file-lines:
|
||||
config:
|
||||
threshold: 250
|
||||
method-complexity:
|
||||
config:
|
||||
threshold: 250
|
||||
method-count:
|
||||
config:
|
||||
threshold: 250
|
||||
method-lines:
|
||||
config:
|
||||
threshold: 500
|
||||
nested-control-flow:
|
||||
config:
|
||||
threshold: 4
|
||||
return-statements:
|
||||
config:
|
||||
threshold: 4
|
||||
similar-code:
|
||||
enabled: false
|
||||
plugins:
|
||||
csslint:
|
||||
enabled: false
|
||||
|
@@ -2417,18 +2417,48 @@ class e_form
|
||||
return false;
|
||||
}
|
||||
|
||||
$snippet = THEME."snippets/form_".$type.".html";
|
||||
$regId = 'core/form/snippet/'.$type;
|
||||
|
||||
if(!file_exists($snippet))
|
||||
if($snippet = e107::getRegistry($regId))
|
||||
{
|
||||
return $snippet;
|
||||
}
|
||||
|
||||
$snippetPath = THEME."snippets/form_".$type.".html";
|
||||
|
||||
if(!file_exists($snippetPath))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return file_get_contents($snippet, false, null, 0, 1024);
|
||||
$content = file_get_contents($snippetPath, false, null, 0, 1024);
|
||||
|
||||
e107::setRegistry($regId, $content);
|
||||
|
||||
return $content;
|
||||
|
||||
}
|
||||
|
||||
private function renderSnippet($snippet, $options, $name, $value)
|
||||
{
|
||||
$snip = $options;
|
||||
|
||||
if(!empty($options['class']))
|
||||
{
|
||||
$snip['class'] = trim($options['class']);
|
||||
unset($options['class']);
|
||||
}
|
||||
|
||||
$snip['attributes'] = $this->get_attributes($options, $name, $value);
|
||||
|
||||
foreach($snip as $k=>$v)
|
||||
{
|
||||
$search[] = '{'.$k.'}';
|
||||
}
|
||||
|
||||
return str_replace($search, array_values($snip), $snippet);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Render a checkbox
|
||||
@@ -2487,35 +2517,15 @@ class e_form
|
||||
|
||||
$options['class'] .= ' form-check-input';
|
||||
|
||||
if($text = $this->getSnippet('checkbox'))
|
||||
if($snippet = $this->getSnippet('checkbox'))
|
||||
{
|
||||
// todo move all this to its own method. eg. renderSnippet()
|
||||
$snip = $options;
|
||||
$snip['name'] = $name;
|
||||
$snip['value'] = $value;
|
||||
$snip['attributes'] = $this->get_attributes($options, $name, $value);
|
||||
$snip['readonly'] = $this->get_attributes(['readonly'=> $options['readonly']]);
|
||||
$snip['checked'] = $this->get_attributes(['checked'=> $options['checked']]);
|
||||
$snip['active'] = trim($active);
|
||||
$snip['class'] = trim($options['class']);
|
||||
$snip['id'] = $this->_format_id($options['id'], $name, $value, null);
|
||||
|
||||
foreach($snip as $k=>$v)
|
||||
{
|
||||
$search[] = '{'.$k.'}';
|
||||
}
|
||||
|
||||
return str_replace($search, array_values($snip), $text);
|
||||
return $this->renderSnippet($snippet, $options, $name, $value);
|
||||
}
|
||||
|
||||
|
||||
$pre = (!empty($options['label'])) ? "<label class='".$labelClass.$active."'{$labelTitle}>" : ""; // Bootstrap compatible markup
|
||||
$post = (!empty($options['label'])) ? "<span>".$options['label']."</span></label>" : "";
|
||||
unset($options['label']); // not to be used as attribute;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return $pre. "<input type='checkbox' name='{$name}' value='{$value}'".$this->get_attributes($options, $name, $value)." />".$post;
|
||||
|
||||
|
@@ -1148,7 +1148,7 @@ class e_formTest extends \Codeception\Test\Unit
|
||||
|
||||
$result = $this->_frm->checkbox('myname', 3, true, ['readonly'=>true]);
|
||||
$expected = "<label class='checkbox form-check'>
|
||||
<input id='myname-3' class='form-check-input' type='checkbox' name='myname' value='3' readonly='readonly' checked='checked' />
|
||||
<input class='form-check-input' type='checkbox' id='myname-3' readonly='readonly' checked='checked' />
|
||||
<span></span>
|
||||
</label>";
|
||||
|
||||
|
@@ -1,4 +1,4 @@
|
||||
<label class='checkbox form-check'>
|
||||
<input id='{id}' class='{class}' type='checkbox' name='{name}' value='{value}' {readonly} {checked} />
|
||||
<input class='{class}' type='checkbox' {attributes} />
|
||||
<span>{label}</span>
|
||||
</label>
|
Reference in New Issue
Block a user